deep-storage
Advanced tools
Comparing version 2.0.4 to 3.0.0
@@ -47,8 +47,2 @@ export * from './async'; | ||
/** | ||
* Creates a new DeepStorage at this point in the object path and | ||
* gives it an initial value if one hasn't already been set | ||
*/ | ||
deepInit: <DeepState>(...path: Path) => (deepState: DeepState) => DeepStorage<DeepState, RootState>; | ||
init: (state: State) => DeepStorage<State, RootState>; | ||
/** | ||
* Gets the root deep storage | ||
@@ -93,3 +87,2 @@ */ | ||
private id; | ||
private initialStates; | ||
private subscriptions; | ||
@@ -105,6 +98,3 @@ constructor(state: State); | ||
updateIn: (...path: (string | number)[]) => <DeepState>(callback: (s: DeepState) => DeepState) => Promise<DeepState>; | ||
cloneInitialState: (...path: (string | number)[]) => any; | ||
stateIn: <DeepState>(...path: (string | number)[]) => any; | ||
init: (state: State) => DeepStorage<State, State>; | ||
deepInit: <DeepState>(...path: (string | number)[]) => (deepState: DeepState) => DeepStorage<DeepState, State>; | ||
deep: <DeepState>(...path: (string | number)[]) => DeepStorage<DeepState, {}>; | ||
@@ -132,4 +122,2 @@ subscription: (callback: StateUpdateCallback) => { | ||
stateIn: <DeepState>(...path: (string | number)[]) => DeepState; | ||
init: (state: State) => DeepStorage<State, RootState>; | ||
deepInit: <DeepState>(...path: (string | number)[]) => (deepState: DeepState) => DeepStorage<DeepState, RootState>; | ||
deep: <DeepState>(...path: (string | number)[]) => DeepStorage<DeepState, {}>; | ||
@@ -136,0 +124,0 @@ subscription: (callback: StateUpdateCallback) => DeepSubscription; |
@@ -66,3 +66,2 @@ "use strict"; | ||
this.id = 0; | ||
this.initialStates = {}; | ||
this.subscriptions = {}; | ||
@@ -125,15 +124,2 @@ this.update = function (callback) { | ||
}; | ||
this.cloneInitialState = function () { | ||
var path = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
path[_i] = arguments[_i]; | ||
} | ||
var initialState = _this.initialStates[path.join('.')]; | ||
if (typeof initialState === 'undefined') { | ||
return undefined; | ||
} | ||
else { | ||
return JSON.parse(JSON.stringify(initialState)); | ||
} | ||
}; | ||
this.stateIn = function () { | ||
@@ -144,3 +130,3 @@ var path = []; | ||
} | ||
var currentState = typeof _this.state === 'undefined' ? _this.cloneInitialState() : _this.state; | ||
var currentState = _this.state; | ||
var pathSoFar = []; | ||
@@ -151,7 +137,3 @@ for (var _a = 0, path_1 = path; _a < path_1.length; _a++) { | ||
if (!(p in currentState)) { | ||
// todo: consider looking ahead to see if the next | ||
// p is a number and if so, initialize and array | ||
// instead of an object | ||
var init = _this.cloneInitialState.apply(_this, pathSoFar); | ||
currentState[p] = typeof init === 'undefined' ? {} : init; | ||
currentState[p] = {}; | ||
} | ||
@@ -162,15 +144,2 @@ currentState = currentState[p]; | ||
}; | ||
this.init = function (state) { | ||
return _this.deepInit()(state); | ||
}; | ||
this.deepInit = function () { | ||
var path = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
path[_i] = arguments[_i]; | ||
} | ||
return function (deepState) { | ||
_this.initialStates[path.join('.')] = deepState; | ||
return new NestedDeepStorage(path, _this); | ||
}; | ||
}; | ||
this.deep = function () { | ||
@@ -268,15 +237,2 @@ var path = []; | ||
}; | ||
this.init = function (state) { | ||
return _this.deepInit()(state); | ||
}; | ||
this.deepInit = function () { | ||
var path = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
path[_i] = arguments[_i]; | ||
} | ||
return function (deepState) { | ||
return (_a = _this.rootStorage).deepInit.apply(_a, _this.path.concat(path))(deepState); | ||
var _a; | ||
}; | ||
}; | ||
this.deep = function () { | ||
@@ -283,0 +239,0 @@ var path = []; |
{ | ||
"name": "deep-storage", | ||
"version": "2.0.4", | ||
"version": "3.0.0", | ||
"description": "Simple observable state management for reactive applications", | ||
@@ -22,3 +22,5 @@ "main": "./lib/index.js", | ||
"build": "rimraf lib *.d.ts && tsc -p tsconfig.prod.json", | ||
"publish-patch": "yarn build && git commit -am 'build' && git push && npm version patch && git push" | ||
"publish-patch": "yarn build && git commit -am 'build' && git push && npm version patch && git push", | ||
"publish-minor": "yarn build && git commit -am 'build' && git push && npm version minor && git push", | ||
"publish-major": "yarn build && git commit -am 'build' && git push && npm version major && git push" | ||
}, | ||
@@ -25,0 +27,0 @@ "dependencies": {}, |
@@ -22,19 +22,2 @@ import deepStorage, { isPathMatch } from '../'; | ||
test('deepInit', () => { | ||
const storage = deepStorage({ | ||
}); | ||
const testStorage = storage.deepInit('test')(1); | ||
expect(testStorage.state).toEqual(1); | ||
}); | ||
test('init', () => { | ||
const storage = deepStorage({ | ||
}); | ||
let loginStorage = storage.deep('app', 'login'); | ||
loginStorage = loginStorage.init({ | ||
lastLoginFailed: false | ||
}); | ||
expect(loginStorage.deep('lastLoginFailed').state).toEqual(false); | ||
}); | ||
test('deep', () => { | ||
@@ -41,0 +24,0 @@ const storage = deepStorage({ |
@@ -59,10 +59,2 @@ export * from './async'; | ||
/** | ||
* Creates a new DeepStorage at this point in the object path and | ||
* gives it an initial value if one hasn't already been set | ||
*/ | ||
deepInit: <DeepState>(...path: Path) => (deepState: DeepState) => DeepStorage<DeepState, RootState>; | ||
init: (state: State) => DeepStorage<State, RootState>; | ||
/** | ||
* Gets the root deep storage | ||
@@ -116,3 +108,2 @@ */ | ||
private id: number = 0; | ||
private initialStates: { [key: string]: any } = {}; | ||
@@ -163,12 +154,4 @@ private subscriptions: { [key: number]: { paths: Path[], callback: StateUpdateCallback } } = {}; | ||
} | ||
cloneInitialState = (...path: Path) => { | ||
const initialState = this.initialStates[path.join('.')]; | ||
if(typeof initialState === 'undefined') { | ||
return undefined; | ||
} else { | ||
return JSON.parse(JSON.stringify(initialState)); | ||
} | ||
} | ||
stateIn = <DeepState>(...path: Path) => { | ||
let currentState: any = typeof this.state === 'undefined' ? this.cloneInitialState() : this.state; | ||
let currentState: any = this.state; | ||
let pathSoFar = []; | ||
@@ -178,7 +161,3 @@ for (let p of path) { | ||
if (!(p in currentState)) { | ||
// todo: consider looking ahead to see if the next | ||
// p is a number and if so, initialize and array | ||
// instead of an object | ||
const init = this.cloneInitialState(...pathSoFar); | ||
currentState[p] = typeof init === 'undefined' ? {} : init; | ||
currentState[p] = {}; | ||
} | ||
@@ -189,9 +168,2 @@ currentState = currentState[p]; | ||
} | ||
init = (state: State): DeepStorage<State, State> => { | ||
return this.deepInit<State>()(state); | ||
} | ||
deepInit = <DeepState>(...path: Path) => (deepState: DeepState): DeepStorage<DeepState, State> => { | ||
this.initialStates[path.join('.')] = deepState; | ||
return new NestedDeepStorage<DeepState, State>(path, this); | ||
} | ||
deep = <DeepState>(...path: Path): DeepStorage<DeepState> => { | ||
@@ -259,8 +231,2 @@ return new NestedDeepStorage<DeepState, State>(path, this); | ||
} | ||
init = (state: State): DeepStorage<State, RootState> => { | ||
return this.deepInit<State>()(state); | ||
} | ||
deepInit = <DeepState>(...path: stringOrNumber[]) => (deepState: DeepState): DeepStorage<DeepState, RootState> => { | ||
return this.rootStorage.deepInit<DeepState>(...this.path.concat(path))(deepState); | ||
} | ||
deep = <DeepState>(...path: stringOrNumber[]): DeepStorage<DeepState> => { | ||
@@ -267,0 +233,0 @@ return this.rootStorage.deep(...this.path.concat(path)); |
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
364087
20
1193