(state: Record<string, any> | null)
| 97 | } |
| 98 | |
| 99 | setLocalState(state: Record<string, any> | null) { |
| 100 | const clientID = this.clientID |
| 101 | const currLocalMeta = this.meta.get(clientID) |
| 102 | const clock = currLocalMeta === undefined ? 0 : currLocalMeta.clock + 1 |
| 103 | const prevState = this.states.get(clientID) |
| 104 | if (state === null) { |
| 105 | this.states.delete(clientID) |
| 106 | } else { |
| 107 | this.states.set(clientID, state) |
| 108 | } |
| 109 | this.meta.set(clientID, { |
| 110 | clock, |
| 111 | lastUpdated: time.getUnixTime(), |
| 112 | }) |
| 113 | const added = [] |
| 114 | const updated = [] |
| 115 | const filteredUpdated = [] |
| 116 | const removed = [] |
| 117 | if (state === null) { |
| 118 | removed.push(clientID) |
| 119 | } else if (prevState == null) { |
| 120 | if (state != null) { |
| 121 | added.push(clientID) |
| 122 | } |
| 123 | } else { |
| 124 | updated.push(clientID) |
| 125 | if (!f.equalityDeep(prevState, state)) { |
| 126 | filteredUpdated.push(clientID) |
| 127 | } |
| 128 | } |
| 129 | if (added.length > 0 || filteredUpdated.length > 0 || removed.length > 0) { |
| 130 | this.emit('change', [{ added, updated: filteredUpdated, removed }, 'local']) |
| 131 | } |
| 132 | this.emit('update', [{ added, updated, removed }, 'local']) |
| 133 | } |
| 134 | |
| 135 | setLocalStateField(field: string, value: any) { |
| 136 | const state = this.getLocalState() |
no test coverage detected