deep-storage
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -44,3 +44,4 @@ export declare type StateUpdateCallback = <DeepState>(path: Path, newState: DeepState, oldState: DeepState) => void; | ||
*/ | ||
init: <DeepState>(...path: Path) => (deepState: DeepState) => DeepStorage<DeepState>; | ||
deepInit: <DeepState>(...path: Path) => (deepState: DeepState) => DeepStorage<DeepState, RootState>; | ||
init: (state: State) => DeepStorage<State, RootState>; | ||
/** | ||
@@ -100,3 +101,4 @@ * Gets the root deep storage | ||
stateIn: <DeepState>(...path: (string | number)[]) => any; | ||
init: <DeepState>(...path: (string | number)[]) => (deepState: DeepState) => DeepStorage<DeepState, {}>; | ||
init: (state: State) => DeepStorage<State, State>; | ||
deepInit: <DeepState>(...path: (string | number)[]) => (deepState: DeepState) => DeepStorage<DeepState, State>; | ||
deep: <DeepState>(...path: (string | number)[]) => DeepStorage<DeepState, {}>; | ||
@@ -115,4 +117,4 @@ subscription: (callback: StateUpdateCallback) => { | ||
path: Path; | ||
rootStorage: DeepStorage<RootState>; | ||
constructor(path: Path, rootStorage: DeepStorage<RootState>); | ||
rootStorage: DeepStorage<RootState, RootState>; | ||
constructor(path: Path, rootStorage: DeepStorage<RootState, RootState>); | ||
setIn: (...path: (string | number)[]) => <DeepState>(newValue: DeepState) => Promise<DeepState>; | ||
@@ -124,6 +126,7 @@ update: (callback: (s: State) => State) => Promise<State>; | ||
stateIn: <DeepState>(...path: (string | number)[]) => DeepState; | ||
init: <DeepState>(...path: (string | number)[]) => (deepState: DeepState) => DeepStorage<DeepState, {}>; | ||
init: (state: State) => DeepStorage<State, RootState>; | ||
deepInit: <DeepState>(...path: (string | number)[]) => (deepState: DeepState) => DeepStorage<DeepState, RootState>; | ||
deep: <DeepState>(...path: (string | number)[]) => DeepStorage<DeepState, {}>; | ||
subscription: (callback: StateUpdateCallback) => DeepSubscription; | ||
root: () => DeepStorage<RootState, {}>; | ||
root: () => DeepStorage<RootState, RootState>; | ||
readonly props: { | ||
@@ -130,0 +133,0 @@ [P in keyof State]: DeepStorage<State[P], {}>; |
@@ -136,3 +136,6 @@ "use strict"; | ||
}; | ||
this.init = function () { | ||
this.init = function (state) { | ||
return _this.deepInit()(state); | ||
}; | ||
this.deepInit = function () { | ||
var path = []; | ||
@@ -235,3 +238,6 @@ for (var _i = 0; _i < arguments.length; _i++) { | ||
}; | ||
this.init = function () { | ||
this.init = function (state) { | ||
return _this.deepInit()(state); | ||
}; | ||
this.deepInit = function () { | ||
var path = []; | ||
@@ -242,3 +248,3 @@ for (var _i = 0; _i < arguments.length; _i++) { | ||
return function (deepState) { | ||
return (_a = _this.rootStorage).init.apply(_a, _this.path.concat(path))(deepState); | ||
return (_a = _this.rootStorage).deepInit.apply(_a, _this.path.concat(path))(deepState); | ||
var _a; | ||
@@ -245,0 +251,0 @@ }; |
{ | ||
"name": "deep-storage", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Simple observable state management for reactive applications", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -25,3 +25,3 @@ import deepStorage, { isPathMatch } from '../'; | ||
}); | ||
const testStorage = storage.init('test')(1); | ||
const testStorage = storage.deepInit('test')(1); | ||
expect(testStorage.state).toEqual(1); | ||
@@ -28,0 +28,0 @@ }); |
@@ -54,4 +54,6 @@ export type StateUpdateCallback = <DeepState>(path: Path, newState: DeepState, oldState: DeepState) => void; | ||
*/ | ||
init: <DeepState>(...path: Path) => (deepState: DeepState) => DeepStorage<DeepState>; | ||
deepInit: <DeepState>(...path: Path) => (deepState: DeepState) => DeepStorage<DeepState, RootState>; | ||
init: (state: State) => DeepStorage<State, RootState>; | ||
/** | ||
@@ -110,3 +112,3 @@ * Gets the root deep storage | ||
private id: number = 0; | ||
private initialStates: {[key: string]: any} = {}; | ||
private initialStates: { [key: string]: any } = {}; | ||
@@ -168,3 +170,6 @@ private subscriptions: { [key: number]: { paths: Path[], callback: StateUpdateCallback } } = {}; | ||
} | ||
init = <DeepState>(...path: Path) => (deepState: DeepState): DeepStorage<DeepState> => { | ||
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; | ||
@@ -207,3 +212,3 @@ return new NestedDeepStorage<DeepState, State>(path, this); | ||
constructor(public path: Path, public rootStorage: DeepStorage<RootState>) { | ||
constructor(public path: Path, public rootStorage: DeepStorage<RootState, RootState>) { | ||
} | ||
@@ -232,5 +237,8 @@ | ||
} | ||
init = <DeepState>(...path: stringOrNumber[]) => (deepState: DeepState): DeepStorage<DeepState> => { | ||
return this.rootStorage.init<DeepState>(...this.path.concat(path))(deepState); | ||
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> => { | ||
@@ -237,0 +245,0 @@ return this.rootStorage.deep(...this.path.concat(path)); |
Sorry, the diff of this file is not supported yet
189794
1223