deep-storage
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -99,2 +99,3 @@ export declare type StateUpdateCallback = <DeepState>(path: Path, newState: DeepState, oldState: DeepState) => void; | ||
updateIn: (...path: (string | number)[]) => <DeepState>(callback: (s: DeepState) => DeepState) => Promise<DeepState>; | ||
cloneInitialState: (...path: (string | number)[]) => any; | ||
stateIn: <DeepState>(...path: (string | number)[]) => any; | ||
@@ -101,0 +102,0 @@ init: (state: State) => DeepStorage<State, State>; |
@@ -117,2 +117,15 @@ "use strict"; | ||
}; | ||
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 () { | ||
@@ -123,3 +136,3 @@ var path = []; | ||
} | ||
var currentState = typeof _this.state === 'undefined' ? _this.initialStates[''] : _this.state; | ||
var currentState = typeof _this.state === 'undefined' ? _this.cloneInitialState() : _this.state; | ||
var pathSoFar = []; | ||
@@ -133,3 +146,3 @@ for (var _a = 0, path_1 = path; _a < path_1.length; _a++) { | ||
// instead of an object | ||
var init = _this.initialStates[pathSoFar.join('.')]; | ||
var init = _this.cloneInitialState.apply(_this, pathSoFar); | ||
currentState[p] = typeof init === 'undefined' ? {} : init; | ||
@@ -136,0 +149,0 @@ } |
{ | ||
"name": "deep-storage", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Simple observable state management for reactive applications", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -154,4 +154,12 @@ export type StateUpdateCallback = <DeepState>(path: Path, newState: DeepState, oldState: DeepState) => void; | ||
} | ||
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.initialStates[''] : this.state; | ||
let currentState: any = typeof this.state === 'undefined' ? this.cloneInitialState() : this.state; | ||
let pathSoFar = []; | ||
@@ -164,3 +172,3 @@ for (let p of path) { | ||
// instead of an object | ||
const init = this.initialStates[pathSoFar.join('.')]; | ||
const init = this.cloneInitialState(...pathSoFar); | ||
currentState[p] = typeof init === 'undefined' ? {} : init; | ||
@@ -167,0 +175,0 @@ } |
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
191435
1258