react-global-state-hooks 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/GlobalStore.d.ts
CHANGED
|
@@ -44,10 +44,8 @@ export declare class GlobalStore<IState, IActions extends IGlobalStore.IActionCo
|
|
|
44
44
|
** [subscriber-update-callback, hook, newState]
|
|
45
45
|
*/
|
|
46
46
|
protected static batchedUpdates: [() => void, object, object][];
|
|
47
|
-
protected globalSetter: (setter: Partial<IState> | ((state: IState) => Partial<IState>)
|
|
48
|
-
protected globalSetterAsync: (setter: Partial<IState> | ((state: IState) => Partial<IState>)) => Promise<void>;
|
|
47
|
+
protected globalSetter: (setter: Partial<IState> | ((state: IState) => Partial<IState>)) => void;
|
|
49
48
|
protected globalSetterToPersistStoreAsync: (setter: Partial<IState> | ((state: IState) => Partial<IState>)) => Promise<void>;
|
|
50
|
-
static ExecutePendingBatchesCallbacks: (() => void)[];
|
|
51
49
|
static ExecutePendingBatches: () => void;
|
|
52
50
|
protected getActions: <IApi extends IGlobalStore.IActionCollectionResult<IState, IGlobalStore.IActionCollectionConfig<IState>>>() => IApi;
|
|
53
51
|
}
|
package/lib/GlobalStore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalStore.d.ts","sourceRoot":"","sources":["../src/GlobalStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AAWnD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IAChC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,QAAQ,uDAUpB,CAAC;AAEF;;;;;;;;IAQI;AACJ,qBAAa,WAAW,CACtB,MAAM,EACN,QAAQ,SAAS,YAAY,CAAC,uBAAuB,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,IA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Ac,YAExB;gBAEqB,KAAK,EAAE,MAAM,EAAY,OAAO,GAAE,QAA2B,EAAY,cAAc,GAAE,MAAM,GAAG,IAAW;IAEnI,OAAO,CAAC,eAAe,CAAiC;IAExD,SAAS,CAAC,mBAAmB,IAAI,MAAM,GAAG,IAAI;IAI9C,SAAS,CAAC,YAAY,IAAI,MAAM;IAehC,SAAS,CAAC,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAIzD,SAAS,CAAC,YAAY,IAAI,IAAI;IAU9B,SAAS,CAAC,oBAAoB,QAAO,MAAM,CAAwB;IAEnE,SAAS,CAAC,YAAY,QAAO,MAAM,CAAqC;IAExE;;;OAGG;IACI,OAAO,6OAsBZ;IAEF;;;;OAIG;IACI,gBAAgB,mLAIf,MAAM,oDASZ;IAEF,OAAO,CAAC,kBAAkB,CAA0G;IAEpI,SAAS,KAAK,iBAAiB,IAAI,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAY3H;IAED;;OAEG;IACH,SAAS,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAM;IAErE,SAAS,CAAC,YAAY,sCAAuC,MAAM,KAAK,QAAQ,MAAM,CAAC,WAwBrF;IAEF,SAAS,CAAC,+BAA+B,sCAA6C,MAAM,KAAK,QAAQ,MAAM,CAAC,MAAI,QAAQ,IAAI,CAAC,CAG/H;IAGF,MAAM,CAAC,qBAAqB,aAU3B;IAED,SAAS,CAAC,UAAU,sHAwBlB;CAEH;AAED,eAAe,WAAW,CAAC"}
|
package/lib/GlobalStore.js
CHANGED
|
@@ -67,7 +67,7 @@ class GlobalStore {
|
|
|
67
67
|
];
|
|
68
68
|
};
|
|
69
69
|
this._stateOrchestrator = null;
|
|
70
|
-
this.globalSetter = (setter
|
|
70
|
+
this.globalSetter = (setter) => {
|
|
71
71
|
const partialState = typeof setter === 'function' ? setter(this.getStateCopy()) : setter;
|
|
72
72
|
let newState = (0, json_storage_formatter_1.isPrimitive)(partialState) || Array.isArray(partialState)
|
|
73
73
|
? partialState : Object.assign(Object.assign({}, this.state), partialState);
|
|
@@ -85,18 +85,16 @@ class GlobalStore {
|
|
|
85
85
|
this.state = newState;
|
|
86
86
|
// batch store updates
|
|
87
87
|
GlobalStore.batchedUpdates.push([() => this.subscribers.forEach((updateChild) => updateChild(newState)), this, newState]);
|
|
88
|
-
GlobalStore.ExecutePendingBatchesCallbacks.push(callback);
|
|
89
88
|
GlobalStore.ExecutePendingBatches();
|
|
90
89
|
};
|
|
91
|
-
this.globalSetterAsync = (setter) => tslib_1.__awaiter(this, void 0, void 0, function* () { return new Promise((resolve) => this.globalSetter(setter, () => resolve())); });
|
|
92
90
|
this.globalSetterToPersistStoreAsync = (setter) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
|
|
91
|
+
this.globalSetter(setter);
|
|
94
92
|
this.setStoreItem();
|
|
95
93
|
});
|
|
96
94
|
this.getActions = () => {
|
|
97
95
|
const actions = this.actions;
|
|
98
96
|
// Setter is allways async because of the render batch
|
|
99
|
-
const setter = this.isPersistStore ? this.globalSetterToPersistStoreAsync : this.
|
|
97
|
+
const setter = this.isPersistStore ? this.globalSetterToPersistStoreAsync : this.globalSetter;
|
|
100
98
|
return Object.keys(actions).reduce((accumulator, key) => (Object.assign(Object.assign({}, accumulator), { [key]: (...parameres) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
101
99
|
let promise;
|
|
102
100
|
const setterWrapper = (value) => {
|
|
@@ -119,9 +117,8 @@ class GlobalStore {
|
|
|
119
117
|
const item = this.localStorageGetItem();
|
|
120
118
|
if (item) {
|
|
121
119
|
const value = JSON.parse(item);
|
|
122
|
-
const primitive = (0, json_storage_formatter_1.isPrimitive)(value);
|
|
123
120
|
const newState = (0, json_storage_formatter_1.formatFromStore)(value);
|
|
124
|
-
this.state =
|
|
121
|
+
this.state = newState;
|
|
125
122
|
}
|
|
126
123
|
return this.state;
|
|
127
124
|
}
|
|
@@ -145,7 +142,7 @@ class GlobalStore {
|
|
|
145
142
|
this._stateOrchestrator = this.globalSetterToPersistStoreAsync;
|
|
146
143
|
}
|
|
147
144
|
else {
|
|
148
|
-
this._stateOrchestrator = this.
|
|
145
|
+
this._stateOrchestrator = this.globalSetter;
|
|
149
146
|
}
|
|
150
147
|
return this._stateOrchestrator;
|
|
151
148
|
}
|
|
@@ -155,17 +152,14 @@ exports.GlobalStore = GlobalStore;
|
|
|
155
152
|
** [subscriber-update-callback, hook, newState]
|
|
156
153
|
*/
|
|
157
154
|
GlobalStore.batchedUpdates = [];
|
|
158
|
-
GlobalStore.ExecutePendingBatchesCallbacks = [];
|
|
159
155
|
// avoid multiples calls to batchedUpdates
|
|
160
|
-
GlobalStore.ExecutePendingBatches = (
|
|
156
|
+
GlobalStore.ExecutePendingBatches = () => {
|
|
161
157
|
const reactBatchedUpdates = react_dom_1.default.unstable_batchedUpdates || ((mock) => mock());
|
|
162
158
|
reactBatchedUpdates(() => {
|
|
163
159
|
GlobalStore.batchedUpdates.forEach(([execute]) => {
|
|
164
160
|
execute();
|
|
165
161
|
});
|
|
166
162
|
GlobalStore.batchedUpdates = [];
|
|
167
|
-
GlobalStore.ExecutePendingBatchesCallbacks.forEach((callback) => callback());
|
|
168
|
-
GlobalStore.ExecutePendingBatchesCallbacks = [];
|
|
169
163
|
});
|
|
170
|
-
}
|
|
164
|
+
};
|
|
171
165
|
exports.default = GlobalStore;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @param {StateSetter<IState>} setter - add a new value to the state
|
|
3
3
|
* @returns {Promise<void>} result - resolves when update_batches finished
|
|
4
4
|
*/
|
|
5
|
-
export type StateSetter<IState> = (setter: Partial<IState> | ((state: IState) => Partial<IState>)) =>
|
|
5
|
+
export type StateSetter<IState> = (setter: Partial<IState> | ((state: IState) => Partial<IState>)) => void;
|
|
6
6
|
/**
|
|
7
7
|
* This is the structure required by the API actions in order to be able to capture action parameters and inject state setter into actions.
|
|
8
8
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalStoreTypes.d.ts","sourceRoot":"","sources":["../src/GlobalStoreTypes.ts"],"names":[],"mappings":"AAAA;;;EAGE;AACF,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI,CAChC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,KAC3D,
|
|
1
|
+
{"version":3,"file":"GlobalStoreTypes.d.ts","sourceRoot":"","sources":["../src/GlobalStoreTypes.ts"],"names":[],"mappings":"AAAA;;;EAGE;AACF,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI,CAChC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,KAC3D,IAAI,CAAC;AAEV;;EAEE;AAEF,MAAM,MAAM,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAE/I;;EAEE;AACF,MAAM,WAAW,uBAAuB,CAAC,MAAM;IAC7C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAChC;AAED;;EAEE;AACF,MAAM,MAAM,uBAAuB,CAAC,MAAM,EAAE,QAAQ,SAAS,uBAAuB,CAAC,MAAM,CAAC,GAAG,IAAI,IAAI;KAEpG,GAAG,IAAI,MAAM,QAAQ,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,KAAK,OAAO;CACvD,CAAC;AAEF;;EAEE;AACF,MAA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1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "This is a package to easily handling global-state across your react components No-redux, No-context.",
|
|
5
5
|
"main": "lib/GlobalStore.js",
|
|
6
6
|
"files": [
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
"react-dom": "workspace:*"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"json-storage-formatter": "^1.0.
|
|
63
|
+
"json-storage-formatter": "^1.0.2"
|
|
64
64
|
}
|
|
65
65
|
}
|