@goldfishjs/reactive-connect
Advanced tools
Comparing version 1.1.5 to 1.1.6
@@ -99,3 +99,3 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
var optionsOldV = options.oldV || []; | ||
updater.setSpliceObjectValue(keyPathString, options.method, options.args || [], optionsOldV); | ||
updater.setSpliceObjectValue(keyPathString, newV, optionsOldV); | ||
} else { | ||
@@ -102,0 +102,0 @@ updater.setSetObjectValue(keyPathString, newV); |
@@ -16,20 +16,9 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty"; | ||
key: "addNode", | ||
value: function addNode(keyPathString, method, args, oldV) { | ||
if (method === 'push') { | ||
this.spliceObjectList.push(_defineProperty({}, keyPathString, [oldV.length, 0].concat(_toConsumableArray(args.map(function (item) { | ||
value: function addNode(keyPathString, newV, oldV) { | ||
if (newV.length > oldV.length) { | ||
this.spliceObjectList.push(_defineProperty({}, keyPathString, [oldV.length, 0].concat(_toConsumableArray(newV.slice(oldV.length, newV.length).map(function (item) { | ||
return cloneDeep(item); | ||
}))))); | ||
} else if (method === 'splice') { | ||
var realArgs = args; | ||
this.spliceObjectList.push(_defineProperty({}, keyPathString, [realArgs[0], realArgs[1]].concat(_toConsumableArray((realArgs[2] || []).map(function (item) { | ||
return cloneDeep(item); | ||
}))))); | ||
} else if (method === 'unshift') { | ||
this.spliceObjectList.push(_defineProperty({}, keyPathString, [0, 0].concat(_toConsumableArray((args || []).map(function (item) { | ||
return cloneDeep(item); | ||
}))))); | ||
} else if (method === 'pop') { | ||
this.spliceObjectList.push(_defineProperty({}, keyPathString, [oldV.length - 1, 1])); | ||
} else if (method === 'shift') { | ||
this.spliceObjectList.push(_defineProperty({}, keyPathString, [0, 1])); | ||
} else if (newV.length < oldV.length) { | ||
this.spliceObjectList.push(_defineProperty({}, keyPathString, [newV.length, oldV.length - newV.length])); | ||
} | ||
@@ -36,0 +25,0 @@ } |
@@ -30,3 +30,3 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; | ||
key: "setSpliceObjectValue", | ||
value: function setSpliceObjectValue(keyPathString, method, args, oldV) { | ||
value: function setSpliceObjectValue(keyPathString, newV, oldV) { | ||
var last = this.list[this.list.length - 1]; | ||
@@ -39,3 +39,3 @@ | ||
last.addNode(keyPathString, method, args, oldV); | ||
last.addNode(keyPathString, newV, oldV); | ||
} | ||
@@ -42,0 +42,0 @@ }, { |
{ | ||
"name": "@goldfishjs/reactive-connect", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "goldfish-reactive-connect", | ||
@@ -18,4 +18,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@goldfishjs/reactive": "^1.1.5", | ||
"@goldfishjs/utils": "^1.1.5", | ||
"@goldfishjs/reactive": "^1.1.6", | ||
"@goldfishjs/utils": "^1.1.6", | ||
"mini-types": "^0.1.0" | ||
@@ -22,0 +22,0 @@ }, |
@@ -8,6 +8,6 @@ import Batch from './Batch'; | ||
import * as keyPath from './keyPath'; | ||
import { Methods as ModifyArrayMethods } from './SpliceTree'; | ||
import { isObject } from '@goldfishjs/utils'; | ||
function isModifyArrayMethod(m: string): m is ModifyArrayMethods { | ||
type Methods = 'push' | 'splice' | 'unshift' | 'pop' | 'shift'; | ||
function isModifyArrayMethod(m: string): m is Methods { | ||
return ['push', 'splice', 'unshift', 'pop', 'shift'].indexOf(m) !== -1; | ||
@@ -107,4 +107,3 @@ } | ||
keyPathString, | ||
options.method, | ||
options.args || [], | ||
newV, | ||
optionsOldV, | ||
@@ -111,0 +110,0 @@ ); |
import { cloneDeep } from '@goldfishjs/utils'; | ||
export type Methods = 'push' | 'splice' | 'unshift' | 'pop' | 'shift'; | ||
export default class SpliceTree { | ||
private spliceObjectList: (Record<string, Parameters<Array<any>['splice']>>)[] = []; | ||
public addNode<M extends Methods>( | ||
public addNode( | ||
keyPathString: string, | ||
method: M, | ||
args: Parameters<Array<any>[M]>, | ||
newV: any[], | ||
oldV: any[], | ||
) { | ||
if (method === 'push') { | ||
if (newV.length > oldV.length) { | ||
this.spliceObjectList.push({ | ||
@@ -19,30 +16,12 @@ [keyPathString]: [ | ||
0, | ||
...(args as any[]).map(item => cloneDeep(item)), | ||
...newV.slice(oldV.length, newV.length).map(item => cloneDeep(item)), | ||
], | ||
}); | ||
} else if (method === 'splice') { | ||
const realArgs = args as Parameters<Array<any>['splice']>; | ||
} else if (newV.length < oldV.length) { | ||
this.spliceObjectList.push({ | ||
[keyPathString]: [ | ||
realArgs[0], | ||
realArgs[1], | ||
...(realArgs[2] || []).map((item: any) => cloneDeep(item)), | ||
newV.length, | ||
oldV.length - newV.length, | ||
], | ||
}); | ||
} else if (method === 'unshift') { | ||
this.spliceObjectList.push({ | ||
[keyPathString]: [ | ||
0, | ||
0, | ||
...((args || []) as any[]).map((item: any) => cloneDeep(item)), | ||
], | ||
}); | ||
} else if (method === 'pop') { | ||
this.spliceObjectList.push({ | ||
[keyPathString]: [oldV.length - 1, 1], | ||
}); | ||
} else if (method === 'shift') { | ||
this.spliceObjectList.push({ | ||
[keyPathString]: [0, 1], | ||
}); | ||
} | ||
@@ -49,0 +28,0 @@ } |
import SetTree from './SetTree'; | ||
import SpliceTree from './SpliceTree'; | ||
import LimitLeafCounter from './LimitLeafCounter'; | ||
import { Methods } from './SpliceTree'; | ||
@@ -30,6 +29,5 @@ type IterateSetCallback = (obj: Record<string, any>) => void; | ||
public setSpliceObjectValue<M extends Methods>( | ||
public setSpliceObjectValue( | ||
keyPathString: string, | ||
method: M, | ||
args: Parameters<Array<any>[M]>, | ||
newV: any[], | ||
oldV: any[], | ||
@@ -43,3 +41,3 @@ ) { | ||
last.addNode(keyPathString, method, args, oldV); | ||
last.addNode(keyPathString, newV, oldV); | ||
} | ||
@@ -46,0 +44,0 @@ |
@@ -1,7 +0,6 @@ | ||
export declare type Methods = 'push' | 'splice' | 'unshift' | 'pop' | 'shift'; | ||
export default class SpliceTree { | ||
private spliceObjectList; | ||
addNode<M extends Methods>(keyPathString: string, method: M, args: Parameters<Array<any>[M]>, oldV: any[]): void; | ||
addNode(keyPathString: string, newV: any[], oldV: any[]): void; | ||
generate(): Record<string, [number, number, ...any[]]>[]; | ||
clear(): void; | ||
} |
@@ -1,2 +0,1 @@ | ||
import { Methods } from './SpliceTree'; | ||
declare type IterateSetCallback = (obj: Record<string, any>) => void; | ||
@@ -10,5 +9,5 @@ declare type IterateSpliceCallback = (obj: Array<Record<string, [number, number, ...any[]]>>) => void; | ||
setSetObjectValue(keyPathString: string, value: any): void; | ||
setSpliceObjectValue<M extends Methods>(keyPathString: string, method: M, args: Parameters<Array<any>[M]>, oldV: any[]): void; | ||
setSpliceObjectValue(keyPathString: string, newV: any[], oldV: any[]): void; | ||
iterate(setCb: IterateSetCallback, spliceCb: IterateSpliceCallback): void; | ||
} | ||
export {}; |
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
77805
2161
Updated@goldfishjs/reactive@^1.1.6
Updated@goldfishjs/utils@^1.1.6