##// END OF EJS Templates
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already
Corrected Scope.own() to cleanup the supplied object immediately when the scope is disposed already

File last commit:

r129:66546e709732 v1.8.0 default
r131:c7d9ad82b374 v1.8.1 default
Show More
store.ts
61 lines | 2.1 KiB | video/mp2t | TypeScriptLexer
cin
added reduce() and next() methods to observable...
r116 import { PromiseOrValue } from "@implab/core-amd/interfaces";
import { isPromise } from "@implab/core-amd/safe";
import { observe, Observable } from "./observable";
export interface OrderedUpdate<T> {
/** The item is being updated */
readonly item: T;
/** The previous index of the item, -1 in case it is inserted */
readonly prevIndex: number;
/** The new index of the item, -1 in case it is deleted */
readonly newIndex: number;
}
export type QueryResults<T> = Observable<OrderedUpdate<T>>;
interface DjObservableResults<T> {
/**
* Allows observation of results
*/
observe(listener: (object: T, previousIndex: number, newIndex: number) => void, includeUpdates?: boolean): {
remove(): void;
};
}
cin
added whenRendered() method to wait for pending oprations to complete
r118 interface Queryable<T, Q, O> {
query(query?: Q, options?: O): PromiseOrValue<T[]>;
cin
added reduce() and next() methods to observable...
r116 }
cin
added whenRendered() method to wait for pending oprations to complete
r118 export const isDjObservableResults = <T>(v: object): v is DjObservableResults<T> =>
cin
added reduce() and next() methods to observable...
r116 v && (typeof (v as { observe?: unknown; }).observe === "function");
cin
added whenRendered() method to wait for pending oprations to complete
r118 export const query = <T, Q, O>(store: Queryable<T, Q, O>, includeUpdates = true) =>
cin
type fixes for i18n, store
r120 (query?: Q, options?: O & { observe?: boolean }) => {
cin
added reduce() and next() methods to observable...
r116 return observe<OrderedUpdate<T>>(({ next, complete, error, isClosed }) => {
cin
added observable.collect() method to collect a sequnce to the array...
r129
const processResults = (items: T[]) =>
items.forEach((item, newIndex) => next({ item, newIndex, prevIndex: -1 }));
cin
added reduce() and next() methods to observable...
r116 try {
cin
added whenRendered() method to wait for pending oprations to complete
r118 const results = store.query(query, options);
cin
added reduce() and next() methods to observable...
r116 if (isPromise(results)) {
cin
added observable.collect() method to collect a sequnce to the array...
r129 results.then(processResults).then(undefined, error);
cin
added reduce() and next() methods to observable...
r116 } else {
cin
added observable.collect() method to collect a sequnce to the array...
r129 processResults(results);
cin
added reduce() and next() methods to observable...
r116 }
cin
added whenRendered() method to wait for pending oprations to complete
r118 if (!isClosed() && (options?.observe !== false) && isDjObservableResults<T>(results)) {
cin
added reduce() and next() methods to observable...
r116 const h = results.observe((item, prevIndex, newIndex) => next({ item, prevIndex, newIndex }), includeUpdates);
return () => h.remove();
} else {
complete();
}
} catch (err) {
error(err);
}
});
};