From e7fa87bcc0052e1e99c6894e7e27a122374956b3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sun, 28 May 2017 16:27:34 +0200 Subject: documentation and tslint settings to check for docs --- src/query.ts | 95 +++++++++++++++++++----------------------------------------- 1 file changed, 30 insertions(+), 65 deletions(-) (limited to 'src/query.ts') diff --git a/src/query.ts b/src/query.ts index 78b810371..cb033df4c 100644 --- a/src/query.ts +++ b/src/query.ts @@ -53,6 +53,9 @@ export class Store { * Definition of an index. */ export class Index { + /** + * Name of the store that this index is associated with. + */ storeName: string; constructor(s: Store, public indexName: string, public keyPath: string | string[]) { @@ -127,16 +130,26 @@ export interface QueryStream { * Query result that consists of at most one value. */ export interface QueryValue { + /** + * Apply a function to a query value. + */ map(f: (x: T) => S): QueryValue; + /** + * Conditionally execute either of two queries based + * on a property of this query value. + * + * Useful to properly implement complex queries within a transaction (as + * opposed to just computing the conditional and then executing either + * branch). This is necessary since IndexedDB does not allow long-lived + * transactions. + */ cond(f: (x: T) => boolean, onTrue: (r: QueryRoot) => R, onFalse: (r: QueryRoot) => R): Promise; } abstract class BaseQueryValue implements QueryValue { - root: QueryRoot; - constructor(root: QueryRoot) { - this.root = root; + constructor(public root: QueryRoot) { } map(f: (x: T) => S): QueryValue { @@ -160,8 +173,9 @@ abstract class BaseQueryValue implements QueryValue { } class FirstQueryValue extends BaseQueryValue { - gotValue = false; - s: QueryStreamBase; + private gotValue = false; + private s: QueryStreamBase; + constructor(stream: QueryStreamBase) { super(stream.root); this.s = stream; @@ -183,13 +197,8 @@ class FirstQueryValue extends BaseQueryValue { } class MapQueryValue extends BaseQueryValue { - mapFn: (x: T) => S; - v: BaseQueryValue; - - constructor(v: BaseQueryValue, mapFn: (x: T) => S) { + constructor(private v: BaseQueryValue, private mapFn: (x: T) => S) { super(v.root); - this.v = v; - this.mapFn = mapFn; } subscribeOne(f: SubscribeOneFn): void { @@ -226,11 +235,7 @@ abstract class QueryStreamBase implements QueryStream, PromiseLike { abstract subscribe(f: (isDone: boolean, value: any, tx: IDBTransaction) => void): void; - - root: QueryRoot; - - constructor(root: QueryRoot) { - this.root = root; + constructor(public root: QueryRoot) { } first(): QueryValue { @@ -313,13 +318,8 @@ type SubscribeOneFn = (value: any, tx: IDBTransaction) => void; type FlatMapFn = (v: T) => T[]; class QueryStreamFilter extends QueryStreamBase { - s: QueryStreamBase; - filterFn: FilterFn; - - constructor(s: QueryStreamBase, filterFn: FilterFn) { + constructor(public s: QueryStreamBase, public filterFn: FilterFn) { super(s.root); - this.s = s; - this.filterFn = filterFn; } subscribe(f: SubscribeFn) { @@ -337,13 +337,8 @@ class QueryStreamFilter extends QueryStreamBase { class QueryStreamFlatMap extends QueryStreamBase { - s: QueryStreamBase; - flatMapFn: (v: T) => S[]; - - constructor(s: QueryStreamBase, flatMapFn: (v: T) => S[]) { + constructor(public s: QueryStreamBase, public flatMapFn: (v: T) => S[]) { super(s.root); - this.s = s; - this.flatMapFn = flatMapFn; } subscribe(f: SubscribeFn) { @@ -362,13 +357,8 @@ class QueryStreamFlatMap extends QueryStreamBase { class QueryStreamMap extends QueryStreamBase { - s: QueryStreamBase; - mapFn: (v: S) => T; - - constructor(s: QueryStreamBase, mapFn: (v: S) => T) { + constructor(public s: QueryStreamBase, public mapFn: (v: S) => T) { super(s.root); - this.s = s; - this.mapFn = mapFn; } subscribe(f: SubscribeFn) { @@ -385,18 +375,9 @@ class QueryStreamMap extends QueryStreamBase { class QueryStreamIndexJoin extends QueryStreamBase> { - s: QueryStreamBase; - storeName: string; - key: any; - indexName: string; - - constructor(s: QueryStreamBase, storeName: string, indexName: string, - key: any) { + constructor(public s: QueryStreamBase, public storeName: string, public indexName: string, + public key: any) { super(s.root); - this.s = s; - this.storeName = storeName; - this.key = key; - this.indexName = indexName; } subscribe(f: SubscribeFn) { @@ -420,18 +401,9 @@ class QueryStreamIndexJoin extends QueryStreamBase> { class QueryStreamIndexJoinLeft extends QueryStreamBase> { - s: QueryStreamBase; - storeName: string; - key: any; - indexName: string; - - constructor(s: QueryStreamBase, storeName: string, indexName: string, - key: any) { + constructor(public s: QueryStreamBase, public storeName: string, public indexName: string, + public key: any) { super(s.root); - this.s = s; - this.storeName = storeName; - this.key = key; - this.indexName = indexName; } subscribe(f: SubscribeFn) { @@ -461,16 +433,9 @@ class QueryStreamIndexJoinLeft extends QueryStreamBase extends QueryStreamBase> { - s: QueryStreamBase; - storeName: string; - key: any; - - constructor(s: QueryStreamBase, storeName: string, - key: any) { + constructor(public s: QueryStreamBase, public storeName: string, + public key: any) { super(s.root); - this.s = s; - this.storeName = storeName; - this.key = key; } subscribe(f: SubscribeFn) { -- cgit v1.2.3