@ngxs/storage-plugin 3.7.3-dev.master-8834f50 → 3.7.3
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/README.md +3 -3
- package/bundles/ngxs-storage-plugin.umd.js +363 -381
- package/bundles/ngxs-storage-plugin.umd.js.map +1 -1
- package/bundles/ngxs-storage-plugin.umd.min.js +1 -1
- package/bundles/ngxs-storage-plugin.umd.min.js.map +1 -1
- package/esm2015/index.js +9 -9
- package/esm2015/ngxs-storage-plugin.js +10 -10
- package/esm2015/src/internals.js +76 -76
- package/esm2015/src/public_api.js +8 -8
- package/esm2015/src/storage.module.js +47 -47
- package/esm2015/src/storage.plugin.js +134 -152
- package/esm2015/src/symbols.js +93 -93
- package/esm5/index.js +9 -9
- package/esm5/ngxs-storage-plugin.js +10 -10
- package/esm5/src/internals.js +77 -77
- package/esm5/src/public_api.js +8 -8
- package/esm5/src/storage.module.js +55 -55
- package/esm5/src/storage.plugin.js +165 -183
- package/esm5/src/symbols.js +93 -93
- package/fesm2015/ngxs-storage-plugin.js +336 -354
- package/fesm2015/ngxs-storage-plugin.js.map +1 -1
- package/fesm5/ngxs-storage-plugin.js +372 -390
- package/fesm5/ngxs-storage-plugin.js.map +1 -1
- package/index.d.ts +4 -4
- package/ngxs-storage-plugin.d.ts +6 -6
- package/ngxs-storage-plugin.metadata.json +1 -1
- package/package.json +3 -3
- package/src/internals.d.ts +15 -15
- package/src/public_api.d.ts +3 -3
- package/src/storage.module.d.ts +6 -6
- package/src/storage.plugin.d.ts +9 -9
- package/src/symbols.d.ts +64 -64
|
@@ -3,372 +3,354 @@ import { StateToken, actionMatcher, InitState, UpdateState, getValue, setValue,
|
|
|
3
3
|
import { isPlatformServer } from '@angular/common';
|
|
4
4
|
import { tap } from 'rxjs/operators';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* @fileoverview added by tsickle
|
|
8
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
9
|
-
*/
|
|
10
|
-
/** @enum {number} */
|
|
11
|
-
const StorageOption = {
|
|
12
|
-
LocalStorage: 0,
|
|
13
|
-
SessionStorage: 1,
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* @record
|
|
17
|
-
*/
|
|
18
|
-
function NgxsStoragePluginOptions() { }
|
|
19
|
-
if (false) {
|
|
20
|
-
/**
|
|
21
|
-
* Key for the state slice to store in the storage engine.
|
|
22
|
-
* @type {?|undefined}
|
|
23
|
-
*/
|
|
24
|
-
NgxsStoragePluginOptions.prototype.key;
|
|
25
|
-
/**
|
|
26
|
-
* Storage engine to use. Deaults to localStorage but can provide
|
|
27
|
-
*
|
|
28
|
-
* sessionStorage or custom implementation of the StorageEngine interface
|
|
29
|
-
* @type {?|undefined}
|
|
30
|
-
*/
|
|
31
|
-
NgxsStoragePluginOptions.prototype.storage;
|
|
32
|
-
/**
|
|
33
|
-
* Migration strategies.
|
|
34
|
-
* @type {?|undefined}
|
|
35
|
-
*/
|
|
36
|
-
NgxsStoragePluginOptions.prototype.migrations;
|
|
37
|
-
/**
|
|
38
|
-
* Serailizer for the object before its pushed into the engine.
|
|
39
|
-
* @param {?} obj
|
|
40
|
-
* @return {?}
|
|
41
|
-
*/
|
|
42
|
-
NgxsStoragePluginOptions.prototype.serialize = function (obj) { };
|
|
43
|
-
/**
|
|
44
|
-
* Deserializer for the object before its pulled out of the engine.
|
|
45
|
-
* @param {?} obj
|
|
46
|
-
* @return {?}
|
|
47
|
-
*/
|
|
48
|
-
NgxsStoragePluginOptions.prototype.deserialize = function (obj) { };
|
|
49
|
-
/**
|
|
50
|
-
* Method to alter object before serialization.
|
|
51
|
-
* @param {?} obj
|
|
52
|
-
* @param {?} key
|
|
53
|
-
* @return {?}
|
|
54
|
-
*/
|
|
55
|
-
NgxsStoragePluginOptions.prototype.beforeSerialize = function (obj, key) { };
|
|
56
|
-
/**
|
|
57
|
-
* Method to alter object after deserialization.
|
|
58
|
-
* @param {?} obj
|
|
59
|
-
* @param {?} key
|
|
60
|
-
* @return {?}
|
|
61
|
-
*/
|
|
62
|
-
NgxsStoragePluginOptions.prototype.afterDeserialize = function (obj, key) { };
|
|
63
|
-
}
|
|
64
|
-
/** @type {?} */
|
|
65
|
-
const NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken('NGXS_STORAGE_PLUGIN_OPTION');
|
|
66
|
-
/** @type {?} */
|
|
67
|
-
const STORAGE_ENGINE = new InjectionToken('STORAGE_ENGINE');
|
|
68
|
-
/**
|
|
69
|
-
* @record
|
|
70
|
-
*/
|
|
71
|
-
function StorageEngine() { }
|
|
72
|
-
if (false) {
|
|
73
|
-
/** @type {?} */
|
|
74
|
-
StorageEngine.prototype.length;
|
|
75
|
-
/**
|
|
76
|
-
* @param {?} key
|
|
77
|
-
* @return {?}
|
|
78
|
-
*/
|
|
79
|
-
StorageEngine.prototype.getItem = function (key) { };
|
|
80
|
-
/**
|
|
81
|
-
* @param {?} key
|
|
82
|
-
* @param {?} val
|
|
83
|
-
* @return {?}
|
|
84
|
-
*/
|
|
85
|
-
StorageEngine.prototype.setItem = function (key, val) { };
|
|
86
|
-
/**
|
|
87
|
-
* @param {?} key
|
|
88
|
-
* @return {?}
|
|
89
|
-
*/
|
|
90
|
-
StorageEngine.prototype.removeItem = function (key) { };
|
|
91
|
-
/**
|
|
92
|
-
* @return {?}
|
|
93
|
-
*/
|
|
94
|
-
StorageEngine.prototype.clear = function () { };
|
|
6
|
+
/**
|
|
7
|
+
* @fileoverview added by tsickle
|
|
8
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
9
|
+
*/
|
|
10
|
+
/** @enum {number} */
|
|
11
|
+
const StorageOption = {
|
|
12
|
+
LocalStorage: 0,
|
|
13
|
+
SessionStorage: 1,
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* @record
|
|
17
|
+
*/
|
|
18
|
+
function NgxsStoragePluginOptions() { }
|
|
19
|
+
if (false) {
|
|
20
|
+
/**
|
|
21
|
+
* Key for the state slice to store in the storage engine.
|
|
22
|
+
* @type {?|undefined}
|
|
23
|
+
*/
|
|
24
|
+
NgxsStoragePluginOptions.prototype.key;
|
|
25
|
+
/**
|
|
26
|
+
* Storage engine to use. Deaults to localStorage but can provide
|
|
27
|
+
*
|
|
28
|
+
* sessionStorage or custom implementation of the StorageEngine interface
|
|
29
|
+
* @type {?|undefined}
|
|
30
|
+
*/
|
|
31
|
+
NgxsStoragePluginOptions.prototype.storage;
|
|
32
|
+
/**
|
|
33
|
+
* Migration strategies.
|
|
34
|
+
* @type {?|undefined}
|
|
35
|
+
*/
|
|
36
|
+
NgxsStoragePluginOptions.prototype.migrations;
|
|
37
|
+
/**
|
|
38
|
+
* Serailizer for the object before its pushed into the engine.
|
|
39
|
+
* @param {?} obj
|
|
40
|
+
* @return {?}
|
|
41
|
+
*/
|
|
42
|
+
NgxsStoragePluginOptions.prototype.serialize = function (obj) { };
|
|
43
|
+
/**
|
|
44
|
+
* Deserializer for the object before its pulled out of the engine.
|
|
45
|
+
* @param {?} obj
|
|
46
|
+
* @return {?}
|
|
47
|
+
*/
|
|
48
|
+
NgxsStoragePluginOptions.prototype.deserialize = function (obj) { };
|
|
49
|
+
/**
|
|
50
|
+
* Method to alter object before serialization.
|
|
51
|
+
* @param {?} obj
|
|
52
|
+
* @param {?} key
|
|
53
|
+
* @return {?}
|
|
54
|
+
*/
|
|
55
|
+
NgxsStoragePluginOptions.prototype.beforeSerialize = function (obj, key) { };
|
|
56
|
+
/**
|
|
57
|
+
* Method to alter object after deserialization.
|
|
58
|
+
* @param {?} obj
|
|
59
|
+
* @param {?} key
|
|
60
|
+
* @return {?}
|
|
61
|
+
*/
|
|
62
|
+
NgxsStoragePluginOptions.prototype.afterDeserialize = function (obj, key) { };
|
|
63
|
+
}
|
|
64
|
+
/** @type {?} */
|
|
65
|
+
const NGXS_STORAGE_PLUGIN_OPTIONS = new InjectionToken('NGXS_STORAGE_PLUGIN_OPTION');
|
|
66
|
+
/** @type {?} */
|
|
67
|
+
const STORAGE_ENGINE = new InjectionToken('STORAGE_ENGINE');
|
|
68
|
+
/**
|
|
69
|
+
* @record
|
|
70
|
+
*/
|
|
71
|
+
function StorageEngine() { }
|
|
72
|
+
if (false) {
|
|
73
|
+
/** @type {?} */
|
|
74
|
+
StorageEngine.prototype.length;
|
|
75
|
+
/**
|
|
76
|
+
* @param {?} key
|
|
77
|
+
* @return {?}
|
|
78
|
+
*/
|
|
79
|
+
StorageEngine.prototype.getItem = function (key) { };
|
|
80
|
+
/**
|
|
81
|
+
* @param {?} key
|
|
82
|
+
* @param {?} val
|
|
83
|
+
* @return {?}
|
|
84
|
+
*/
|
|
85
|
+
StorageEngine.prototype.setItem = function (key, val) { };
|
|
86
|
+
/**
|
|
87
|
+
* @param {?} key
|
|
88
|
+
* @return {?}
|
|
89
|
+
*/
|
|
90
|
+
StorageEngine.prototype.removeItem = function (key) { };
|
|
91
|
+
/**
|
|
92
|
+
* @return {?}
|
|
93
|
+
*/
|
|
94
|
+
StorageEngine.prototype.clear = function () { };
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
/**
|
|
98
|
-
* @fileoverview added by tsickle
|
|
99
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
100
|
-
*/
|
|
101
|
-
/**
|
|
102
|
-
* If the `key` option is not provided then the below constant
|
|
103
|
-
* will be used as a default key
|
|
104
|
-
* @type {?}
|
|
105
|
-
*/
|
|
106
|
-
const DEFAULT_STATE_KEY = '@@STATE';
|
|
107
|
-
/**
|
|
108
|
-
* This key is used to retrieve static metadatas on state classes.
|
|
109
|
-
* This constant is taken from the core codebase
|
|
110
|
-
* @type {?}
|
|
111
|
-
*/
|
|
112
|
-
const META_OPTIONS_KEY = 'NGXS_OPTIONS_META';
|
|
113
|
-
/**
|
|
114
|
-
* @param {?} key
|
|
115
|
-
* @return {?}
|
|
116
|
-
*/
|
|
117
|
-
function transformKeyOption(key) {
|
|
118
|
-
if (!Array.isArray(key)) {
|
|
119
|
-
key = [key];
|
|
120
|
-
}
|
|
121
|
-
return key.map((/**
|
|
122
|
-
* @param {?} token
|
|
123
|
-
* @return {?}
|
|
124
|
-
*/
|
|
125
|
-
(token) => {
|
|
126
|
-
// If it has the `NGXS_OPTIONS_META` key then it means the developer
|
|
127
|
-
// has provided state class like `key: [AuthState]`.
|
|
128
|
-
if (token.hasOwnProperty(META_OPTIONS_KEY)) {
|
|
129
|
-
// The `name` property will be an actual state name or a `StateToken`.
|
|
130
|
-
token = ((/** @type {?} */ (token)))[META_OPTIONS_KEY].name;
|
|
131
|
-
}
|
|
132
|
-
return token instanceof StateToken ? token.getName() : ((/** @type {?} */ (token)));
|
|
133
|
-
}));
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* @param {?} options
|
|
137
|
-
* @return {?}
|
|
138
|
-
*/
|
|
139
|
-
function storageOptionsFactory(options) {
|
|
140
|
-
if (options !== undefined && options.key) {
|
|
141
|
-
options.key = transformKeyOption(options.key);
|
|
142
|
-
}
|
|
143
|
-
return Object.assign({ key: [DEFAULT_STATE_KEY], storage: 0 /* LocalStorage */, serialize: JSON.stringify, deserialize: JSON.parse, beforeSerialize: (/**
|
|
144
|
-
* @param {?} obj
|
|
145
|
-
* @return {?}
|
|
146
|
-
*/
|
|
147
|
-
obj => obj), afterDeserialize: (/**
|
|
148
|
-
* @param {?} obj
|
|
149
|
-
* @return {?}
|
|
150
|
-
*/
|
|
151
|
-
obj => obj) }, options);
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* @param {?} options
|
|
155
|
-
* @param {?} platformId
|
|
156
|
-
* @return {?}
|
|
157
|
-
*/
|
|
158
|
-
function engineFactory(options, platformId) {
|
|
159
|
-
if (isPlatformServer(platformId)) {
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
if (options.storage === 0 /* LocalStorage */) {
|
|
163
|
-
return localStorage;
|
|
164
|
-
}
|
|
165
|
-
else if (options.storage === 1 /* SessionStorage */) {
|
|
166
|
-
return sessionStorage;
|
|
167
|
-
}
|
|
168
|
-
return null;
|
|
97
|
+
/**
|
|
98
|
+
* @fileoverview added by tsickle
|
|
99
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
100
|
+
*/
|
|
101
|
+
/**
|
|
102
|
+
* If the `key` option is not provided then the below constant
|
|
103
|
+
* will be used as a default key
|
|
104
|
+
* @type {?}
|
|
105
|
+
*/
|
|
106
|
+
const DEFAULT_STATE_KEY = '@@STATE';
|
|
107
|
+
/**
|
|
108
|
+
* This key is used to retrieve static metadatas on state classes.
|
|
109
|
+
* This constant is taken from the core codebase
|
|
110
|
+
* @type {?}
|
|
111
|
+
*/
|
|
112
|
+
const META_OPTIONS_KEY = 'NGXS_OPTIONS_META';
|
|
113
|
+
/**
|
|
114
|
+
* @param {?} key
|
|
115
|
+
* @return {?}
|
|
116
|
+
*/
|
|
117
|
+
function transformKeyOption(key) {
|
|
118
|
+
if (!Array.isArray(key)) {
|
|
119
|
+
key = [key];
|
|
120
|
+
}
|
|
121
|
+
return key.map((/**
|
|
122
|
+
* @param {?} token
|
|
123
|
+
* @return {?}
|
|
124
|
+
*/
|
|
125
|
+
(token) => {
|
|
126
|
+
// If it has the `NGXS_OPTIONS_META` key then it means the developer
|
|
127
|
+
// has provided state class like `key: [AuthState]`.
|
|
128
|
+
if (token.hasOwnProperty(META_OPTIONS_KEY)) {
|
|
129
|
+
// The `name` property will be an actual state name or a `StateToken`.
|
|
130
|
+
token = ((/** @type {?} */ (token)))[META_OPTIONS_KEY].name;
|
|
131
|
+
}
|
|
132
|
+
return token instanceof StateToken ? token.getName() : ((/** @type {?} */ (token)));
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* @param {?} options
|
|
137
|
+
* @return {?}
|
|
138
|
+
*/
|
|
139
|
+
function storageOptionsFactory(options) {
|
|
140
|
+
if (options !== undefined && options.key) {
|
|
141
|
+
options.key = transformKeyOption(options.key);
|
|
142
|
+
}
|
|
143
|
+
return Object.assign({ key: [DEFAULT_STATE_KEY], storage: 0 /* LocalStorage */, serialize: JSON.stringify, deserialize: JSON.parse, beforeSerialize: (/**
|
|
144
|
+
* @param {?} obj
|
|
145
|
+
* @return {?}
|
|
146
|
+
*/
|
|
147
|
+
obj => obj), afterDeserialize: (/**
|
|
148
|
+
* @param {?} obj
|
|
149
|
+
* @return {?}
|
|
150
|
+
*/
|
|
151
|
+
obj => obj) }, options);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* @param {?} options
|
|
155
|
+
* @param {?} platformId
|
|
156
|
+
* @return {?}
|
|
157
|
+
*/
|
|
158
|
+
function engineFactory(options, platformId) {
|
|
159
|
+
if (isPlatformServer(platformId)) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
if (options.storage === 0 /* LocalStorage */) {
|
|
163
|
+
return localStorage;
|
|
164
|
+
}
|
|
165
|
+
else if (options.storage === 1 /* SessionStorage */) {
|
|
166
|
+
return sessionStorage;
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
/**
|
|
172
|
-
* @fileoverview added by tsickle
|
|
173
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
174
|
-
*/
|
|
175
|
-
class NgxsStoragePlugin {
|
|
176
|
-
/**
|
|
177
|
-
* @param {?} _options
|
|
178
|
-
* @param {?} _engine
|
|
179
|
-
* @param {?} _platformId
|
|
180
|
-
*/
|
|
181
|
-
constructor(_options, _engine, _platformId) {
|
|
182
|
-
this._options = _options;
|
|
183
|
-
this._engine = _engine;
|
|
184
|
-
this._platformId = _platformId;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* @param {?} state
|
|
188
|
-
* @param {?} event
|
|
189
|
-
* @param {?} next
|
|
190
|
-
* @return {?}
|
|
191
|
-
*/
|
|
192
|
-
handle(state, event, next) {
|
|
193
|
-
if (isPlatformServer(this._platformId) && this._engine === null) {
|
|
194
|
-
return next(state, event);
|
|
195
|
-
}
|
|
196
|
-
// We cast to `string[]` here as we're sure that this option has been
|
|
197
|
-
// transformed by the `storageOptionsFactory` function that provided token
|
|
198
|
-
/** @type {?} */
|
|
199
|
-
const keys = (/** @type {?} */ (this._options.key));
|
|
200
|
-
/** @type {?} */
|
|
201
|
-
const matches = actionMatcher(event);
|
|
202
|
-
/** @type {?} */
|
|
203
|
-
const isInitAction = matches(InitState);
|
|
204
|
-
/** @type {?} */
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
{ type: String, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] }
|
|
298
|
-
];
|
|
299
|
-
if (false) {
|
|
300
|
-
/**
|
|
301
|
-
* @type {?}
|
|
302
|
-
* @private
|
|
303
|
-
*/
|
|
304
|
-
NgxsStoragePlugin.prototype._options;
|
|
305
|
-
/**
|
|
306
|
-
* @type {?}
|
|
307
|
-
* @private
|
|
308
|
-
*/
|
|
309
|
-
NgxsStoragePlugin.prototype._engine;
|
|
310
|
-
/**
|
|
311
|
-
* @type {?}
|
|
312
|
-
* @private
|
|
313
|
-
*/
|
|
314
|
-
NgxsStoragePlugin.prototype._platformId;
|
|
171
|
+
/**
|
|
172
|
+
* @fileoverview added by tsickle
|
|
173
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
174
|
+
*/
|
|
175
|
+
class NgxsStoragePlugin {
|
|
176
|
+
/**
|
|
177
|
+
* @param {?} _options
|
|
178
|
+
* @param {?} _engine
|
|
179
|
+
* @param {?} _platformId
|
|
180
|
+
*/
|
|
181
|
+
constructor(_options, _engine, _platformId) {
|
|
182
|
+
this._options = _options;
|
|
183
|
+
this._engine = _engine;
|
|
184
|
+
this._platformId = _platformId;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* @param {?} state
|
|
188
|
+
* @param {?} event
|
|
189
|
+
* @param {?} next
|
|
190
|
+
* @return {?}
|
|
191
|
+
*/
|
|
192
|
+
handle(state, event, next) {
|
|
193
|
+
if (isPlatformServer(this._platformId) && this._engine === null) {
|
|
194
|
+
return next(state, event);
|
|
195
|
+
}
|
|
196
|
+
// We cast to `string[]` here as we're sure that this option has been
|
|
197
|
+
// transformed by the `storageOptionsFactory` function that provided token
|
|
198
|
+
/** @type {?} */
|
|
199
|
+
const keys = (/** @type {?} */ (this._options.key));
|
|
200
|
+
/** @type {?} */
|
|
201
|
+
const matches = actionMatcher(event);
|
|
202
|
+
/** @type {?} */
|
|
203
|
+
const isInitAction = matches(InitState) || matches(UpdateState);
|
|
204
|
+
/** @type {?} */
|
|
205
|
+
let hasMigration = false;
|
|
206
|
+
if (isInitAction) {
|
|
207
|
+
for (const key of keys) {
|
|
208
|
+
/** @type {?} */
|
|
209
|
+
const isMaster = key === DEFAULT_STATE_KEY;
|
|
210
|
+
/** @type {?} */
|
|
211
|
+
let val = this._engine.getItem((/** @type {?} */ (key)));
|
|
212
|
+
if (val !== 'undefined' && typeof val !== 'undefined' && val !== null) {
|
|
213
|
+
try {
|
|
214
|
+
/** @type {?} */
|
|
215
|
+
const newVal = (/** @type {?} */ (this._options.deserialize))(val);
|
|
216
|
+
val = (/** @type {?} */ (this._options.afterDeserialize))(newVal, key);
|
|
217
|
+
}
|
|
218
|
+
catch (e) {
|
|
219
|
+
console.error('Error ocurred while deserializing the store value, falling back to empty object.');
|
|
220
|
+
val = {};
|
|
221
|
+
}
|
|
222
|
+
if (this._options.migrations) {
|
|
223
|
+
this._options.migrations.forEach((/**
|
|
224
|
+
* @param {?} strategy
|
|
225
|
+
* @return {?}
|
|
226
|
+
*/
|
|
227
|
+
strategy => {
|
|
228
|
+
/** @type {?} */
|
|
229
|
+
const versionMatch = strategy.version === getValue(val, strategy.versionKey || 'version');
|
|
230
|
+
/** @type {?} */
|
|
231
|
+
const keyMatch = (!strategy.key && isMaster) || strategy.key === key;
|
|
232
|
+
if (versionMatch && keyMatch) {
|
|
233
|
+
val = strategy.migrate(val);
|
|
234
|
+
hasMigration = true;
|
|
235
|
+
}
|
|
236
|
+
}));
|
|
237
|
+
}
|
|
238
|
+
if (!isMaster) {
|
|
239
|
+
state = setValue(state, (/** @type {?} */ (key)), val);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
state = Object.assign({}, state, val);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return next(state, event).pipe(tap((/**
|
|
248
|
+
* @param {?} nextState
|
|
249
|
+
* @return {?}
|
|
250
|
+
*/
|
|
251
|
+
nextState => {
|
|
252
|
+
if (!isInitAction || (isInitAction && hasMigration)) {
|
|
253
|
+
for (const key of keys) {
|
|
254
|
+
/** @type {?} */
|
|
255
|
+
let val = nextState;
|
|
256
|
+
if (key !== DEFAULT_STATE_KEY) {
|
|
257
|
+
val = getValue(nextState, (/** @type {?} */ (key)));
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
/** @type {?} */
|
|
261
|
+
const newVal = (/** @type {?} */ (this._options.beforeSerialize))(val, key);
|
|
262
|
+
this._engine.setItem((/** @type {?} */ (key)), (/** @type {?} */ (this._options.serialize))(newVal));
|
|
263
|
+
}
|
|
264
|
+
catch (e) {
|
|
265
|
+
console.error('Error ocurred while serializing the store value, value not updated.');
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
})));
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
NgxsStoragePlugin.decorators = [
|
|
273
|
+
{ type: Injectable }
|
|
274
|
+
];
|
|
275
|
+
/** @nocollapse */
|
|
276
|
+
NgxsStoragePlugin.ctorParameters = () => [
|
|
277
|
+
{ type: undefined, decorators: [{ type: Inject, args: [NGXS_STORAGE_PLUGIN_OPTIONS,] }] },
|
|
278
|
+
{ type: undefined, decorators: [{ type: Inject, args: [STORAGE_ENGINE,] }] },
|
|
279
|
+
{ type: String, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] }
|
|
280
|
+
];
|
|
281
|
+
if (false) {
|
|
282
|
+
/**
|
|
283
|
+
* @type {?}
|
|
284
|
+
* @private
|
|
285
|
+
*/
|
|
286
|
+
NgxsStoragePlugin.prototype._options;
|
|
287
|
+
/**
|
|
288
|
+
* @type {?}
|
|
289
|
+
* @private
|
|
290
|
+
*/
|
|
291
|
+
NgxsStoragePlugin.prototype._engine;
|
|
292
|
+
/**
|
|
293
|
+
* @type {?}
|
|
294
|
+
* @private
|
|
295
|
+
*/
|
|
296
|
+
NgxsStoragePlugin.prototype._platformId;
|
|
315
297
|
}
|
|
316
298
|
|
|
317
|
-
/**
|
|
318
|
-
* @fileoverview added by tsickle
|
|
319
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
320
|
-
*/
|
|
321
|
-
/** @type {?} */
|
|
322
|
-
const USER_OPTIONS = new InjectionToken('USER_OPTIONS');
|
|
323
|
-
class NgxsStoragePluginModule {
|
|
324
|
-
/**
|
|
325
|
-
* @param {?=} options
|
|
326
|
-
* @return {?}
|
|
327
|
-
*/
|
|
328
|
-
static forRoot(options) {
|
|
329
|
-
return {
|
|
330
|
-
ngModule: NgxsStoragePluginModule,
|
|
331
|
-
providers: [
|
|
332
|
-
{
|
|
333
|
-
provide: NGXS_PLUGINS,
|
|
334
|
-
useClass: NgxsStoragePlugin,
|
|
335
|
-
multi: true
|
|
336
|
-
},
|
|
337
|
-
{
|
|
338
|
-
provide: USER_OPTIONS,
|
|
339
|
-
useValue: options
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
provide: NGXS_STORAGE_PLUGIN_OPTIONS,
|
|
343
|
-
useFactory: storageOptionsFactory,
|
|
344
|
-
deps: [USER_OPTIONS]
|
|
345
|
-
},
|
|
346
|
-
{
|
|
347
|
-
provide: STORAGE_ENGINE,
|
|
348
|
-
useFactory: engineFactory,
|
|
349
|
-
deps: [NGXS_STORAGE_PLUGIN_OPTIONS, PLATFORM_ID]
|
|
350
|
-
}
|
|
351
|
-
]
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
NgxsStoragePluginModule.decorators = [
|
|
356
|
-
{ type: NgModule }
|
|
299
|
+
/**
|
|
300
|
+
* @fileoverview added by tsickle
|
|
301
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
302
|
+
*/
|
|
303
|
+
/** @type {?} */
|
|
304
|
+
const USER_OPTIONS = new InjectionToken('USER_OPTIONS');
|
|
305
|
+
class NgxsStoragePluginModule {
|
|
306
|
+
/**
|
|
307
|
+
* @param {?=} options
|
|
308
|
+
* @return {?}
|
|
309
|
+
*/
|
|
310
|
+
static forRoot(options) {
|
|
311
|
+
return {
|
|
312
|
+
ngModule: NgxsStoragePluginModule,
|
|
313
|
+
providers: [
|
|
314
|
+
{
|
|
315
|
+
provide: NGXS_PLUGINS,
|
|
316
|
+
useClass: NgxsStoragePlugin,
|
|
317
|
+
multi: true
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
provide: USER_OPTIONS,
|
|
321
|
+
useValue: options
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
provide: NGXS_STORAGE_PLUGIN_OPTIONS,
|
|
325
|
+
useFactory: storageOptionsFactory,
|
|
326
|
+
deps: [USER_OPTIONS]
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
provide: STORAGE_ENGINE,
|
|
330
|
+
useFactory: engineFactory,
|
|
331
|
+
deps: [NGXS_STORAGE_PLUGIN_OPTIONS, PLATFORM_ID]
|
|
332
|
+
}
|
|
333
|
+
]
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
NgxsStoragePluginModule.decorators = [
|
|
338
|
+
{ type: NgModule }
|
|
357
339
|
];
|
|
358
340
|
|
|
359
|
-
/**
|
|
360
|
-
* @fileoverview added by tsickle
|
|
361
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
341
|
+
/**
|
|
342
|
+
* @fileoverview added by tsickle
|
|
343
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
362
344
|
*/
|
|
363
345
|
|
|
364
|
-
/**
|
|
365
|
-
* @fileoverview added by tsickle
|
|
366
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
346
|
+
/**
|
|
347
|
+
* @fileoverview added by tsickle
|
|
348
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
367
349
|
*/
|
|
368
350
|
|
|
369
|
-
/**
|
|
370
|
-
* @fileoverview added by tsickle
|
|
371
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
351
|
+
/**
|
|
352
|
+
* @fileoverview added by tsickle
|
|
353
|
+
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
372
354
|
*/
|
|
373
355
|
|
|
374
356
|
export { NGXS_STORAGE_PLUGIN_OPTIONS, NgxsStoragePlugin, NgxsStoragePluginModule, STORAGE_ENGINE, USER_OPTIONS as ɵa, storageOptionsFactory as ɵb, engineFactory as ɵc };
|