reactivedb
Advanced tools
Comparing version
{ | ||
"name": "reactivedb", | ||
"version": "0.10.4-alpha.13-diff", | ||
"version": "0.10.4-alpha.14-diff", | ||
"description": "Reactive ORM for Lovefield", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -16,8 +16,16 @@ import { Observable } from 'rxjs/Observable' | ||
import { TokenConsumed } from '../../exception/token' | ||
import { diff, Ops, OpsType } from '../../utils/diff' | ||
import { diff, Ops, OpsType, OpType } from '../../utils/diff' | ||
export type TraceResult<T> = Ops & { | ||
result: T[] | ||
result: ReadonlyArray<T> | ||
} | ||
function initialTraceResult<T>(list: ReadonlyArray<T>): TraceResult<T> { | ||
return { | ||
type: OpsType.Success, | ||
ops: list.map((_value, index) => ({ type: OpType.New, index })), | ||
result: list | ||
} | ||
} | ||
export type SelectorMeta<T> = Selector<T> | ProxySelector<T> | ||
@@ -32,5 +40,7 @@ | ||
private consumed = false | ||
private lastEmit: T[] = [] | ||
constructor(selector$: Observable<SelectorMeta<T>>, lastEmit?: T[]) { | ||
constructor( | ||
selector$: Observable<SelectorMeta<T>>, | ||
private lastEmit?: ReadonlyArray<T> | ||
) { | ||
this.selector$ = selector$.pipe( | ||
@@ -40,3 +50,3 @@ publishReplay(1), | ||
) | ||
this.lastEmit = lastEmit || [] | ||
this.lastEmit = lastEmit | ||
} | ||
@@ -77,2 +87,5 @@ | ||
map((result: T[]) => { | ||
if (!this.lastEmit) { | ||
return initialTraceResult(result) | ||
} | ||
const ops = diff(this.lastEmit, result, pk) | ||
@@ -79,0 +92,0 @@ return { result, ...ops } |
@@ -29,3 +29,3 @@ export enum OpType { | ||
// as an example, use diff to patch data | ||
export const patch = <T>(ops: Op[], oldList: T[], newList: T[]) => { | ||
export const patch = <T>(ops: ReadonlyArray<Op>, oldList: ReadonlyArray<T>, newList: ReadonlyArray<T>) => { | ||
if (!oldList.length) { | ||
@@ -46,3 +46,3 @@ return newList | ||
export const getPatchResult = <T>(oldList: T[], newList: T[], ops: Ops): T[] => { | ||
export const getPatchResult = <T>(oldList: ReadonlyArray<T>, newList: ReadonlyArray<T>, ops: Ops): ReadonlyArray<T> => { | ||
switch (ops.type) { | ||
@@ -125,3 +125,3 @@ case OpsType.Error: | ||
export function diff<T>(oldList: T[], newList: T[], pk = '_id'): Ops { | ||
export function diff<T>(oldList: ReadonlyArray<T>, newList: ReadonlyArray<T>, pk = '_id'): Ops { | ||
const prev = oldList | ||
@@ -180,3 +180,3 @@ const curr = newList | ||
const arrayIsSame = reused === curr.length && prev.length === curr.length && reused !== 0 | ||
const arrayIsSame = reused === curr.length && prev.length === curr.length | ||
return { | ||
@@ -183,0 +183,0 @@ type: arrayIsSame ? OpsType.ShouldSkip : OpsType.Success, |
@@ -1,1 +0,1 @@ | ||
export default '0.10.4-alpha.13-diff' | ||
export default '0.10.4-alpha.14-diff-alpha0.10.4-alpha.14-diff-diff-alpha0.10.4-alpha.14-diff-alpha0.10.4-alpha.14-diff-diff-diff-alpha0.10.4-alpha.14-diff-alpha0.10.4-alpha.14-diff-diff-alpha0.10.4-alpha.14-diff-alpha0.10.4-alpha.14-diff-diff-diff-lazyassert' |
@@ -7,10 +7,10 @@ import { Observable } from 'rxjs/Observable'; | ||
export declare type TraceResult<T> = Ops & { | ||
result: T[]; | ||
result: ReadonlyArray<T>; | ||
}; | ||
export declare type SelectorMeta<T> = Selector<T> | ProxySelector<T>; | ||
export declare class QueryToken<T> { | ||
private lastEmit; | ||
selector$: Observable<SelectorMeta<T>>; | ||
private consumed; | ||
private lastEmit; | ||
constructor(selector$: Observable<SelectorMeta<T>>, lastEmit?: T[]); | ||
constructor(selector$: Observable<SelectorMeta<T>>, lastEmit?: ReadonlyArray<T> | undefined); | ||
setLastEmit(data: T[]): void; | ||
@@ -17,0 +17,0 @@ map<K>(fn: OperatorFunction<T[], K[]>): QueryToken<K>; |
@@ -18,9 +18,16 @@ "use strict"; | ||
var diff_1 = require("../../utils/diff"); | ||
function initialTraceResult(list) { | ||
return { | ||
type: diff_1.OpsType.Success, | ||
ops: list.map(function (_value, index) { return ({ type: diff_1.OpType.New, index: index }); }), | ||
result: list | ||
}; | ||
} | ||
var skipWhileProxySelector = skipWhile_1.skipWhile(function (v) { return v instanceof ProxySelector_1.ProxySelector; }); | ||
var QueryToken = /** @class */ (function () { | ||
function QueryToken(selector$, lastEmit) { | ||
this.lastEmit = lastEmit; | ||
this.consumed = false; | ||
this.lastEmit = []; | ||
this.selector$ = selector$.pipe(publishReplay_1.publishReplay(1), refCount_1.refCount()); | ||
this.lastEmit = lastEmit || []; | ||
this.lastEmit = lastEmit; | ||
} | ||
@@ -47,2 +54,5 @@ QueryToken.prototype.setLastEmit = function (data) { | ||
return this.changes().pipe(map_1.map(function (result) { | ||
if (!_this.lastEmit) { | ||
return initialTraceResult(result); | ||
} | ||
var ops = diff_1.diff(_this.lastEmit, result, pk); | ||
@@ -49,0 +59,0 @@ return tslib_1.__assign({ result: result }, ops); |
@@ -19,4 +19,4 @@ export declare enum OpType { | ||
}; | ||
export declare const patch: <T>(ops: Op[], oldList: T[], newList: T[]) => T[]; | ||
export declare const getPatchResult: <T>(oldList: T[], newList: T[], ops: Ops) => T[]; | ||
export declare function diff<T>(oldList: T[], newList: T[], pk?: string): Ops; | ||
export declare const patch: <T>(ops: ReadonlyArray<Op>, oldList: ReadonlyArray<T>, newList: ReadonlyArray<T>) => ReadonlyArray<T>; | ||
export declare const getPatchResult: <T>(oldList: ReadonlyArray<T>, newList: ReadonlyArray<T>, ops: Ops) => ReadonlyArray<T>; | ||
export declare function diff<T>(oldList: ReadonlyArray<T>, newList: ReadonlyArray<T>, pk?: string): Ops; |
@@ -141,3 +141,3 @@ "use strict"; | ||
} | ||
var arrayIsSame = reused === curr.length && prev.length === curr.length && reused !== 0; | ||
var arrayIsSame = reused === curr.length && prev.length === curr.length; | ||
return { | ||
@@ -144,0 +144,0 @@ type: arrayIsSame ? OpsType.ShouldSkip : OpsType.Success, |
@@ -1,2 +0,2 @@ | ||
declare const _default: "0.10.4-alpha.13-diff"; | ||
declare const _default: "0.10.4-alpha.14-diff-alpha0.10.4-alpha.14-diff-diff-alpha0.10.4-alpha.14-diff-alpha0.10.4-alpha.14-diff-diff-diff-alpha0.10.4-alpha.14-diff-alpha0.10.4-alpha.14-diff-diff-alpha0.10.4-alpha.14-diff-alpha0.10.4-alpha.14-diff-diff-diff-lazyassert"; | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = '0.10.4-alpha.13-diff'; | ||
exports.default = '0.10.4-alpha.14-diff-alpha0.10.4-alpha.14-diff-diff-alpha0.10.4-alpha.14-diff-alpha0.10.4-alpha.14-diff-diff-diff-alpha0.10.4-alpha.14-diff-alpha0.10.4-alpha.14-diff-diff-alpha0.10.4-alpha.14-diff-alpha0.10.4-alpha.14-diff-diff-diff-lazyassert'; | ||
//# sourceMappingURL=version.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
297056
0.63%5319
0.47%