reactivedb
Advanced tools
Comparing version 0.10.4-alpha.15-diff2 to 0.10.4-alpha.16-diff
@@ -68,6 +68,2 @@ /// <reference types="lovefield" /> | ||
} | ||
export interface ConcatInfo { | ||
length: number; | ||
consumed: boolean; | ||
} | ||
export interface Record { | ||
@@ -74,0 +70,0 @@ [property: string]: number; |
{ | ||
"name": "reactivedb", | ||
"version": "0.10.4-alpha.15-diff2", | ||
"version": "0.10.4-alpha.16-diff", | ||
"description": "Reactive ORM for Lovefield", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -78,7 +78,2 @@ import { Observable } from 'rxjs/Observable' | ||
export interface ConcatInfo { | ||
length: number | ||
consumed: boolean | ||
} | ||
export interface Record { | ||
@@ -85,0 +80,0 @@ [property: string]: number |
@@ -6,8 +6,8 @@ import { Observable } from 'rxjs/Observable' | ||
import { map } from 'rxjs/operators/map' | ||
import { pairwise } from 'rxjs/operators/pairwise' | ||
import { publishReplay } from 'rxjs/operators/publishReplay' | ||
import { refCount } from 'rxjs/operators/refCount' | ||
import { skipWhile } from 'rxjs/operators/skipWhile' | ||
import { startWith } from 'rxjs/operators/startWith' | ||
import { switchMap } from 'rxjs/operators/switchMap' | ||
import { startWith } from 'rxjs/operators/startWith' | ||
import { pairwise } from 'rxjs/operators/pairwise' | ||
import { take } from 'rxjs/operators/take' | ||
@@ -19,6 +19,16 @@ import { tap } from 'rxjs/operators/tap' | ||
import { TokenConsumed } from '../../exception/token' | ||
import { diff, Ops, OpsType, concatDiff } from '../../utils/diff' | ||
import { diff, Ops, OpsType, OpType } from '../../utils/diff' | ||
export type TraceResult<T> = Ops<T> | ||
export type TraceResult<T> = Ops & { | ||
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> | ||
@@ -33,12 +43,6 @@ | ||
private consumed = false | ||
private lastEmit: ReadonlyArray<T> | undefined | ||
private trace: ReadonlyArray<T> | undefined | ||
private consume = () => { | ||
assert(!this.consumed, TokenConsumed()) | ||
this.consumed = true | ||
} | ||
constructor( | ||
selector$: Observable<SelectorMeta<T>>, | ||
public concatConsumed = false | ||
) { | ||
constructor(selector$: Observable<SelectorMeta<T>>, trace?: ReadonlyArray<T>) { | ||
this.selector$ = selector$.pipe( | ||
@@ -48,4 +52,9 @@ publishReplay(1), | ||
) | ||
this.trace = trace | ||
} | ||
setTrace(data: T[]) { | ||
this.trace = data | ||
} | ||
map<K>(fn: OperatorFunction<T[], K[]>) { | ||
@@ -59,4 +68,6 @@ this.selector$ = this.selector$.pipe( | ||
values(): Observable<T[]> { | ||
assert(!this.consumed, TokenConsumed()) | ||
this.consumed = true | ||
return this.selector$.pipe( | ||
tap(this.consume), | ||
switchMap(s => s.values()), | ||
@@ -68,5 +79,7 @@ take(1) | ||
changes(): Observable<T[]> { | ||
assert(!this.consumed, TokenConsumed()) | ||
this.consumed = true | ||
return this.selector$.pipe( | ||
tap(this.consume), | ||
switchMap(s => s.changes()), | ||
switchMap(s => s.changes()) | ||
) | ||
@@ -76,14 +89,15 @@ } | ||
traces(pk?: string): Observable<TraceResult<T>> { | ||
return this.selector$.pipe( | ||
tap(this.consume), | ||
switchMap(s => s.changes().pipe( | ||
startWith<T[]>([]), | ||
pairwise(), | ||
map(([lastEmit, result], i): TraceResult<T> => | ||
i === 0 && !(s instanceof ProxySelector) && s.concatInfo && (s.concatInfo.consumed || this.concatConsumed) | ||
? concatDiff(result, s.concatInfo!.length) | ||
: diff(lastEmit, result, pk) | ||
), | ||
filter(({ type }) => type !== OpsType.ShouldSkip), | ||
)), | ||
return this.changes().pipe( | ||
startWith<undefined | ReadonlyArray<T>>(this.trace), | ||
pairwise(), | ||
map(([prev, curr]) => { | ||
const result = curr! | ||
if (!prev) { | ||
return initialTraceResult(result) | ||
} | ||
const ops = diff(prev, result, pk) | ||
return { result, ...ops } | ||
}), | ||
filter(({ type }) => type !== OpsType.ShouldSkip), | ||
tap(({ result }) => (this.lastEmit = result)), | ||
) | ||
@@ -95,3 +109,3 @@ } | ||
const newSelector$ = Observable.from(tokens).pipe( | ||
map((token) => token.selector$.pipe(skipWhileProxySelector)), | ||
map(token => token.selector$.pipe(skipWhileProxySelector)), | ||
combineAll<Observable<Selector<T>>, Selector<T>[]>(), | ||
@@ -103,3 +117,3 @@ map((r) => { | ||
) | ||
return new QueryToken<T>(newSelector$, this.concatConsumed) | ||
return new QueryToken<T>(newSelector$, this.lastEmit) | ||
} | ||
@@ -110,3 +124,3 @@ | ||
const newSelector$ = Observable.from(tokens).pipe( | ||
map((token) => token.selector$.pipe(skipWhileProxySelector)), | ||
map(token => token.selector$.pipe(skipWhileProxySelector)), | ||
combineAll<Observable<Selector<T>>, Selector<T>[]>(), | ||
@@ -118,3 +132,3 @@ map((r) => { | ||
) | ||
return new QueryToken<T>(newSelector$) | ||
return new QueryToken<T>(newSelector$, this.lastEmit) | ||
} | ||
@@ -121,0 +135,0 @@ |
@@ -12,3 +12,2 @@ import { Observer } from 'rxjs/Observer' | ||
import { switchMap } from 'rxjs/operators/switchMap' | ||
import { tap } from 'rxjs/operators/tap' | ||
import { async } from 'rxjs/scheduler/async' | ||
@@ -20,3 +19,3 @@ import * as lf from 'lovefield' | ||
import { PredicateProvider } from './PredicateProvider' | ||
import { ShapeMatcher, OrderInfo, StatementType, ConcatInfo } from '../../interface' | ||
import { ShapeMatcher, OrderInfo, StatementType } from '../../interface' | ||
import { mapFn } from './mapFn' | ||
@@ -41,8 +40,5 @@ | ||
}) | ||
const concatInfo = { length: meta.limit! - meta.skip!, consumed: meta.consumed } | ||
return new Selector( | ||
db, lselect, shape, predicateProvider, | ||
maxLimit.limit! + maxLimit.skip!, minSkip.skip, meta.orderDescriptions, | ||
concatInfo, | ||
maxLimit.limit! + maxLimit.skip!, minSkip.skip, meta.orderDescriptions | ||
) | ||
@@ -94,6 +90,2 @@ .map<U>(meta.mapFn) | ||
private consume = () => { | ||
this.consumed = true | ||
} | ||
private mapFn: (stream$: Observable<T[]>) => Observable<any[]> = mapFn | ||
@@ -201,4 +193,3 @@ | ||
private skip?: number, | ||
private orderDescriptions?: OrderInfo[], | ||
readonly concatInfo?: ConcatInfo, | ||
private orderDescriptions?: OrderInfo[] | ||
) { | ||
@@ -214,3 +205,2 @@ this.predicateProvider = this.normPredicateProvider(predicateProvider) | ||
values(): Observable<T[]> | never { | ||
let values$ | ||
if (typeof this.limit !== 'undefined' || typeof this.skip !== 'undefined') { | ||
@@ -220,9 +210,6 @@ const p = this.rangeQuery.exec() | ||
.then(pks => this.getValue(this.getQuery(this.inPKs(pks)))) | ||
values$ = this.mapFn(Observable.fromPromise(p)) | ||
return this.mapFn(Observable.fromPromise(p)) | ||
} else { | ||
values$ = this.mapFn(Observable.fromPromise(this.getValue(this.getQuery()) as Promise<T[]>)) | ||
return this.mapFn(Observable.fromPromise(this.getValue(this.getQuery()) as Promise<T[]>)) | ||
} | ||
return values$.pipe( | ||
tap(this.consume) | ||
) | ||
} | ||
@@ -249,3 +236,2 @@ | ||
assert(equal, tokenErrMsg.TokenConcatFailed()) | ||
console.info('concat', this.consumed) | ||
@@ -256,6 +242,3 @@ return Selector.concatFactory(this, ...selectors) | ||
changes(): Observable<T[]> | never { | ||
return this.mapFn(this.change$).pipe( | ||
tap(this.consume), | ||
tap(() => console.info('consumed')) | ||
) | ||
return this.mapFn(this.change$) | ||
} | ||
@@ -262,0 +245,0 @@ |
@@ -8,10 +8,5 @@ export enum OpType { | ||
export type Op<T = any> = { | ||
type: OpType.Reuse | ||
export type Op = { | ||
type: OpType | ||
index: number | ||
value?: undefined | ||
} | { | ||
type: OpType.New | ||
value: T | ||
index?: undefined | ||
} | ||
@@ -28,34 +23,29 @@ | ||
export type Ops<T = any> = { | ||
type: OpsType.Error | ||
result: ReadonlyArray<T> | ||
ops?: undefined | ||
export type Ops = { | ||
type: OpsType | ||
ops: Op[] | ||
message?: string | ||
} | { | ||
type: OpsType.Success | ||
ops: Op<T>[] | ||
result?: undefined | ||
message?: string | ||
} | { | ||
type: OpsType.ShouldSkip | ||
ops?: undefined | ||
result?: undefined | ||
message?: string | ||
} | ||
// as an example, use diff to patch data | ||
export const patch = <T>(ops: ReadonlyArray<Op>, oldList: ReadonlyArray<T>) => { | ||
return ops.map(op => { | ||
export const patch = <T>(ops: ReadonlyArray<Op>, oldList: ReadonlyArray<T>, newList: ReadonlyArray<T>) => { | ||
if (!oldList.length) { | ||
return newList | ||
} | ||
return newList.map((data, i) => { | ||
const op = ops[i] | ||
if (op.type === OpType.Reuse) { | ||
return oldList[op.index] | ||
} else { | ||
return op.value | ||
} | ||
return data | ||
}) | ||
} | ||
export const getPatchResult = <T>(oldList: ReadonlyArray<T>, ops: Ops): ReadonlyArray<T> => { | ||
export const getPatchResult = <T>(oldList: ReadonlyArray<T>, newList: ReadonlyArray<T>, ops: Ops): ReadonlyArray<T> => { | ||
switch (ops.type) { | ||
case OpsType.Error: | ||
return ops.result | ||
return newList | ||
case OpsType.ShouldSkip: | ||
@@ -65,3 +55,3 @@ return oldList | ||
default: | ||
return patch(ops.ops, oldList) | ||
return patch(ops.ops, oldList, newList) | ||
} | ||
@@ -86,3 +76,3 @@ } | ||
for (let i = length; i-- !== 0;) { | ||
for (let i = length; i-- !== 0; ) { | ||
if (!fastEqual(left[i], right[i])) { | ||
@@ -118,3 +108,3 @@ return false | ||
for (let k = LeftLen; k-- !== 0;) { | ||
for (let k = LeftLen; k-- !== 0; ) { | ||
if (!right.hasOwnProperty(keys[k])) { | ||
@@ -125,3 +115,3 @@ return false | ||
for (let j = LeftLen; j-- !== 0;) { | ||
for (let j = LeftLen; j-- !== 0; ) { | ||
const key = keys[j] | ||
@@ -139,3 +129,3 @@ if (!fastEqual(left[key], right[key])) { | ||
export function diff<T>(oldList: ReadonlyArray<T>, newList: ReadonlyArray<T>, pk = '_id'): Ops<T> { | ||
export function diff<T>(oldList: ReadonlyArray<T>, newList: ReadonlyArray<T>, pk = '_id'): Ops { | ||
const prev = oldList | ||
@@ -147,3 +137,3 @@ const curr = newList | ||
type: OpsType.Error, | ||
result: newList, | ||
ops: [], | ||
message: `cannot compare non-list object`, | ||
@@ -159,3 +149,3 @@ } | ||
type: OpsType.Error, | ||
result: newList, | ||
ops: [], | ||
message: `cannot find pk: ${pk} at prev.${i}`, | ||
@@ -167,3 +157,3 @@ } | ||
const ret: Op<T>[] = [] | ||
const ret: Op[] = [] | ||
let reused = 0 | ||
@@ -176,3 +166,3 @@ | ||
type: OpsType.Error, | ||
result: newList, | ||
ops: [], | ||
message: `cannot find pk: ${pk} at curr.${k}`, | ||
@@ -185,5 +175,5 @@ } | ||
if (prevIndex !== undefined) { | ||
const isEqual = fastEqual(curr[k], prev[prevIndex]) | ||
const isEqual = fastEqual((curr as any)[k], (prev as any)[prevIndex]) | ||
// if equal then reuse the previous data otherwise use the new data | ||
const op: Op<T> = isEqual ? { type: OpType.Reuse, index: prevIndex } : { type: OpType.New, value: curr[k] } | ||
const op: Op = isEqual ? { type: OpType.Reuse, index: prevIndex } : { type: OpType.New, index: k } | ||
@@ -195,3 +185,3 @@ if (prevIndex === k && isEqual) { | ||
} else { | ||
ret.push({ type: OpType.New, value: curr[k] }) | ||
ret.push({ type: OpType.New, index: k }) | ||
} | ||
@@ -201,16 +191,6 @@ } | ||
const arrayIsSame = reused === curr.length && prev.length === curr.length | ||
return arrayIsSame | ||
? { type: OpsType.ShouldSkip } | ||
: { type: OpsType.Success, ops: ret } | ||
} | ||
export const concatDiff = <T>(newList: ReadonlyArray<T>, concatLength: number) => { | ||
return { | ||
type: OpsType.Success, | ||
ops: newList.map((value, index) => { | ||
return index >= concatLength | ||
? { type: OpType.New, value } | ||
: { type: OpType.Reuse, index } | ||
}) | ||
} as Ops<T> | ||
type: arrayIsSame ? OpsType.ShouldSkip : OpsType.Success, | ||
ops: ret, | ||
} | ||
} |
@@ -1,2 +0,1 @@ | ||
/* tslint:disable */ | ||
export default '0.10.4-alpha.15-diff2' | ||
export default '0.10.4-alpha.16-diff' |
@@ -6,10 +6,13 @@ import { Observable } from 'rxjs/Observable'; | ||
import { Ops } from '../../utils/diff'; | ||
export declare type TraceResult<T> = Ops<T>; | ||
export declare type TraceResult<T> = Ops & { | ||
result: ReadonlyArray<T>; | ||
}; | ||
export declare type SelectorMeta<T> = Selector<T> | ProxySelector<T>; | ||
export declare class QueryToken<T> { | ||
concatConsumed: boolean; | ||
selector$: Observable<SelectorMeta<T>>; | ||
private consumed; | ||
private consume; | ||
constructor(selector$: Observable<SelectorMeta<T>>, concatConsumed?: boolean); | ||
private lastEmit; | ||
private trace; | ||
constructor(selector$: Observable<SelectorMeta<T>>, trace?: ReadonlyArray<T>); | ||
setTrace(data: T[]): void; | ||
map<K>(fn: OperatorFunction<T[], K[]>): QueryToken<K>; | ||
@@ -16,0 +19,0 @@ values(): Observable<T[]>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var Observable_1 = require("rxjs/Observable"); | ||
@@ -7,8 +8,8 @@ var combineAll_1 = require("rxjs/operators/combineAll"); | ||
var map_1 = require("rxjs/operators/map"); | ||
var pairwise_1 = require("rxjs/operators/pairwise"); | ||
var publishReplay_1 = require("rxjs/operators/publishReplay"); | ||
var refCount_1 = require("rxjs/operators/refCount"); | ||
var skipWhile_1 = require("rxjs/operators/skipWhile"); | ||
var startWith_1 = require("rxjs/operators/startWith"); | ||
var switchMap_1 = require("rxjs/operators/switchMap"); | ||
var startWith_1 = require("rxjs/operators/startWith"); | ||
var pairwise_1 = require("rxjs/operators/pairwise"); | ||
var take_1 = require("rxjs/operators/take"); | ||
@@ -20,15 +21,19 @@ var tap_1 = require("rxjs/operators/tap"); | ||
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$, concatConsumed) { | ||
if (concatConsumed === void 0) { concatConsumed = false; } | ||
var _this = this; | ||
this.concatConsumed = concatConsumed; | ||
function QueryToken(selector$, trace) { | ||
this.consumed = false; | ||
this.consume = function () { | ||
assert_1.assert(!_this.consumed, token_1.TokenConsumed()); | ||
_this.consumed = true; | ||
}; | ||
this.selector$ = selector$.pipe(publishReplay_1.publishReplay(1), refCount_1.refCount()); | ||
this.trace = trace; | ||
} | ||
QueryToken.prototype.setTrace = function (data) { | ||
this.trace = data; | ||
}; | ||
QueryToken.prototype.map = function (fn) { | ||
@@ -39,18 +44,28 @@ this.selector$ = this.selector$.pipe(tap_1.tap(function (selector) { return selector.map(fn); })); | ||
QueryToken.prototype.values = function () { | ||
return this.selector$.pipe(tap_1.tap(this.consume), switchMap_1.switchMap(function (s) { return s.values(); }), take_1.take(1)); | ||
assert_1.assert(!this.consumed, token_1.TokenConsumed()); | ||
this.consumed = true; | ||
return this.selector$.pipe(switchMap_1.switchMap(function (s) { return s.values(); }), take_1.take(1)); | ||
}; | ||
QueryToken.prototype.changes = function () { | ||
return this.selector$.pipe(tap_1.tap(this.consume), switchMap_1.switchMap(function (s) { return s.changes(); })); | ||
assert_1.assert(!this.consumed, token_1.TokenConsumed()); | ||
this.consumed = true; | ||
return this.selector$.pipe(switchMap_1.switchMap(function (s) { return s.changes(); })); | ||
}; | ||
QueryToken.prototype.traces = function (pk) { | ||
var _this = this; | ||
return this.selector$.pipe(tap_1.tap(this.consume), switchMap_1.switchMap(function (s) { return s.changes().pipe(startWith_1.startWith([]), pairwise_1.pairwise(), map_1.map(function (_a, i) { | ||
var lastEmit = _a[0], result = _a[1]; | ||
return i === 0 && !(s instanceof ProxySelector_1.ProxySelector) && s.concatInfo && (s.concatInfo.consumed || _this.concatConsumed) | ||
? diff_1.concatDiff(result, s.concatInfo.length) | ||
: diff_1.diff(lastEmit, result, pk); | ||
return this.changes().pipe(startWith_1.startWith(this.trace), pairwise_1.pairwise(), map_1.map(function (_a) { | ||
var prev = _a[0], curr = _a[1]; | ||
var result = curr; | ||
if (!prev) { | ||
return initialTraceResult(result); | ||
} | ||
var ops = diff_1.diff(prev, result, pk); | ||
return tslib_1.__assign({ result: result }, ops); | ||
}), filter_1.filter(function (_a) { | ||
var type = _a.type; | ||
return type !== diff_1.OpsType.ShouldSkip; | ||
})); })); | ||
}), tap_1.tap(function (_a) { | ||
var result = _a.result; | ||
return (_this.lastEmit = result); | ||
})); | ||
}; | ||
@@ -68,3 +83,3 @@ QueryToken.prototype.concat = function () { | ||
})); | ||
return new QueryToken(newSelector$, this.concatConsumed); | ||
return new QueryToken(newSelector$, this.lastEmit); | ||
}; | ||
@@ -82,3 +97,3 @@ QueryToken.prototype.combine = function () { | ||
})); | ||
return new QueryToken(newSelector$); | ||
return new QueryToken(newSelector$, this.lastEmit); | ||
}; | ||
@@ -85,0 +100,0 @@ QueryToken.prototype.toString = function () { |
@@ -6,3 +6,3 @@ /// <reference types="lovefield" /> | ||
import { PredicateProvider } from './PredicateProvider'; | ||
import { ShapeMatcher, OrderInfo, ConcatInfo } from '../../interface'; | ||
import { ShapeMatcher, OrderInfo } from '../../interface'; | ||
export declare class Selector<T> { | ||
@@ -16,7 +16,5 @@ db: lf.Database; | ||
private orderDescriptions; | ||
readonly concatInfo: ConcatInfo | undefined; | ||
private static concatFactory<U>(...metaDatas); | ||
private static combineFactory<U>(...metaDatas); | ||
private static stringifyOrder(orderInfo); | ||
private consume; | ||
private mapFn; | ||
@@ -31,3 +29,3 @@ select: string; | ||
private normPredicateProvider(pp?); | ||
constructor(db: lf.Database, lselect: lf.query.Select, shape: ShapeMatcher, predicateProvider?: PredicateProvider<T> | undefined, limit?: number | undefined, skip?: number | undefined, orderDescriptions?: OrderInfo[] | undefined, concatInfo?: ConcatInfo | undefined); | ||
constructor(db: lf.Database, lselect: lf.query.Select, shape: ShapeMatcher, predicateProvider?: PredicateProvider<T> | undefined, limit?: number | undefined, skip?: number | undefined, orderDescriptions?: OrderInfo[] | undefined); | ||
toString(): string; | ||
@@ -34,0 +32,0 @@ values(): Observable<T[]> | never; |
@@ -12,3 +12,2 @@ "use strict"; | ||
var switchMap_1 = require("rxjs/operators/switchMap"); | ||
var tap_1 = require("rxjs/operators/tap"); | ||
var async_1 = require("rxjs/scheduler/async"); | ||
@@ -22,4 +21,3 @@ var lf = require("lovefield"); | ||
var Selector = /** @class */ (function () { | ||
function Selector(db, lselect, shape, predicateProvider, limit, skip, orderDescriptions, concatInfo) { | ||
var _this = this; | ||
function Selector(db, lselect, shape, predicateProvider, limit, skip, orderDescriptions) { | ||
this.db = db; | ||
@@ -32,6 +30,2 @@ this.lselect = lselect; | ||
this.orderDescriptions = orderDescriptions; | ||
this.concatInfo = concatInfo; | ||
this.consume = function () { | ||
_this.consumed = true; | ||
}; | ||
this.mapFn = mapFn_1.mapFn; | ||
@@ -60,4 +54,3 @@ this._change$ = null; | ||
}); | ||
var concatInfo = { length: meta.limit - meta.skip, consumed: meta.consumed }; | ||
return new Selector(db, lselect, shape, predicateProvider, maxLimit.limit + maxLimit.skip, minSkip.skip, meta.orderDescriptions, concatInfo) | ||
return new Selector(db, lselect, shape, predicateProvider, maxLimit.limit + maxLimit.skip, minSkip.skip, meta.orderDescriptions) | ||
.map(meta.mapFn); | ||
@@ -187,3 +180,2 @@ }; | ||
var _this = this; | ||
var values$; | ||
if (typeof this.limit !== 'undefined' || typeof this.skip !== 'undefined') { | ||
@@ -193,8 +185,7 @@ var p = this.rangeQuery.exec() | ||
.then(function (pks) { return _this.getValue(_this.getQuery(_this.inPKs(pks))); }); | ||
values$ = this.mapFn(Observable_1.Observable.fromPromise(p)); | ||
return this.mapFn(Observable_1.Observable.fromPromise(p)); | ||
} | ||
else { | ||
values$ = this.mapFn(Observable_1.Observable.fromPromise(this.getValue(this.getQuery()))); | ||
return this.mapFn(Observable_1.Observable.fromPromise(this.getValue(this.getQuery()))); | ||
} | ||
return values$.pipe(tap_1.tap(this.consume)); | ||
}; | ||
@@ -224,7 +215,6 @@ Selector.prototype.combine = function () { | ||
utils_1.assert(equal, exception_1.tokenErrMsg.TokenConcatFailed()); | ||
console.info('concat', this.consumed); | ||
return Selector.concatFactory.apply(Selector, [this].concat(selectors)); | ||
}; | ||
Selector.prototype.changes = function () { | ||
return this.mapFn(this.change$).pipe(tap_1.tap(this.consume), tap_1.tap(function () { return console.info('consumed'); })); | ||
return this.mapFn(this.change$); | ||
}; | ||
@@ -231,0 +221,0 @@ Selector.prototype.map = function (fn) { |
@@ -5,10 +5,5 @@ export declare enum OpType { | ||
} | ||
export declare type Op<T = any> = { | ||
type: OpType.Reuse; | ||
export declare type Op = { | ||
type: OpType; | ||
index: number; | ||
value?: undefined; | ||
} | { | ||
type: OpType.New; | ||
value: T; | ||
index?: undefined; | ||
}; | ||
@@ -20,21 +15,9 @@ export declare enum OpsType { | ||
} | ||
export declare type Ops<T = any> = { | ||
type: OpsType.Error; | ||
result: ReadonlyArray<T>; | ||
ops?: undefined; | ||
export declare type Ops = { | ||
type: OpsType; | ||
ops: Op[]; | ||
message?: string; | ||
} | { | ||
type: OpsType.Success; | ||
ops: Op<T>[]; | ||
result?: undefined; | ||
message?: string; | ||
} | { | ||
type: OpsType.ShouldSkip; | ||
ops?: undefined; | ||
result?: undefined; | ||
message?: string; | ||
}; | ||
export declare const patch: <T>(ops: ReadonlyArray<Op<any>>, oldList: ReadonlyArray<T>) => any[]; | ||
export declare const getPatchResult: <T>(oldList: ReadonlyArray<T>, ops: Ops<any>) => ReadonlyArray<T>; | ||
export declare function diff<T>(oldList: ReadonlyArray<T>, newList: ReadonlyArray<T>, pk?: string): Ops<T>; | ||
export declare const concatDiff: <T>(newList: ReadonlyArray<T>, concatLength: number) => Ops<T>; | ||
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; |
@@ -20,16 +20,18 @@ "use strict"; | ||
// as an example, use diff to patch data | ||
exports.patch = function (ops, oldList) { | ||
return ops.map(function (op) { | ||
exports.patch = function (ops, oldList, newList) { | ||
if (!oldList.length) { | ||
return newList; | ||
} | ||
return newList.map(function (data, i) { | ||
var op = ops[i]; | ||
if (op.type === OpType.Reuse) { | ||
return oldList[op.index]; | ||
} | ||
else { | ||
return op.value; | ||
} | ||
return data; | ||
}); | ||
}; | ||
exports.getPatchResult = function (oldList, ops) { | ||
exports.getPatchResult = function (oldList, newList, ops) { | ||
switch (ops.type) { | ||
case OpsType.Error: | ||
return ops.result; | ||
return newList; | ||
case OpsType.ShouldSkip: | ||
@@ -39,3 +41,3 @@ return oldList; | ||
default: | ||
return exports.patch(ops.ops, oldList); | ||
return exports.patch(ops.ops, oldList, newList); | ||
} | ||
@@ -100,3 +102,3 @@ }; | ||
type: OpsType.Error, | ||
result: newList, | ||
ops: [], | ||
message: "cannot compare non-list object", | ||
@@ -111,3 +113,3 @@ }; | ||
type: OpsType.Error, | ||
result: newList, | ||
ops: [], | ||
message: "cannot find pk: " + pk + " at prev." + i, | ||
@@ -125,3 +127,3 @@ }; | ||
type: OpsType.Error, | ||
result: newList, | ||
ops: [], | ||
message: "cannot find pk: " + pk + " at curr." + k, | ||
@@ -134,3 +136,3 @@ }; | ||
// if equal then reuse the previous data otherwise use the new data | ||
var op = isEqual ? { type: OpType.Reuse, index: prevIndex } : { type: OpType.New, value: curr[k] }; | ||
var op = isEqual ? { type: OpType.Reuse, index: prevIndex } : { type: OpType.New, index: k }; | ||
if (prevIndex === k && isEqual) { | ||
@@ -142,21 +144,12 @@ reused++; | ||
else { | ||
ret.push({ type: OpType.New, value: curr[k] }); | ||
ret.push({ type: OpType.New, index: k }); | ||
} | ||
} | ||
var arrayIsSame = reused === curr.length && prev.length === curr.length; | ||
return arrayIsSame | ||
? { type: OpsType.ShouldSkip } | ||
: { type: OpsType.Success, ops: ret }; | ||
return { | ||
type: arrayIsSame ? OpsType.ShouldSkip : OpsType.Success, | ||
ops: ret, | ||
}; | ||
} | ||
exports.diff = diff; | ||
exports.concatDiff = function (newList, concatLength) { | ||
return { | ||
type: OpsType.Success, | ||
ops: newList.map(function (value, index) { | ||
return index >= concatLength | ||
? { type: OpType.New, value: value } | ||
: { type: OpType.Reuse, index: index }; | ||
}) | ||
}; | ||
}; | ||
//# sourceMappingURL=diff.js.map |
@@ -1,2 +0,2 @@ | ||
declare const _default: "0.10.4-alpha.15-diff2"; | ||
declare const _default: "0.10.4-alpha.16-diff"; | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* tslint:disable */ | ||
exports.default = '0.10.4-alpha.15-diff2'; | ||
exports.default = '0.10.4-alpha.16-diff'; | ||
//# 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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
296894
5324