deep-storage
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -123,4 +123,6 @@ "use strict"; | ||
var currentState = typeof _this.state === 'undefined' ? _this.initialStates[''] : _this.state; | ||
var pathSoFar = []; | ||
for (var _a = 0, path_1 = path; _a < path_1.length; _a++) { | ||
var p = path_1[_a]; | ||
pathSoFar.push(p); | ||
if (!(p in currentState)) { | ||
@@ -130,3 +132,3 @@ // todo: consider looking ahead to see if the next | ||
// instead of an object | ||
var init = _this.initialStates[path.join('.')]; | ||
var init = _this.initialStates[pathSoFar.join('.')]; | ||
currentState[p] = typeof init === 'undefined' ? {} : init; | ||
@@ -133,0 +135,0 @@ } |
{ | ||
"name": "deep-storage", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Simple observable state management for reactive applications", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -22,3 +22,3 @@ import deepStorage, { isPathMatch } from '../'; | ||
test('init', () => { | ||
test('deepInit', () => { | ||
const storage = deepStorage({ | ||
@@ -30,2 +30,12 @@ }); | ||
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', () => { | ||
@@ -32,0 +42,0 @@ const storage = deepStorage({ |
@@ -156,3 +156,5 @@ export type StateUpdateCallback = <DeepState>(path: Path, newState: DeepState, oldState: DeepState) => void; | ||
let currentState: any = typeof this.state === 'undefined' ? this.initialStates[''] : this.state; | ||
let pathSoFar = []; | ||
for (let p of path) { | ||
pathSoFar.push(p); | ||
if (!(p in currentState)) { | ||
@@ -162,3 +164,3 @@ // todo: consider looking ahead to see if the next | ||
// instead of an object | ||
const init = this.initialStates[path.join('.')]; | ||
const init = this.initialStates[pathSoFar.join('.')]; | ||
currentState[p] = typeof init === 'undefined' ? {} : init; | ||
@@ -165,0 +167,0 @@ } |
Sorry, the diff of this file is not supported yet
190261
1236