Created
March 8, 2020 12:06
-
-
Save tchak/04394c5fa87e3e8eccf44c8332a2589d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { RecordIdentity } from '@orbit/data'; | |
import { SyncLiveQuery } from '@orbit/record-cache'; | |
import { consume, dirty } from './tracked'; | |
import { ReadonlyArray } from './readonly-array'; | |
export class LiveQueryArray<M extends RecordIdentity> extends ReadonlyArray<M> { | |
private readonly _liveQuery: SyncLiveQuery; | |
private get _content(): M[] { | |
return this._liveQuery.query() as M[]; | |
} | |
readonly unsubscribe: () => void; | |
[Symbol.iterator]() { | |
consume(this); | |
return this._content[Symbol.iterator](); | |
} | |
getAt(i: number): M | undefined { | |
consume(this); | |
return this._content[i]; | |
} | |
constructor(liveQuery: SyncLiveQuery) { | |
super(); | |
this._liveQuery = liveQuery; | |
this.unsubscribe = this._liveQuery.subscribe(() => { | |
dirty(this); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment