| 28 | } |
| 29 | |
| 30 | export class DataCollection<DataType extends BaseClass> implements IDataCollection { |
| 31 | restPath!: string; |
| 32 | query!: Query; |
| 33 | accessor!: IDataAccessor; |
| 34 | socketPath!: string; |
| 35 | endpoint!: string; |
| 36 | socketPathRE!: RegExp; |
| 37 | queryExecutor!: DataQuery; |
| 38 | descriptor!: IDataDescriptor<DataType>; |
| 39 | webSocketClient!: WebSocketClient; |
| 40 | isOpen: boolean = false; |
| 41 | internalId: number = 0; |
| 42 | |
| 43 | @observable resolved: boolean = false; |
| 44 | // does not contain elements that have been filtered out and off limits |
| 45 | @observable array: IObservableArray<DataType> = observable<DataType>([]); |
| 46 | // does not contain elements that have been filtered out |
| 47 | @observable byId: ObservableMap<string, DataType> = observable.map<string, DataType>(); |
| 48 | |
| 49 | // includes IDs of all elements received before resolved becomes true. This is necessary to |
| 50 | // track which elements have been received, but filtered out. |
| 51 | idsBeforeResolve = new Set<string>(); |
| 52 | |
| 53 | constructor(internalId: number = 0) { |
| 54 | makeObservable(this); |
| 55 | this.internalId = internalId; |
| 56 | } |
| 57 | |
| 58 | listener(data: any) { |
| 59 | const key = data.k; |
| 60 | const message = data.m; |
| 61 | // Test if the message is for me |
| 62 | if (this.socketPathRE.test(key)) { |
| 63 | this.put(message); |
| 64 | this.recomputeQuery(); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | isValid() { |
| 69 | if (this.accessor === undefined) { |
| 70 | return false; |
| 71 | } |
| 72 | return this.accessor.isOpen(); |
| 73 | } |
| 74 | |
| 75 | isResolved() { |
| 76 | return this.resolved; |
| 77 | } |
| 78 | |
| 79 | subscribe() { |
| 80 | return this.webSocketClient.subscribe(this.socketPath, this); |
| 81 | } |
| 82 | |
| 83 | open(restPath: string, query: Query, accessor: IDataAccessor, |
| 84 | descriptor: IDataDescriptor<DataType>, webSocketClient: WebSocketClient) { |
| 85 | this.restPath = restPath; |
| 86 | this.query = query; |
| 87 | this.accessor = accessor; |
nothing calls this directly
no outgoing calls
no test coverage detected