reactivedb
Advanced tools
Comparing version 0.10.4-alpha.6-diff to 0.10.4-alpha.7-diff
{ | ||
"name": "reactivedb", | ||
"version": "0.10.4-alpha.6-diff", | ||
"version": "0.10.4-alpha.7-diff", | ||
"description": "Reactive ORM for Lovefield", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
import { Observable } from 'rxjs/Observable' | ||
import { OperatorFunction } from 'rxjs/interfaces' | ||
import { map } from 'rxjs/operators/map' | ||
import { tap } from 'rxjs/operators/tap' | ||
import { Query } from '../../interface' | ||
import { mapFn } from './mapFn' | ||
import diff, { Ops } from '../../utils/diff' | ||
@@ -18,4 +16,3 @@ export class ProxySelector<T> { | ||
public query: Query<T>, | ||
public tableName: string, | ||
public lastEmit?: T[], | ||
public tableName: string | ||
) { | ||
@@ -32,20 +29,5 @@ this.request$ = request$.pipe( | ||
changes() { | ||
return this.mapFn(this.request$.pipe( | ||
tap((data: T[]) => this.lastEmit = data) | ||
)) | ||
return this.mapFn(this.request$) | ||
} | ||
getLastEmit(): T[] | undefined { | ||
return this.lastEmit | ||
} | ||
changesWithOps(pk?: string): Observable<{ result: T[], ops: Ops}> | never { | ||
return this.request$.pipe( | ||
map((result: T[]) => { | ||
const ops = diff(this.lastEmit || [], result, pk) | ||
return { result, ops } | ||
}), | ||
) | ||
} | ||
map<K>(fn: OperatorFunction<T[], K[]>) { | ||
@@ -52,0 +34,0 @@ this.mapFn = fn |
@@ -17,2 +17,7 @@ import { Observable } from 'rxjs/Observable' | ||
export interface TraceResult<T> { | ||
result: T[] | ||
ops: Ops | ||
} | ||
export type SelectorMeta<T> = Selector<T> | ProxySelector<T> | ||
@@ -25,4 +30,4 @@ | ||
selector$: Observable<SelectorMeta<T>> | ||
lastEmit: T[] = [] | ||
public lastEmit: T[] = [] | ||
private consumed = false | ||
@@ -38,6 +43,2 @@ | ||
getLastEmit() { | ||
return this.lastEmit | ||
} | ||
setLastEmit(data: T[]) { | ||
@@ -69,7 +70,7 @@ this.lastEmit = data | ||
return this.selector$.pipe( | ||
switchMap(s => s.changes()), | ||
switchMap(s => s.changes()) | ||
) | ||
} | ||
changesWithOps(pk?: string): Observable<{ result: T[], ops: Ops}> { | ||
traces(pk?: string): Observable<TraceResult<T>> { | ||
return this.changes() | ||
@@ -81,3 +82,3 @@ .pipe( | ||
}), | ||
tap((data) => this.lastEmit = data.result), | ||
tap(({ result }) => this.lastEmit = result), | ||
) | ||
@@ -88,3 +89,2 @@ } | ||
tokens.unshift(this) | ||
const newSelector$ = Observable.from(tokens).pipe( | ||
@@ -111,3 +111,3 @@ map(token => token.selector$.pipe(skipWhileProxySelector)), | ||
) | ||
return new QueryToken<T>(newSelector$) | ||
return new QueryToken<T>(newSelector$, this.lastEmit) | ||
} | ||
@@ -114,0 +114,0 @@ |
@@ -38,3 +38,2 @@ import { Observer } from 'rxjs/Observer' | ||
}) | ||
return new Selector( | ||
@@ -191,3 +190,3 @@ db, lselect, shape, predicateProvider, | ||
private skip?: number, | ||
private orderDescriptions?: OrderInfo[], | ||
private orderDescriptions?: OrderInfo[] | ||
) { | ||
@@ -194,0 +193,0 @@ this.predicateProvider = this.normPredicateProvider(predicateProvider) |
@@ -1,20 +0,8 @@ | ||
export type Location = { | ||
loc: number | ||
index: number | ||
} | ||
export enum OpType { | ||
export type Op = { | ||
// 0 = reuse | ||
// 1 = use new item | ||
Reuse, | ||
New, | ||
} | ||
export type Op = { | ||
type: OpType | ||
type: 0 | 1 | ||
index: number | ||
} | ||
export enum OpsType { | ||
Error, | ||
Success, | ||
SuccessAndSkip, | ||
} | ||
export type Ops = { | ||
@@ -24,3 +12,3 @@ // 0 = error | ||
// 2 = success but should skip | ||
type: OpsType | ||
type: 0 | 1 | 2 | ||
ops: Op[] | ||
@@ -30,2 +18,19 @@ message?: string | ||
// as an example, use diff to patch data | ||
export const patch = <T>(ops: Op[], oldList: T[], newList: T[]) => { | ||
if (!oldList.length) { | ||
return newList | ||
} | ||
return newList.map((data, i) => { | ||
const op = ops[i] | ||
if (op.type === 0) { | ||
return oldList[op.index] | ||
} | ||
return data | ||
}) | ||
} | ||
export default function diff<T>(oldList: T[], newList: T[], pk = '_id'): Ops { | ||
@@ -37,3 +42,3 @@ const prev = oldList | ||
return { | ||
type: OpsType.Error, | ||
type: 0, | ||
ops: [], | ||
@@ -52,3 +57,3 @@ message: `cannot compare non-list object`, | ||
return { | ||
type: OpsType.Error, | ||
type: 0, | ||
ops: [], | ||
@@ -66,3 +71,3 @@ message: `cannot find pk: ${pk} at prev.${i}`, | ||
return { | ||
type: OpsType.Error, | ||
type: 0, | ||
ops: [], | ||
@@ -151,3 +156,3 @@ message: `cannot find pk: ${pk} at curr.${j}`, | ||
// if equal then reuse the previous data otherwise use the new data | ||
const op: Op = isEqual ? { type: OpType.Reuse, index: prevIndex } : { type: OpType.New, index: k } | ||
const op: Op = isEqual ? { type: 0, index: prevIndex } : { type: 1, index: k } | ||
@@ -159,3 +164,3 @@ if (prevIndex === k && isEqual) { | ||
} else { | ||
ret.push({ type: OpType.New, index: k }) | ||
ret.push({ type: 1, index: k }) | ||
} | ||
@@ -166,5 +171,5 @@ } | ||
return { | ||
type: arrayIsSame ? OpsType.SuccessAndSkip : OpsType.Success, | ||
type: arrayIsSame ? 2 : 1, | ||
ops: ret, | ||
} | ||
} |
@@ -12,2 +12,3 @@ export * from './hash' | ||
export * from './try-catch' | ||
export * from './diff' | ||
export { warn } from './warn' |
@@ -1,1 +0,1 @@ | ||
export default '0.10.4-alpha.6-diff-alpha0.10.4-alpha.6-diff-diff-alpha0.10.4-alpha.6-diff-alpha0.10.4-alpha.6-diff-diff-diff' | ||
export default '0.10.4-alpha.7-diff-alpha0.10.4-alpha.7-diff-lazyassert' |
import { Observable } from 'rxjs/Observable'; | ||
import { OperatorFunction } from 'rxjs/interfaces'; | ||
import { Query } from '../../interface'; | ||
import { Ops } from '../../utils/diff'; | ||
export declare class ProxySelector<T> { | ||
query: Query<T>; | ||
tableName: string; | ||
lastEmit: T[] | undefined; | ||
request$: Observable<T[]>; | ||
private mapFn; | ||
constructor(request$: Observable<T | T[]>, query: Query<T>, tableName: string, lastEmit?: T[] | undefined); | ||
constructor(request$: Observable<T | T[]>, query: Query<T>, tableName: string); | ||
values(): Observable<any>; | ||
changes(): Observable<any>; | ||
getLastEmit(): T[] | undefined; | ||
changesWithOps(pk?: string): Observable<{ | ||
result: T[]; | ||
ops: Ops; | ||
}> | never; | ||
map<K>(fn: OperatorFunction<T[], K[]>): ProxySelector<K>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var map_1 = require("rxjs/operators/map"); | ||
var tap_1 = require("rxjs/operators/tap"); | ||
var mapFn_1 = require("./mapFn"); | ||
var diff_1 = require("../../utils/diff"); | ||
var ProxySelector = /** @class */ (function () { | ||
function ProxySelector(request$, query, tableName, lastEmit) { | ||
function ProxySelector(request$, query, tableName) { | ||
this.query = query; | ||
this.tableName = tableName; | ||
this.lastEmit = lastEmit; | ||
this.mapFn = mapFn_1.mapFn; | ||
@@ -19,15 +16,4 @@ this.request$ = request$.pipe(map_1.map(function (r) { return Array.isArray(r) ? r : [r]; })); | ||
ProxySelector.prototype.changes = function () { | ||
var _this = this; | ||
return this.mapFn(this.request$.pipe(tap_1.tap(function (data) { return _this.lastEmit = data; }))); | ||
return this.mapFn(this.request$); | ||
}; | ||
ProxySelector.prototype.getLastEmit = function () { | ||
return this.lastEmit; | ||
}; | ||
ProxySelector.prototype.changesWithOps = function (pk) { | ||
var _this = this; | ||
return this.request$.pipe(map_1.map(function (result) { | ||
var ops = diff_1.default(_this.lastEmit || [], result, pk); | ||
return { result: result, ops: ops }; | ||
})); | ||
}; | ||
ProxySelector.prototype.map = function (fn) { | ||
@@ -34,0 +20,0 @@ this.mapFn = fn; |
@@ -6,2 +6,6 @@ import { Observable } from 'rxjs/Observable'; | ||
import { Ops } from '../../utils/diff'; | ||
export interface TraceResult<T> { | ||
result: T[]; | ||
ops: Ops; | ||
} | ||
export declare type SelectorMeta<T> = Selector<T> | ProxySelector<T>; | ||
@@ -13,3 +17,2 @@ export declare class QueryToken<T> { | ||
constructor(selector$: Observable<SelectorMeta<T>>, lasEmit?: T[]); | ||
getLastEmit(): T[]; | ||
setLastEmit(data: T[]): void; | ||
@@ -19,6 +22,3 @@ map<K>(fn: OperatorFunction<T[], K[]>): QueryToken<K>; | ||
changes(): Observable<T[]>; | ||
changesWithOps(pk?: string): Observable<{ | ||
result: T[]; | ||
ops: Ops; | ||
}>; | ||
traces(pk?: string): Observable<TraceResult<T>>; | ||
concat(...tokens: QueryToken<T>[]): QueryToken<T>; | ||
@@ -25,0 +25,0 @@ combine(...tokens: QueryToken<any>[]): QueryToken<T>; |
@@ -24,5 +24,2 @@ "use strict"; | ||
} | ||
QueryToken.prototype.getLastEmit = function () { | ||
return this.lastEmit; | ||
}; | ||
QueryToken.prototype.setLastEmit = function (data) { | ||
@@ -45,3 +42,3 @@ this.lastEmit = data; | ||
}; | ||
QueryToken.prototype.changesWithOps = function (pk) { | ||
QueryToken.prototype.traces = function (pk) { | ||
var _this = this; | ||
@@ -52,3 +49,6 @@ return this.changes() | ||
return { result: result, ops: ops }; | ||
}), tap_1.tap(function (data) { return _this.lastEmit = data.result; })); | ||
}), tap_1.tap(function (_a) { | ||
var result = _a.result; | ||
return _this.lastEmit = result; | ||
})); | ||
}; | ||
@@ -79,3 +79,3 @@ QueryToken.prototype.concat = function () { | ||
})); | ||
return new QueryToken(newSelector$); | ||
return new QueryToken(newSelector$, this.lastEmit); | ||
}; | ||
@@ -82,0 +82,0 @@ QueryToken.prototype.toString = function () { |
@@ -1,23 +0,11 @@ | ||
export declare type Location = { | ||
loc: number; | ||
index: number; | ||
}; | ||
export declare enum OpType { | ||
Reuse = 0, | ||
New = 1, | ||
} | ||
export declare type Op = { | ||
type: OpType; | ||
type: 0 | 1; | ||
index: number; | ||
}; | ||
export declare enum OpsType { | ||
Error = 0, | ||
Success = 1, | ||
SuccessAndSkip = 2, | ||
} | ||
export declare type Ops = { | ||
type: OpsType; | ||
type: 0 | 1 | 2; | ||
ops: Op[]; | ||
message?: string; | ||
}; | ||
export declare const patch: <T>(ops: Op[], oldList: T[], newList: T[]) => T[]; | ||
export default function diff<T>(oldList: T[], newList: T[], pk?: string): Ops; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var OpType; | ||
(function (OpType) { | ||
// 0 = reuse | ||
// 1 = use new item | ||
OpType[OpType["Reuse"] = 0] = "Reuse"; | ||
OpType[OpType["New"] = 1] = "New"; | ||
})(OpType = exports.OpType || (exports.OpType = {})); | ||
var OpsType; | ||
(function (OpsType) { | ||
OpsType[OpsType["Error"] = 0] = "Error"; | ||
OpsType[OpsType["Success"] = 1] = "Success"; | ||
OpsType[OpsType["SuccessAndSkip"] = 2] = "SuccessAndSkip"; | ||
})(OpsType = exports.OpsType || (exports.OpsType = {})); | ||
// as an example, use diff to patch data | ||
exports.patch = function (ops, oldList, newList) { | ||
if (!oldList.length) { | ||
return newList; | ||
} | ||
return newList.map(function (data, i) { | ||
var op = ops[i]; | ||
if (op.type === 0) { | ||
return oldList[op.index]; | ||
} | ||
return data; | ||
}); | ||
}; | ||
function diff(oldList, newList, pk) { | ||
@@ -22,3 +22,3 @@ if (pk === void 0) { pk = '_id'; } | ||
return { | ||
type: OpsType.Error, | ||
type: 0, | ||
ops: [], | ||
@@ -35,3 +35,3 @@ message: "cannot compare non-list object", | ||
return { | ||
type: OpsType.Error, | ||
type: 0, | ||
ops: [], | ||
@@ -48,3 +48,3 @@ message: "cannot find pk: " + pk + " at prev." + i, | ||
return { | ||
type: OpsType.Error, | ||
type: 0, | ||
ops: [], | ||
@@ -114,3 +114,3 @@ message: "cannot find pk: " + pk + " at curr." + j, | ||
// if equal then reuse the previous data otherwise use the new data | ||
var op = isEqual ? { type: OpType.Reuse, index: prevIndex } : { type: OpType.New, index: k }; | ||
var op = isEqual ? { type: 0, index: prevIndex } : { type: 1, index: k }; | ||
if (prevIndex === k && isEqual) { | ||
@@ -122,3 +122,3 @@ reused++; | ||
else { | ||
ret.push({ type: OpType.New, index: k }); | ||
ret.push({ type: 1, index: k }); | ||
} | ||
@@ -128,3 +128,3 @@ } | ||
return { | ||
type: arrayIsSame ? OpsType.SuccessAndSkip : OpsType.Success, | ||
type: arrayIsSame ? 2 : 1, | ||
ops: ret, | ||
@@ -131,0 +131,0 @@ }; |
@@ -12,2 +12,3 @@ export * from './hash'; | ||
export * from './try-catch'; | ||
export * from './diff'; | ||
export { warn } from './warn'; |
@@ -15,4 +15,5 @@ "use strict"; | ||
tslib_1.__exportStar(require("./try-catch"), exports); | ||
tslib_1.__exportStar(require("./diff"), exports); | ||
var warn_1 = require("./warn"); | ||
exports.warn = warn_1.warn; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
declare const _default: "0.10.4-alpha.6-diff-alpha0.10.4-alpha.6-diff-diff-alpha0.10.4-alpha.6-diff-alpha0.10.4-alpha.6-diff-diff-diff"; | ||
declare const _default: "0.10.4-alpha.7-diff-alpha0.10.4-alpha.7-diff-lazyassert"; | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = '0.10.4-alpha.6-diff-alpha0.10.4-alpha.6-diff-diff-alpha0.10.4-alpha.6-diff-alpha0.10.4-alpha.6-diff-diff-diff'; | ||
exports.default = '0.10.4-alpha.7-diff-alpha0.10.4-alpha.7-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
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
293423
215
5248