global-store 1.0.0-beta.18 → 1.0.0-beta.20
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 +37 -50
- package/dist/createAsyncStore.d.ts +3 -3
- package/dist/createStore.d.ts +1 -1
- package/dist/global-store.es.js +21 -28
- package/dist/global-store.es.js.map +1 -1
- package/dist/global-store.es5.js +1 -1
- package/dist/global-store.es5.js.map +1 -1
- package/dist/global-store.systemjs.js +24 -30
- package/dist/global-store.systemjs.js.map +1 -1
- package/dist/types.d.ts +6 -6
- package/dist/util.d.ts +6 -5
- package/lib/compareVersion.d.ts +7 -0
- package/lib/compareVersion.js +3 -4
- package/lib/compareVersion.js.map +1 -1
- package/lib/createAsyncStore.d.ts +12 -0
- package/lib/createAsyncStore.js +8 -15
- package/lib/createAsyncStore.js.map +1 -1
- package/lib/createStore.d.ts +28 -0
- package/lib/createStore.js +6 -6
- package/lib/createStore.js.map +1 -1
- package/lib/index.d.ts +4 -0
- package/lib/index.js +7 -2
- package/lib/index.js.map +1 -1
- package/lib/shouldInvokeInitializer.d.ts +2 -0
- package/lib/shouldInvokeInitializer.js +3 -2
- package/lib/shouldInvokeInitializer.js.map +1 -1
- package/lib/toVersionArray.d.ts +3 -0
- package/lib/toVersionArray.js.map +1 -1
- package/lib/types.d.ts +9 -0
- package/lib/types.js.map +1 -1
- package/lib/typesInternal.d.ts +16 -0
- package/lib/typesInternal.js.map +1 -1
- package/lib/util.d.ts +14 -0
- package/lib/util.js +8 -6
- package/lib/util.js.map +1 -1
- package/libm/compareVersion.js +1 -2
- package/libm/compareVersion.js.map +1 -1
- package/libm/createAsyncStore.d.ts +3 -3
- package/libm/createAsyncStore.js +8 -15
- package/libm/createAsyncStore.js.map +1 -1
- package/libm/createStore.d.ts +1 -1
- package/libm/createStore.js +4 -4
- package/libm/createStore.js.map +1 -1
- package/libm/index.js.map +1 -1
- package/libm/shouldInvokeInitializer.js +2 -1
- package/libm/shouldInvokeInitializer.js.map +1 -1
- package/libm/toVersionArray.js.map +1 -1
- package/libm/types.d.ts +6 -6
- package/libm/types.js +1 -0
- package/libm/types.js.map +1 -1
- package/libm/typesInternal.d.ts +9 -9
- package/libm/typesInternal.js +1 -0
- package/libm/typesInternal.js.map +1 -1
- package/libm/util.d.ts +7 -6
- package/libm/util.js +5 -4
- package/libm/util.js.map +1 -1
- package/package.json +61 -40
- package/{src → ts}/compareVersion.spec.ts +0 -0
- package/{src → ts}/compareVersion.ts +1 -2
- package/{src → ts}/createAsyncStore.spec.ts +9 -1
- package/{src → ts}/createAsyncStore.ts +8 -15
- package/{src → ts}/createStore.spec.ts +13 -6
- package/{src → ts}/createStore.ts +5 -5
- package/{src → ts}/index.spec.ts +0 -0
- package/{src → ts}/index.ts +0 -0
- package/{src → ts}/shouldInvokeInitializer.spec.ts +0 -0
- package/{src → ts}/shouldInvokeInitializer.ts +2 -2
- package/{src → ts}/toVersionArray.ts +1 -1
- package/ts/types.ts +12 -0
- package/ts/typesInternal.ts +21 -0
- package/{src → ts}/util.ts +12 -10
- package/src/types.ts +0 -12
- package/src/typesInternal.ts +0 -19
package/README.md
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
# global-store
|
|
2
2
|
|
|
3
3
|
[![NPM version][npm-image]][npm-url]
|
|
4
|
-
[![NPM beta version][npm-beta-image]][npm-url]
|
|
5
4
|
[![NPM downloads][downloads-image]][downloads-url]
|
|
6
5
|
![badge-size-es5-url]
|
|
7
|
-
![badge-size-esnext-url]
|
|
8
6
|
|
|
9
|
-
[![
|
|
10
|
-
[![Travis CI][travis-image]][travis-url]
|
|
7
|
+
[![GitHub NodeJS][github-nodejs]][github-action-url]
|
|
11
8
|
[![Codecov][codecov-image]][codecov-url]
|
|
12
|
-
[![Coveralls Status][coveralls-image]][coveralls-url]
|
|
13
9
|
|
|
14
|
-
[![Greenkeeper][greenkeeper-image]][greenkeeper-url]
|
|
15
10
|
[![Visual Studio Code][vscode-image]][vscode-url]
|
|
16
|
-
[![Wallaby.js][wallaby-image]][wallaby-url]
|
|
17
11
|
|
|
18
|
-
[global-store] provides version stable stores for
|
|
12
|
+
[global-store] provides version stable stores for libraries.
|
|
19
13
|
|
|
20
14
|
Once this library reaches `1.0`, it will forever be backward compatible.
|
|
21
15
|
Meaning there will never be a breaking change or `2.0` version of this library.
|
|
@@ -24,17 +18,18 @@ PLEASE NOTE: This document describes the new `1.0.0-beta` version (finally!! :ta
|
|
|
24
18
|
|
|
25
19
|
For the current stable version, please check out [here](https://github.com/unional/global-store/blob/v0.8.2/README.md).
|
|
26
20
|
|
|
27
|
-
## Who
|
|
21
|
+
## Who needs this
|
|
28
22
|
|
|
29
|
-
- library
|
|
30
|
-
- library with state, and/or
|
|
31
|
-
- library wants to protect its state from modification.
|
|
23
|
+
- A library used by other libraries, and
|
|
24
|
+
- A library with state, and/or
|
|
25
|
+
- A library wants to protect its state from modification.
|
|
32
26
|
|
|
33
27
|
## Why do you need this
|
|
34
28
|
|
|
35
|
-
If you use a file
|
|
29
|
+
If you use a file-level variable to store some states,
|
|
36
30
|
and your library can be used by other libraries,
|
|
37
|
-
the state it stores could scatter around the memory
|
|
31
|
+
the state it stores could scatter around the memory,
|
|
32
|
+
and you will get inconsistent results.
|
|
38
33
|
|
|
39
34
|
For example, you have this:
|
|
40
35
|
|
|
@@ -50,7 +45,7 @@ When your library is used by other libraries,
|
|
|
50
45
|
they may use different versions.
|
|
51
46
|
For example:
|
|
52
47
|
|
|
53
|
-
```
|
|
48
|
+
```sh
|
|
54
49
|
app
|
|
55
50
|
- some-library@1.5
|
|
56
51
|
- your-library@1.0
|
|
@@ -60,8 +55,8 @@ app
|
|
|
60
55
|
Since the versions are not compatible,
|
|
61
56
|
both versions of your library are loaded thus two instances of the `registry` variable exist and contain different values.
|
|
62
57
|
|
|
63
|
-
|
|
64
|
-
or global variable in browser.
|
|
58
|
+
The solution to this problem is to use some form of global storage such as `global` in NodeJS,
|
|
59
|
+
or global variable in the browser.
|
|
65
60
|
|
|
66
61
|
The problem is that these mechanisms are shared by everything else in the application,
|
|
67
62
|
completely exposed to everyone,
|
|
@@ -93,7 +88,7 @@ const store = createStore({
|
|
|
93
88
|
moduleName: 'your-module',
|
|
94
89
|
key: 'some-unique-string',
|
|
95
90
|
version: '1.0.0',
|
|
96
|
-
initializer: (current, versions) =>({
|
|
91
|
+
initializer: (current, versions) => ({
|
|
97
92
|
prop1: false,
|
|
98
93
|
prop2: [] as string[],
|
|
99
94
|
...current
|
|
@@ -113,48 +108,50 @@ Type: `string`
|
|
|
113
108
|
|
|
114
109
|
Name of your module.
|
|
115
110
|
|
|
116
|
-
This is typically your
|
|
111
|
+
This is typically your NPM package name.
|
|
117
112
|
This will be shown if something goes wrong.
|
|
118
113
|
|
|
119
114
|
#### StoreOptions#key
|
|
120
115
|
|
|
121
|
-
Type: `string`
|
|
116
|
+
Type: optional `string`
|
|
122
117
|
|
|
123
|
-
|
|
118
|
+
A specific key for each store in your module.
|
|
124
119
|
|
|
125
120
|
You can create multiple stores in your module for different purposes.
|
|
126
121
|
The key for each store needs to be unique.
|
|
127
|
-
And the key has to
|
|
122
|
+
And the key has to remain the same across versions.
|
|
128
123
|
|
|
129
124
|
For example, you can use a format like this to make it unique: `<some-purpose>:<UUID>`
|
|
130
125
|
|
|
131
126
|
e.g. `config:d15427a4-75cf-4999-9065-1dc325839a59`
|
|
132
127
|
|
|
133
|
-
`key` + `moduleName` forms
|
|
128
|
+
`key` + `moduleName` forms a unique ID to the store.
|
|
134
129
|
|
|
135
130
|
`key` will not be shown if something goes wrong.
|
|
136
131
|
|
|
132
|
+
If `key` is not specified, it defaults to the string `default`.
|
|
133
|
+
|
|
137
134
|
#### StoreOptions#version
|
|
138
135
|
|
|
139
136
|
Type: `StoreVersion = string | number`
|
|
140
137
|
|
|
141
|
-
|
|
138
|
+
The version of the store.
|
|
142
139
|
|
|
143
140
|
This is used during initialization to determine should the [`StoreOptions#initializer`](#StoreOptionsinitializer) be called (and in what order for [`createAsyncStore()`](#createAsyncStore)).
|
|
144
141
|
|
|
145
142
|
It will be added to the `processedVersions` argument of the [`StoreOptions#initializer()`](#StoreOptionsinitializer) after it is being called.
|
|
146
143
|
|
|
147
|
-
When
|
|
144
|
+
When specified as a string (recommended),
|
|
148
145
|
it must be in this format: `major.minor.patch`.
|
|
149
146
|
|
|
150
|
-
When there is a mix of string and numeric
|
|
147
|
+
When there is a mix of string and numeric versions across different versions of your library,
|
|
151
148
|
the numeric value is compared to the patch number of the string version.
|
|
152
149
|
|
|
153
150
|
#### StoreOptions#initializer()
|
|
154
151
|
|
|
155
152
|
Type: `<T extends StoreValue>(current: StoreValue, processedVersions: StoreVersion[]) => T`
|
|
156
153
|
|
|
157
|
-
|
|
154
|
+
The function to initialize the store.
|
|
158
155
|
|
|
159
156
|
Since there may be multiple copies of your library loaded,
|
|
160
157
|
multiple calls to the store creation function (e.g. [`createStore()`](#createStore)) may occur.
|
|
@@ -169,11 +166,11 @@ the `initializer` function will be called in the order of `version`.
|
|
|
169
166
|
|
|
170
167
|
For [`createStore`](#createStore),
|
|
171
168
|
since there is no way to control the load order,
|
|
172
|
-
they can be called by a newer version of your
|
|
173
|
-
This means your `initializer` needs to be future
|
|
169
|
+
they can be called by a newer version of your library before an older version.
|
|
170
|
+
This means your `initializer` needs to be future-proof.
|
|
174
171
|
|
|
175
172
|
To do that, you should fill in the pieces your specific version needs,
|
|
176
|
-
and carry over whatever currently available.
|
|
173
|
+
and carry over whatever is currently available.
|
|
177
174
|
|
|
178
175
|
This is only a general guideline,
|
|
179
176
|
the actual implementation will depend on how you use your store.
|
|
@@ -182,9 +179,9 @@ the actual implementation will depend on how you use your store.
|
|
|
182
179
|
|
|
183
180
|
Type: `Record<string | symbol, any>`
|
|
184
181
|
|
|
185
|
-
|
|
182
|
+
The type of value stored in the stores.
|
|
186
183
|
|
|
187
|
-
Note that the key must be string or `Symbol.for()` because `Symbol()` cannot be shared across versions.
|
|
184
|
+
Note that the key must be a string or `Symbol.for()` because `Symbol()` cannot be shared across versions.
|
|
188
185
|
|
|
189
186
|
#### Store#value
|
|
190
187
|
|
|
@@ -203,11 +200,11 @@ store.value.x = 2
|
|
|
203
200
|
|
|
204
201
|
Reset the store to its initial value.
|
|
205
202
|
|
|
206
|
-
This is mostly used in tests
|
|
203
|
+
This is mostly used in tests so that the tests would not interfere with each other.
|
|
207
204
|
|
|
208
205
|
### createAsyncStore()
|
|
209
206
|
|
|
210
|
-
|
|
207
|
+
A `async` variant of [`createStore()`](#createStore).
|
|
211
208
|
It will return a promise,
|
|
212
209
|
which will resolve when the [`initializeAsyncStore()`](#initializeAsyncStore) is called.
|
|
213
210
|
|
|
@@ -221,40 +218,30 @@ Calling [`initializeAsyncStore()`](#initializeAsyncStore) will start the initial
|
|
|
221
218
|
|
|
222
219
|
It takes two arguments:
|
|
223
220
|
|
|
224
|
-
- `moduleName: string`: Name of your
|
|
221
|
+
- `moduleName: string`: Name of your module.
|
|
225
222
|
- `key: string`: Optional. Key of the specific store to initialize.
|
|
226
223
|
If omitted, all stores in the module will be initialized.
|
|
227
224
|
|
|
228
225
|
## Bundling
|
|
229
226
|
|
|
230
227
|
If your library will be a standalone bundle, make sure to exclude [global-store].
|
|
231
|
-
If not, there will be multiple copies of [global-store] loaded and will completely defeat the purpose.
|
|
232
228
|
|
|
233
|
-
|
|
229
|
+
If not, there will be multiple copies of [global-store] loaded and will completely defeat the purpose.
|
|
234
230
|
|
|
235
|
-
|
|
231
|
+
Except the consuming application, which will declare [global-store] as a regular dependency,
|
|
232
|
+
all libraries should declare [global-store] as a peer dependency.
|
|
236
233
|
|
|
237
234
|
[badge-size-es5-url]: http://img.badgesize.io/unional/global-store/master/dist/global-store.es5.js.svg?label=es5_size&compression=gzip
|
|
238
|
-
[badge-size-esnext-url]: http://img.badgesize.io/unional/global-store/master/dist/global-store.es.js.svg?label=esnext_size&compression=gzip
|
|
239
|
-
[circleci-image]: https://circleci.com/gh/unional/global-store/tree/master.svg?style=shield
|
|
240
|
-
[circleci-url]: https://circleci.com/gh/unional/global-store/tree/master
|
|
241
235
|
[codecov-image]: https://codecov.io/gh/unional/global-store/branch/master/graph/badge.svg
|
|
242
236
|
[codecov-url]: https://codecov.io/gh/unional/global-store
|
|
243
|
-
[coveralls-image]: https://coveralls.io/repos/github/unional/global-store/badge.svg
|
|
244
|
-
[coveralls-url]: https://coveralls.io/github/unional/global-store
|
|
245
237
|
[downloads-image]: https://img.shields.io/npm/dm/global-store.svg?style=flat
|
|
246
238
|
[downloads-url]: https://npmjs.org/package/global-store
|
|
239
|
+
[github-nodejs]: https://github.com/unional/global-store/workflows/release/badge.svg
|
|
240
|
+
[github-action-url]: https://github.com/unional/global-store/actions
|
|
247
241
|
[global-store]: https://github.com/unional/global-store
|
|
248
|
-
[greenkeeper-image]: https://badges.greenkeeper.io/unional/global-store.svg
|
|
249
|
-
[greenkeeper-url]: https://greenkeeper.io/
|
|
250
|
-
[npm-beta-image]: https://img.shields.io/npm/v/global-store/beta.svg?style=flat
|
|
251
242
|
[npm-image]: https://img.shields.io/npm/v/global-store.svg?style=flat
|
|
252
243
|
[npm-url]: https://npmjs.org/package/global-store
|
|
253
244
|
[downloads-image]: https://img.shields.io/npm/dm/global-store.svg?style=flat
|
|
254
245
|
[downloads-url]: https://npmjs.org/package/global-store
|
|
255
|
-
[travis-image]: https://img.shields.io/travis/unional/global-store/master.svg?style=flat
|
|
256
|
-
[travis-url]: https://travis-ci.org/unional/global-store?branch=master
|
|
257
246
|
[vscode-image]: https://img.shields.io/badge/vscode-ready-green.svg
|
|
258
247
|
[vscode-url]: https://code.visualstudio.com/
|
|
259
|
-
[wallaby-image]: https://img.shields.io/badge/wallaby.js-configured-green.svg
|
|
260
|
-
[wallaby-url]: https://wallabyjs.com
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Store } from './createStore';
|
|
2
2
|
import { StoreOptions, StoreValue } from './types';
|
|
3
3
|
/**
|
|
4
|
-
* Creates a store of type T
|
|
5
|
-
* https://github.com/unional/global-store#createAsyncStore
|
|
4
|
+
* Creates a store of type T asynchronously.
|
|
5
|
+
* @see https://github.com/unional/global-store#createAsyncStore
|
|
6
6
|
*/
|
|
7
7
|
export declare function createAsyncStore<T extends StoreValue>({ moduleName, key, version, initializer }: StoreOptions<T>): Promise<Store<T>>;
|
|
8
8
|
/**
|
|
9
9
|
* Initializes the stores for `createAsyncStore()`.
|
|
10
|
-
* https://github.com/unional/global-store#initializeAsyncStore
|
|
10
|
+
* @see https://github.com/unional/global-store#initializeAsyncStore
|
|
11
11
|
*/
|
|
12
12
|
export declare function initializeAsyncStore(moduleName: string, key?: string): void;
|
package/dist/createStore.d.ts
CHANGED
|
@@ -23,6 +23,6 @@ export declare type Store<T extends StoreValue> = {
|
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Creates a store of type T.
|
|
26
|
-
* https://www.npmjs.com/package/global-store
|
|
26
|
+
* @see https://www.npmjs.com/package/global-store
|
|
27
27
|
*/
|
|
28
28
|
export declare function createStore<T extends StoreValue>({ moduleName, key, version, initializer }: StoreOptions<T>): Store<T>;
|
package/dist/global-store.es.js
CHANGED
|
@@ -12,8 +12,7 @@ function compareVersion(processed, current) {
|
|
|
12
12
|
const v1 = toVersionArray(processed);
|
|
13
13
|
const v2 = toVersionArray(current);
|
|
14
14
|
return v1[0] !== v2[0] ? v1[0] - v2[0] :
|
|
15
|
-
v1[1] !== v2[1] ? v1[1] - v2[1] :
|
|
16
|
-
v1[2] - v2[2];
|
|
15
|
+
v1[1] !== v2[1] ? v1[1] - v2[1] : v1[2] - v2[2];
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
function shouldInvokeInitializer(versions, version) {
|
|
@@ -25,7 +24,8 @@ function noMatchMajor(versions, version) {
|
|
|
25
24
|
return !versions.some(v => v[0] === version[0]);
|
|
26
25
|
}
|
|
27
26
|
function hasNewVersion(versions, version) {
|
|
28
|
-
return versions.filter(v => v[0] === version[0])
|
|
27
|
+
return versions.filter(v => v[0] === version[0])
|
|
28
|
+
.some(v => version[1] > v[1] || (version[1] === v[1] && version[2] > v[2]));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function getStoreValue(stores, id) {
|
|
@@ -50,11 +50,12 @@ function resetStoreValue(stores, id) {
|
|
|
50
50
|
}, {});
|
|
51
51
|
}
|
|
52
52
|
function getStore(stores, id) {
|
|
53
|
-
const moduleStore = stores[id.moduleName] = stores[id.moduleName] ||
|
|
54
|
-
|
|
53
|
+
const moduleStore = stores[id.moduleName] = stores[id.moduleName] || Object.create(null);
|
|
54
|
+
const key = id.key ?? 'default';
|
|
55
|
+
return moduleStore[key] = moduleStore[key] || { versions: [], value: {}, initializers: [] };
|
|
55
56
|
}
|
|
56
|
-
function resolveCreators(moduleName, key, storeCreators,
|
|
57
|
-
sortByVersion(storeCreators).forEach(({ version, resolve, initializer }) => resolve(
|
|
57
|
+
function resolveCreators(moduleName, key, storeCreators, cs) {
|
|
58
|
+
sortByVersion(storeCreators).forEach(({ version, resolve, initializer }) => resolve(cs({ moduleName, key, version, initializer })));
|
|
58
59
|
}
|
|
59
60
|
function sortByVersion(storeCreators) {
|
|
60
61
|
return storeCreators.sort((a, b) => compareVersion(a.version, b.version));
|
|
@@ -82,53 +83,45 @@ function freezeIfIsArray(storeValue, k) {
|
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
const stores =
|
|
86
|
+
const stores = Object.create(null);
|
|
86
87
|
/**
|
|
87
88
|
* Creates a store of type T.
|
|
88
|
-
* https://www.npmjs.com/package/global-store
|
|
89
|
+
* @see https://www.npmjs.com/package/global-store
|
|
89
90
|
*/
|
|
90
91
|
function createStore({ moduleName, key, version, initializer }) {
|
|
91
92
|
const id = { moduleName, key };
|
|
92
93
|
initStoreValue(stores, id, version, initializer);
|
|
93
94
|
return {
|
|
94
95
|
get value() { return getStoreValue(stores, id); },
|
|
95
|
-
freeze
|
|
96
|
-
reset
|
|
96
|
+
freeze(value) { return freezeStoreValue(stores, id, value); },
|
|
97
|
+
reset() { return resetStoreValue(stores, id); }
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
const asyncStoreCreators = {};
|
|
101
102
|
/**
|
|
102
|
-
* Creates a store of type T
|
|
103
|
-
* https://github.com/unional/global-store#createAsyncStore
|
|
103
|
+
* Creates a store of type T asynchronously.
|
|
104
|
+
* @see https://github.com/unional/global-store#createAsyncStore
|
|
104
105
|
*/
|
|
105
106
|
async function createAsyncStore({ moduleName, key, version, initializer }) {
|
|
106
107
|
return new Promise(resolve => {
|
|
107
|
-
const creatorsOfModules = asyncStoreCreators[moduleName] = asyncStoreCreators[moduleName] ||
|
|
108
|
-
const
|
|
108
|
+
const creatorsOfModules = asyncStoreCreators[moduleName] = asyncStoreCreators[moduleName] || Object.create(null);
|
|
109
|
+
const k = key ?? 'default';
|
|
110
|
+
const storeCreators = creatorsOfModules[k] = creatorsOfModules[k] || [];
|
|
109
111
|
storeCreators.push({ version, resolve, initializer });
|
|
110
112
|
});
|
|
111
113
|
}
|
|
112
114
|
/**
|
|
113
115
|
* Initializes the stores for `createAsyncStore()`.
|
|
114
|
-
* https://github.com/unional/global-store#initializeAsyncStore
|
|
116
|
+
* @see https://github.com/unional/global-store#initializeAsyncStore
|
|
115
117
|
*/
|
|
116
118
|
function initializeAsyncStore(moduleName, key) {
|
|
117
119
|
const creatorsOfModules = asyncStoreCreators[moduleName];
|
|
118
120
|
if (!creatorsOfModules)
|
|
119
121
|
return;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
resolveCreators(moduleName, key, storeCreators, createStore);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
Object.keys(creatorsOfModules).forEach(k => {
|
|
126
|
-
const storeCreators = creatorsOfModules[k];
|
|
127
|
-
resolveCreators(moduleName, k, storeCreators, createStore);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
122
|
+
const keys = key ? [key] : Object.keys(creatorsOfModules);
|
|
123
|
+
keys.forEach(key => resolveCreators(moduleName, key, creatorsOfModules[key], createStore));
|
|
130
124
|
}
|
|
131
125
|
|
|
132
|
-
export default
|
|
133
|
-
export { createAsyncStore, createStore, initializeAsyncStore };
|
|
126
|
+
export { createAsyncStore, createStore, createStore as default, initializeAsyncStore };
|
|
134
127
|
//# sourceMappingURL=global-store.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-store.es.js","sources":["../src/toVersionArray.ts","../src/compareVersion.ts","../src/shouldInvokeInitializer.ts","../src/util.ts","../src/createStore.ts","../src/createAsyncStore.ts"],"sourcesContent":["import { StoreVersion } from './types'\n\nexport type ParsedVersion = [number, number, number]\n\nexport function toVersionArray(v: StoreVersion): ParsedVersion {\n return typeof v === 'number' ? [0, 0, v] :\n v.split('.').map(v => parseInt(v, 10)) as any\n}\n","import { toVersionArray } from './toVersionArray'\nimport { StoreVersion } from './types'\n\n/**\n * Compare version.\n * Positive when processed > current\n * Negative when processed < current\n */\nexport function compareVersion(processed: StoreVersion, current: StoreVersion) {\n const v1 = toVersionArray(processed)\n const v2 = toVersionArray(current)\n return v1[0] !== v2[0] ? v1[0] - v2[0] :\n v1[1] !== v2[1] ? v1[1] - v2[1] :\n v1[2] - v2[2]\n}\n","import { ParsedVersion, toVersionArray } from './toVersionArray'\nimport { StoreVersion } from './types'\n\nexport function shouldInvokeInitializer(versions: StoreVersion[], version: StoreVersion) {\n const vs = versions.map(toVersionArray)\n const v = toVersionArray(version)\n return noMatchMajor(vs, v) || hasNewVersion(vs, v)\n}\n\nfunction noMatchMajor(versions: ParsedVersion[], version: ParsedVersion) {\n return !versions.some(v => v[0] === version[0])\n}\n\nfunction hasNewVersion(versions: ParsedVersion[], version: ParsedVersion) {\n return versions.filter(v => v[0] === version[0]).some(\n v => version[1] > v[1] || (version[1] === v[1] && version[2] > v[2]))\n}\n","import { compareVersion } from './compareVersion'\nimport { shouldInvokeInitializer } from './shouldInvokeInitializer'\nimport { StoreInitializer, StoreValue, StoreVersion } from './types'\nimport { StoreCreator, StoreId, Stores } from './typesInternal'\n\nexport function getStoreValue(stores: Stores, id: StoreId): any {\n return getStore(stores, id).value\n}\n\nexport function initStoreValue<T extends StoreValue>(stores: Stores, id: StoreId, version: StoreVersion, initializer: StoreInitializer<T>) {\n const store = getStore(stores, id)\n if (shouldInvokeInitializer(store.versions, version)) {\n store.initializers.push(initializer)\n store.value = initializer(store.value as T, store.versions)\n store.versions.push(version)\n }\n}\n\nexport function resetStoreValue(stores: Stores, id: StoreId) {\n const store = getStore(stores, id)\n const versions = store.versions\n store.versions = []\n store.value = store.initializers.reduce((value, initializer, i) => {\n value = initializer(value, store.versions)\n store.versions.push(versions[i])\n return value\n }, {})\n}\n\nexport function getStore(stores: Stores, id: StoreId) {\n const moduleStore = stores[id.moduleName] = stores[id.moduleName] || {}\n return moduleStore[id.key as any] = moduleStore[id.key as any] || { versions: [], value: {}, initializers: [] }\n}\n\nexport function resolveCreators<S>(moduleName: string, key: string, storeCreators: Array<StoreCreator<S>>, createStore: any) {\n sortByVersion(storeCreators).forEach(({ version, resolve, initializer }) => resolve(createStore({ moduleName, key, version, initializer })))\n}\n\nexport function sortByVersion<S>(storeCreators: Array<StoreCreator<S>>) {\n return storeCreators.sort((a, b) => compareVersion(a.version, b.version))\n}\n\nexport function freezeStoreValue(stores: Stores, id: StoreId, value?: any) {\n const store = getStore(stores, id)\n store.value = value ?\n Object.isFrozen(value) ? value : Object.freeze(value) :\n freezeValue(store.value)\n}\n\nfunction freezeValue(storeValue: StoreValue) {\n if (Object.isFrozen(storeValue)) throw TypeError('Frozen value cannot be freezed again')\n\n Object.keys(storeValue).forEach(k => freezeIfIsArray(storeValue, k))\n // istanbul ignore next\n if (Object.getOwnPropertySymbols) {\n Object.getOwnPropertySymbols(storeValue).forEach(k => freezeIfIsArray(storeValue, k))\n }\n\n return Object.freeze(storeValue)\n}\n\nfunction freezeIfIsArray(storeValue: StoreValue, k: any) {\n const value = storeValue[k]\n if (Array.isArray(value)) {\n storeValue[k] = Object.freeze(value)\n }\n}\n","import { StoreOptions, StoreValue } from './types'\nimport { Stores } from './typesInternal'\nimport { freezeStoreValue, getStoreValue, initStoreValue, resetStoreValue } from './util'\n\nexport type Store<T extends StoreValue> = {\n /**\n * The store value.\n */\n readonly value: T,\n /**\n * Freezes the store value.\n * @param value Optional new store value.\n * If supplied, this value will be freezed and used as the store value.\n * You can use this update the store value and freeze part of it.\n * If not supplied,\n * the original value will be freezed and its array property will also be freezed.\n */\n freeze(value?: { [k in keyof T]: Readonly<T[k]> }): void,\n /**\n * Resets the store to its initial value.\n * You should only use this during testing.\n */\n reset(): void,\n}\n\nconst stores: Stores = {}\n\n/**\n * Creates a store of type T.\n * https://www.npmjs.com/package/global-store\n */\nexport function createStore<\n T extends StoreValue\n>({ moduleName, key, version, initializer }: StoreOptions<T>): Store<T> {\n const id = { moduleName, key }\n initStoreValue(stores, id, version, initializer)\n\n return {\n get value() { return getStoreValue(stores, id) },\n freeze: (value) => freezeStoreValue(stores, id, value),\n reset: () => resetStoreValue(stores, id)\n }\n}\n","import { createStore, Store } from './createStore'\nimport { StoreOptions, StoreValue } from './types'\nimport { StoreCreators } from './typesInternal'\nimport { resolveCreators } from './util'\n\nconst asyncStoreCreators: StoreCreators<Store<any>> = {}\n\n/**\n * Creates a store of type T asychronously.\n * https://github.com/unional/global-store#createAsyncStore\n */\nexport async function createAsyncStore<T extends StoreValue>({ moduleName, key, version, initializer }: StoreOptions<T>): Promise<Store<T>> {\n return new Promise(resolve => {\n const creatorsOfModules = asyncStoreCreators[moduleName] = asyncStoreCreators[moduleName] || {}\n const storeCreators = creatorsOfModules[key as any] = creatorsOfModules[key as any] || []\n storeCreators.push({ version, resolve, initializer })\n })\n}\n\n/**\n * Initializes the stores for `createAsyncStore()`.\n * https://github.com/unional/global-store#initializeAsyncStore\n */\nexport function initializeAsyncStore(moduleName: string, key?: string) {\n const creatorsOfModules = asyncStoreCreators[moduleName]\n if (!creatorsOfModules) return\n\n if (key) {\n const storeCreators = creatorsOfModules[key as any]\n resolveCreators(moduleName, key, storeCreators, createStore)\n }\n else {\n Object.keys(creatorsOfModules).forEach(k => {\n const storeCreators = creatorsOfModules[k]\n resolveCreators(moduleName, k, storeCreators, createStore)\n })\n }\n}\n"],"names":[],"mappings":"SAIgB,cAAc,CAAC,CAAe;IAC5C,OAAO,OAAO,CAAC,KAAK,QAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACtC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAQ,CAAA;AACjD;;ACJA;;;;;SAKgB,cAAc,CAAC,SAAuB,EAAE,OAAqB;IAC3E,MAAM,EAAE,GAAG,cAAc,CAAC,SAAS,CAAC,CAAA;IACpC,MAAM,EAAE,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;IAClC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACpC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAC7B,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;AACnB;;SCXgB,uBAAuB,CAAC,QAAwB,EAAE,OAAqB;IACrF,MAAM,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;IACvC,MAAM,CAAC,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;IACjC,OAAO,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,aAAa,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AACpD,CAAC;AAED,SAAS,YAAY,CAAC,QAAyB,EAAE,OAAsB;IACrE,OAAO,CAAC,QAAQ,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D,CAAC,CAAA;KACH;AACH;;;;;"}
|
|
1
|
+
{"version":3,"file":"global-store.es.js","sources":["../ts/toVersionArray.ts","../ts/compareVersion.ts","../ts/shouldInvokeInitializer.ts","../ts/util.ts","../ts/createStore.ts","../ts/createAsyncStore.ts"],"sourcesContent":["import { StoreVersion } from './types'\n\nexport type ParsedVersion = [number, number, number]\n\nexport function toVersionArray(v: StoreVersion): ParsedVersion {\n return typeof v === 'number' ? [0, 0, v] :\n v.split('.').map(v => parseInt(v, 10)) as ParsedVersion\n}\n","import { toVersionArray } from './toVersionArray'\nimport { StoreVersion } from './types'\n\n/**\n * Compare version.\n * Positive when processed > current\n * Negative when processed < current\n */\nexport function compareVersion(processed: StoreVersion, current: StoreVersion) {\n const v1 = toVersionArray(processed)\n const v2 = toVersionArray(current)\n return v1[0] !== v2[0] ? v1[0] - v2[0] :\n v1[1] !== v2[1] ? v1[1] - v2[1] : v1[2] - v2[2]\n}\n","import { ParsedVersion, toVersionArray } from './toVersionArray'\nimport { StoreVersion } from './types'\n\nexport function shouldInvokeInitializer(versions: StoreVersion[], version: StoreVersion) {\n const vs = versions.map(toVersionArray)\n const v = toVersionArray(version)\n return noMatchMajor(vs, v) || hasNewVersion(vs, v)\n}\n\nfunction noMatchMajor(versions: ParsedVersion[], version: ParsedVersion) {\n return !versions.some(v => v[0] === version[0])\n}\n\nfunction hasNewVersion(versions: ParsedVersion[], version: ParsedVersion) {\n return versions.filter(v => v[0] === version[0])\n .some(v => version[1] > v[1] || (version[1] === v[1] && version[2] > v[2]))\n}\n","import { compareVersion } from './compareVersion'\nimport { createStore } from './createStore'\nimport { shouldInvokeInitializer } from './shouldInvokeInitializer'\nimport { StoreInitializer, StoreValue, StoreVersion } from './types'\nimport { StoreCreator, StoreId, Stores } from './typesInternal'\n\nexport function getStoreValue<T extends StoreValue>(stores: Stores, id: StoreId): T {\n return getStore(stores, id).value as T\n}\n\nexport function initStoreValue<T extends StoreValue>(stores: Stores, id: StoreId, version: StoreVersion, initializer: StoreInitializer<T>) {\n const store = getStore(stores, id)\n if (shouldInvokeInitializer(store.versions, version)) {\n store.initializers.push(initializer as StoreInitializer<StoreValue>)\n store.value = initializer(store.value as T, store.versions)\n store.versions.push(version)\n }\n}\n\nexport function resetStoreValue(stores: Stores, id: StoreId) {\n const store = getStore(stores, id)\n const versions = store.versions\n store.versions = []\n store.value = store.initializers.reduce<StoreValue>((value, initializer, i) => {\n value = initializer(value, store.versions)\n store.versions.push(versions[i])\n return value\n }, {})\n}\n\nexport function getStore(stores: Stores, id: StoreId) {\n const moduleStore = stores[id.moduleName] = stores[id.moduleName] || Object.create(null)\n const key = id.key ?? 'default'\n return moduleStore[key] = moduleStore[key] || { versions: [], value: {}, initializers: [] }\n}\n\nexport function resolveCreators(moduleName: string, key: string, storeCreators: Array<StoreCreator<any>>, cs: typeof createStore) {\n sortByVersion(storeCreators).forEach(({ version, resolve, initializer }) => resolve(cs({ moduleName, key, version, initializer })))\n}\n\nexport function sortByVersion<S>(storeCreators: Array<StoreCreator<S>>) {\n return storeCreators.sort((a, b) => compareVersion(a.version, b.version))\n}\n\nexport function freezeStoreValue(stores: Stores, id: StoreId, value?: StoreValue) {\n const store = getStore(stores, id)\n store.value = value ?\n Object.isFrozen(value) ? value : Object.freeze(value) :\n freezeValue(store.value)\n}\n\nfunction freezeValue(storeValue: StoreValue) {\n if (Object.isFrozen(storeValue)) throw TypeError('Frozen value cannot be freezed again')\n\n Object.keys(storeValue).forEach(k => freezeIfIsArray(storeValue, k))\n // istanbul ignore next\n if (Object.getOwnPropertySymbols) {\n Object.getOwnPropertySymbols(storeValue).forEach(k => freezeIfIsArray(storeValue, k))\n }\n\n return Object.freeze(storeValue)\n}\n\nfunction freezeIfIsArray(storeValue: StoreValue, k: string | number | symbol) {\n const value = storeValue[k]\n if (Array.isArray(value)) {\n storeValue[k] = Object.freeze(value)\n }\n}\n","import { StoreOptions, StoreValue } from './types'\nimport { Stores } from './typesInternal'\nimport { freezeStoreValue, getStoreValue, initStoreValue, resetStoreValue } from './util'\n\nexport type Store<T extends StoreValue> = {\n /**\n * The store value.\n */\n readonly value: T,\n /**\n * Freezes the store value.\n * @param value Optional new store value.\n * If supplied, this value will be freezed and used as the store value.\n * You can use this update the store value and freeze part of it.\n * If not supplied,\n * the original value will be freezed and its array property will also be freezed.\n */\n freeze(value?: { [k in keyof T]: Readonly<T[k]> }): void,\n /**\n * Resets the store to its initial value.\n * You should only use this during testing.\n */\n reset(): void,\n}\n\nconst stores: Stores = Object.create(null) as Stores\n\n/**\n * Creates a store of type T.\n * @see https://www.npmjs.com/package/global-store\n */\nexport function createStore<\n T extends StoreValue\n>({ moduleName, key, version, initializer }: StoreOptions<T>): Store<T> {\n const id = { moduleName, key }\n initStoreValue(stores, id, version, initializer)\n\n return {\n get value() { return getStoreValue<T>(stores, id) },\n freeze(value) { return freezeStoreValue(stores, id, value) },\n reset() { return resetStoreValue(stores, id) }\n }\n}\n","import { createStore, Store } from './createStore'\nimport { StoreOptions, StoreValue } from './types'\nimport { StoreCreators } from './typesInternal'\nimport { resolveCreators } from './util'\n\nconst asyncStoreCreators: StoreCreators<Store<any>> = {}\n\n/**\n * Creates a store of type T asynchronously.\n * @see https://github.com/unional/global-store#createAsyncStore\n */\nexport async function createAsyncStore<T extends StoreValue>({ moduleName, key, version, initializer }: StoreOptions<T>): Promise<Store<T>> {\n return new Promise(resolve => {\n const creatorsOfModules = asyncStoreCreators[moduleName] = asyncStoreCreators[moduleName] || Object.create(null)\n const k = key ?? 'default'\n const storeCreators = creatorsOfModules[k] = creatorsOfModules[k] || []\n storeCreators.push({ version, resolve, initializer })\n })\n}\n\n/**\n * Initializes the stores for `createAsyncStore()`.\n * @see https://github.com/unional/global-store#initializeAsyncStore\n */\nexport function initializeAsyncStore(moduleName: string, key?: string) {\n const creatorsOfModules = asyncStoreCreators[moduleName]\n if (!creatorsOfModules) return\n\n const keys = key ? [key] : Object.keys(creatorsOfModules)\n keys.forEach(key => resolveCreators(moduleName, key, creatorsOf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;AAGG;AACa,SAAA,oBAAoB,CAAC,UAAkB,EAAE,GAAY,EAAA;AACnE,IAAA,MAAM,iBAAiB,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAA;AACxD,IAAA,IAAI,CAAC,iBAAiB;QAAE,OAAM;AAE9B,IAAA,MAAM,IAAI,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;IACzD,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,eAAe,CAAC,UAAU,EAAE,GAAG,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,CAAA;AAC5F;;;;"}
|
package/dist/global-store.es5.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var GlobalStore
|
|
1
|
+
var GlobalStore;(()=>{"use strict";var e={629:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.compareVersion=void 0;var n=t(487);r.compareVersion=function(e,r){var t=(0,n.toVersionArray)(e),o=(0,n.toVersionArray)(r);return t[0]!==o[0]?t[0]-o[0]:t[1]!==o[1]?t[1]-o[1]:t[2]-o[2]}},490:function(e,r,t){var n=this&&this.__awaiter||function(e,r,t,n){return new(t||(t=Promise))((function(o,i){function u(e){try{l(n.next(e))}catch(e){i(e)}}function a(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(u,a)}l((n=n.apply(e,r||[])).next())}))},o=this&&this.__generator||function(e,r){var t,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;u;)try{if(t=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,n=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=r.call(e,u)}catch(e){i=[6,e],n=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(r,"__esModule",{value:!0}),r.initializeAsyncStore=r.createAsyncStore=void 0;var i=t(817),u=t(128),a={};r.createAsyncStore=function(e){var r=e.moduleName,t=e.key,i=e.version,u=e.initializer;return n(this,void 0,Promise,(function(){return o(this,(function(e){return[2,new Promise((function(e){var n=a[r]=a[r]||Object.create(null),o=null!=t?t:"default";(n[o]=n[o]||[]).push({version:i,resolve:e,initializer:u})}))]}))}))},r.initializeAsyncStore=function(e,r){var t=a[e];t&&(r?[r]:Object.keys(t)).forEach((function(r){return(0,u.resolveCreators)(e,r,t[r],i.createStore)}))}},817:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.createStore=void 0;var n=t(128),o=Object.create(null);r.createStore=function(e){var r=e.moduleName,t=e.key,i=e.version,u=e.initializer,a={moduleName:r,key:t};return(0,n.initStoreValue)(o,a,i,u),{get value(){return(0,n.getStoreValue)(o,a)},freeze:function(e){return(0,n.freezeStoreValue)(o,a,e)},reset:function(){return(0,n.resetStoreValue)(o,a)}}}},733:function(e,r,t){var n=this&&this.__createBinding||(Object.create?function(e,r,t,n){void 0===n&&(n=t);var o=Object.getOwnPropertyDescriptor(r,t);o&&!("get"in o?!r.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,o)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]}),o=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0,o(t(490),r),o(t(817),r);var i=t(817);Object.defineProperty(r,"default",{enumerable:!0,get:function(){return i.createStore}}),o(t(171),r)},420:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.shouldInvokeInitializer=void 0;var n=t(487);r.shouldInvokeInitializer=function(e,r){var t=e.map(n.toVersionArray),o=(0,n.toVersionArray)(r);return function(e,r){return!e.some((function(e){return e[0]===r[0]}))}(t,o)||function(e,r){return e.filter((function(e){return e[0]===r[0]})).some((function(e){return r[1]>e[1]||r[1]===e[1]&&r[2]>e[2]}))}(t,o)}},487:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.toVersionArray=void 0,r.toVersionArray=function(e){return"number"==typeof e?[0,0,e]:e.split(".").map((function(e){return parseInt(e,10)}))}},171:(e,r)=>{Object.defineProperty(r,"__esModule",{value:!0})},128:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.freezeStoreValue=r.sortByVersion=r.resolveCreators=r.getStore=r.resetStoreValue=r.initStoreValue=r.getStoreValue=void 0;var n=t(629),o=t(420);function i(e,r){var t,n=e[r.moduleName]=e[r.moduleName]||Object.create(null),o=null!==(t=r.key)&&void 0!==t?t:"default";return n[o]=n[o]||{versions:[],value:{},initializers:[]}}function u(e){return e.sort((function(e,r){return(0,n.compareVersion)(e.version,r.version)}))}function a(e,r){var t=e[r];Array.isArray(t)&&(e[r]=Object.freeze(t))}r.getStoreValue=function(e,r){return i(e,r).value},r.initStoreValue=function(e,r,t,n){var u=i(e,r);(0,o.shouldInvokeInitializer)(u.versions,t)&&(u.initializers.push(n),u.value=n(u.value,u.versions),u.versions.push(t))},r.resetStoreValue=function(e,r){var t=i(e,r),n=t.versions;t.versions=[],t.value=t.initializers.reduce((function(e,r,o){return e=r(e,t.versions),t.versions.push(n[o]),e}),{})},r.getStore=i,r.resolveCreators=function(e,r,t,n){u(t).forEach((function(t){var o=t.version,i=t.resolve,u=t.initializer;return i(n({moduleName:e,key:r,version:o,initializer:u}))}))},r.sortByVersion=u,r.freezeStoreValue=function(e,r,t){var n=i(e,r);n.value=t?Object.isFrozen(t)?t:Object.freeze(t):function(e){if(Object.isFrozen(e))throw TypeError("Frozen value cannot be freezed again");return Object.keys(e).forEach((function(r){return a(e,r)})),Object.getOwnPropertySymbols&&Object.getOwnPropertySymbols(e).forEach((function(r){return a(e,r)})),Object.freeze(e)}(n.value)}}},r={},t=function t(n){var o=r[n];if(void 0!==o)return o.exports;var i=r[n]={exports:{}};return e[n].call(i.exports,i,i.exports,t),i.exports}(733);GlobalStore=t})();
|
|
2
2
|
//# sourceMappingURL=global-store.es5.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["webpack://GlobalStore/webpack/bootstrap","webpack://GlobalStore/./src/createStore.ts","webpack://GlobalStore/./src/util.ts","webpack://GlobalStore/./src/toVersionArray.ts","webpack://GlobalStore/./src/index.ts","webpack://GlobalStore/./src/createAsyncStore.ts","webpack://GlobalStore/./src/compareVersion.ts","webpack://GlobalStore/./src/shouldInvokeInitializer.ts"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","stores","moduleName","version","initializer","id","initStoreValue","getStoreValue","freeze","freezeStoreValue","reset","resetStoreValue","getStore","moduleStore","versions","initializers","sortByVersion","storeCreators","sort","a","b","compareVersion","freezeIfIsArray","storeValue","k","Array","isArray","store","shouldInvokeInitializer","push","reduce","createStore","forEach","resolve","isFrozen","TypeError","keys","getOwnPropertySymbols","freezeValue","v","split","map","parseInt","asyncStoreCreators","Promise","creatorsOfModules","resolveCreators","processed","current","v1","toVersionArray","v2","vs","some","noMatchMajor","filter","hasNewVersion"],"mappings":"4BACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASF,GAG/DG,EAAOE,GAAI,EAGJF,EAAOD,QA0Df,OArDAF,EAAoBQ,EAAIF,EAGxBN,EAAoBS,EAAIV,EAGxBC,EAAoBU,EAAI,SAASR,EAASS,EAAMC,GAC3CZ,EAAoBa,EAAEX,EAASS,IAClCG,OAAOC,eAAeb,EAASS,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhEZ,EAAoBkB,EAAI,SAAShB,GACX,oBAAXiB,QAA0BA,OAAOC,aAC1CN,OAAOC,eAAeb,EAASiB,OAAOC,YAAa,CAAEC,MAAO,WAE7DP,OAAOC,eAAeb,EAAS,aAAc,CAAEmB,OAAO,KAQvDrB,EAAoBsB,EAAI,SAASD,EAAOE,GAEvC,GADU,EAAPA,IAAUF,EAAQrB,EAAoBqB,IAC/B,EAAPE,EAAU,OAAOF,EACpB,GAAW,EAAPE,GAA8B,iBAAVF,GAAsBA,GAASA,EAAMG,WAAY,OAAOH,EAChF,IAAII,EAAKX,OAAOY,OAAO,MAGvB,GAFA1B,EAAoBkB,EAAEO,GACtBX,OAAOC,eAAeU,EAAI,UAAW,CAAET,YAAY,EAAMK,MAAOA,IACtD,EAAPE,GAA4B,iBAATF,EAAmB,IAAI,IAAIM,KAAON,EAAOrB,EAAoBU,EAAEe,EAAIE,EAAK,SAASA,GAAO,OAAON,EAAMM,IAAQC,KAAK,KAAMD,IAC9I,OAAOF,GAIRzB,EAAoB6B,EAAI,SAAS1B,GA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AAd,GAAK,OAAApC,EAAQ,GAAKoC,EAAE,IAAOpC,EAAQ,KAAOoC,EAAE,IAAMpC,EAAQ,GAAKoC,EAAE,MATrCiB,CAAcJ,EAAIb,K","file":"global-store.es5.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 3);\n","import { StoreOptions, StoreValue } from './types'\nimport { Stores } from './typesInternal'\nimport { freezeStoreValue, getStoreValue, initStoreValue, resetStoreValue } from './util'\n\nexport type Store<T extends StoreValue> = {\n /**\n * The store value.\n */\n readonly value: T,\n /**\n * Freezes the store value.\n * @param value Optional new store value.\n * If supplied, this value will be freezed and used as the store value.\n * You can use this update the store value and freeze part of it.\n * If not supplied,\n * the original value will be freezed and its array property will also be freezed.\n */\n freeze(value?: { [k in keyof T]: Readonly<T[k]> }): void,\n /**\n * Resets the store to its initial value.\n * You should only use this during testing.\n */\n reset(): void,\n}\n\nconst stores: Stores = {}\n\n/**\n * Creates a store of type T.\n * https://www.npmjs.com/package/global-store\n */\nexport function createStore<\n T extends StoreValue\n>({ moduleName, key, version, initializer }: StoreOptions<T>): Store<T> {\n const id = { moduleName, key }\n initStoreValue(stores, id, version, initializer)\n\n return {\n get value() { return getStoreValue(stores, id) },\n freeze: (value) => freezeStoreValue(stores, id, value),\n reset: () => resetStoreValue(stores, id)\n }\n}\n","import { compareVersion } from './compareVersion'\nimport { shouldInvokeInitializer } from './shouldInvokeInitializer'\nimport { StoreInitializer, StoreValue, StoreVersion } from './types'\nimport { StoreCreator, StoreId, Stores } from './typesInternal'\n\nexport function getStoreValue(stores: Stores, id: StoreId): any {\n return getStore(stores, id).value\n}\n\nexport function initStoreValue<T extends StoreValue>(stores: Stores, id: StoreId, version: StoreVersion, initializer: StoreInitializer<T>) {\n const store = getStore(stores, id)\n if (shouldInvokeInitializer(store.versions, version)) {\n store.initializers.push(initializer)\n store.value = initializer(store.value as T, store.versions)\n store.versions.push(version)\n }\n}\n\nexport function resetStoreValue(stores: Stores, id: StoreId) {\n const store = getStore(stores, id)\n const versions = store.versions\n store.versions = []\n store.value = store.initializers.reduce((value, initializer, i) => {\n value = initializer(value, store.versions)\n store.versions.push(versions[i])\n return value\n }, {})\n}\n\nexport function getStore(stores: Stores, id: StoreId) {\n const moduleStore = stores[id.moduleName] = stores[id.moduleName] || {}\n return moduleStore[id.key as any] = moduleStore[id.key as any] || { versions: [], value: {}, initializers: [] }\n}\n\nexport function resolveCreators<S>(moduleName: string, key: string, storeCreators: Array<StoreCreator<S>>, createStore: any) {\n sortByVersion(storeCreators).forEach(({ version, resolve, initializer }) => resolve(createStore({ moduleName, key, version, initializer })))\n}\n\nexport function sortByVersion<S>(storeCreators: Array<StoreCreator<S>>) {\n return storeCreators.sort((a, b) => compareVersion(a.version, b.version))\n}\n\nexport function freezeStoreValue(stores: Stores, id: StoreId, value?: any) {\n const store = getStore(stores, id)\n store.value = value ?\n Object.isFrozen(value) ? value : Object.freeze(value) :\n freezeValue(store.value)\n}\n\nfunction freezeValue(storeValue: StoreValue) {\n if (Object.isFrozen(storeValue)) throw TypeError('Frozen value cannot be freezed again')\n\n Object.keys(storeValue).forEach(k => freezeIfIsArray(storeValue, k))\n // istanbul ignore next\n if (Object.getOwnPropertySymbols) {\n Object.getOwnPropertySymbols(storeValue).forEach(k => freezeIfIsArray(storeValue, k))\n }\n\n return Object.freeze(storeValue)\n}\n\nfunction freezeIfIsArray(storeValue: StoreValue, k: any) {\n const value = storeValue[k]\n if (Array.isArray(value)) {\n storeValue[k] = Object.freeze(value)\n }\n}\n","import { StoreVersion } from './types'\n\nexport type ParsedVersion = [number, number, number]\n\nexport function toVersionArray(v: StoreVersion): ParsedVersion {\n return typeof v === 'number' ? [0, 0, v] :\n v.split('.').map(v => parseInt(v, 10)) as any\n}\n","export * from './createAsyncStore'\nexport * from './createStore'\nexport { createStore as default } from './createStore'\nexport * from './types'\n\n","import { createStore, Store } from './createStore'\nimport { StoreOptions, StoreValue } from './types'\nimport { StoreCreators } from './typesInternal'\nimport { resolveCreators } from './util'\n\nconst asyncStoreCreators: StoreCreators<Store<any>> = {}\n\n/**\n * Creates a store of type T asychronously.\n * https://github.com/unional/global-store#createAsyncStore\n */\nexport async function createAsyncStore<T extends StoreValue>({ moduleName, key, version, initializer }: StoreOptions<T>): Promise<Store<T>> {\n return new Promise(resolve => {\n const creatorsOfModules = asyncStoreCreators[moduleName] = asyncStoreCreators[moduleName] || {}\n const storeCreators = creatorsOfModules[key as any] = creatorsOfModules[key as any] || []\n storeCreators.push({ version, resolve, initializer })\n })\n}\n\n/**\n * Initializes the stores for `createAsyncStore()`.\n * https://github.com/unional/global-store#initializeAsyncStore\n */\nexport function initializeAsyncStore(moduleName: string, key?: string) {\n const creatorsOfModules = asyncStoreCreators[moduleName]\n if (!creatorsOfModules) return\n\n if (key) {\n const storeCreators = creatorsOfModules[key as any]\n resolveCreators(moduleName, key, storeCreators, createStore)\n }\n else {\n Object.keys(creatorsOfModules).forEach(k => {\n const storeCreators = creatorsOfModules[k]\n resolveCreators(moduleName, k, storeCreators, createStore)\n })\n }\n}\n","import { toVersionArray } from './toVersionArray'\nimport { StoreVersion } from './types'\n\n/**\n * Compare version.\n * Positive when processed > current\n * Negative when processed < current\n */\nexport function compareVersion(processed: StoreVersion, current: StoreVersion) {\n const v1 = toVersionArray(processed)\n const v2 = toVersionArray(current)\n return v1[0] !== v2[0] ? v1[0] - v2[0] :\n v1[1] !== v2[1] ? v1[1] - v2[1] :\n v1[2] - v2[2]\n}\n","import { ParsedVersion, toVersionArray } from './toVersionArray'\nimport { StoreVersion } from './types'\n\nexport function shouldInvokeInitializer(versions: StoreVersion[], version: StoreVersion) {\n const vs = versions.map(toVersionArray)\n const v = toVersionArray(version)\n return noMatchMajor(vs, v) || hasNewVersion(vs, v)\n}\n\nfunction noMatchMajor(versions: ParsedVersion[], version: ParsedVersion) {\n return !versions.some(v => v[0] === version[0])\n}\n\nfunction hasNewVersion(versions: ParsedVersion[], version: ParsedVersion) {\n return versions.filter(v => v[0] === version[0]).some(\n v => version[1] > v[1] || (version[1] === v[1] && version[2] > v[2]))\n}\n"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"global-store.es5.js","mappings":"iIAAA,aAQA,0BAA+BA,EAAyBC,GACtD,IAAMC,GAAK,IAAAC,gBAAeH,GACpBI,GAAK,IAAAD,gBAAeF,GAC1B,OAAOC,EAAG,KAAOE,EAAG,GAAKF,EAAG,GAAKE,EAAG,GAClCF,EAAG,KAAOE,EAAG,GAAKF,EAAG,GAAKE,EAAG,GAAKF,EAAG,GAAKE,EAAG,K,q/CCZjD,aAGA,SAEMC,EAAgD,GAMtD,4BAA6D,G,IAAEC,EAAU,aAAEC,EAAG,MAAEC,EAAO,UAAEC,EAAW,c,qBAAsBC,SAAO,W,2BAC/H,MAAO,CAAP,EAAO,IAAIA,SAAQ,SAAAC,GACjB,IAAMC,EAAoBP,EAAmBC,GAAcD,EAAmBC,IAAeO,OAAOC,OAAO,MACrGC,EAAIR,MAAAA,EAAAA,EAAO,WACKK,EAAkBG,GAAKH,EAAkBG,IAAM,IACvDC,KAAK,CAAER,QAAO,EAAEG,QAAO,EAAEF,YAAW,eAQtD,gCAAqCH,EAAoBC,GACvD,IAAMK,EAAoBP,EAAmBC,GACxCM,IAEQL,EAAM,CAACA,GAAOM,OAAOI,KAAKL,IAClCM,SAAQ,SAAAX,GAAO,WAAAY,iBAAgBb,EAAYC,EAAKK,EAAkBL,GAAM,EAAAa,kB,oFC3B/E,aAuBMC,EAAiBR,OA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AASR,GAAa,MAAMS,UAAU,wCAQjD,OANA9C,OAAOI,KAAKiC,GAAYhC,SAAQ,SAAAH,GAAK,OAAAkC,EAAgBC,EAAYnC,MAE7DF,OAAO+C,uBACT/C,OAAO+C,sBAAsBV,GAAYhC,SAAQ,SAAAH,GAAK,OAAAkC,EAAgBC,EAAYnC,MAG7EF,OAAOa,OAAOwB,GAZnBW,CAAYR,EAAM7B,UC/ClBsC,EAA2B,GCE3BC,EDCJ,SAASC,EAAoBC,GAE5B,IAAIC,EAAeJ,EAAyBG,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaE,QAGrB,IAAIC,EAASP,EAAyBG,GAAY,CAGjDG,QAAS,IAOV,OAHAE,EAAoBL,GAAUM,KAAKF,EAAOD,QAASC,EAAQA,EAAOD,QAASJ,GAGpEK,EAAOD,QClBWJ,CAAoB,K","sources":["webpack://GlobalStore/./ts/compareVersion.ts","webpack://GlobalStore/./ts/createAsyncStore.ts","webpack://GlobalStore/./ts/createStore.ts","webpack://GlobalStore/./ts/index.ts","webpack://GlobalStore/./ts/shouldInvokeInitializer.ts","webpack://GlobalStore/./ts/toVersionArray.ts","webpack://GlobalStore/./ts/util.ts","webpack://GlobalStore/webpack/bootstrap","webpack://GlobalStore/webpack/startup"],"sourcesContent":["import { toVersionArray } from './toVersionArray'\nimport { StoreVersion } from './types'\n\n/**\n * Compare version.\n * Positive when processed > current\n * Negative when processed < current\n */\nexport function compareVersion(processed: StoreVersion, current: StoreVersion) {\n const v1 = toVersionArray(processed)\n const v2 = toVersionArray(current)\n return v1[0] !== v2[0] ? v1[0] - v2[0] :\n v1[1] !== v2[1] ? v1[1] - v2[1] : v1[2] - v2[2]\n}\n","import { createStore, Store } from './createStore'\nimport { StoreOptions, StoreValue } from './types'\nimport { StoreCreators } from './typesInternal'\nimport { resolveCreators } from './util'\n\nconst asyncStoreCreators: StoreCreators<Store<any>> = {}\n\n/**\n * Creates a store of type T asynchronously.\n * @see https://github.com/unional/global-store#createAsyncStore\n */\nexport async function createAsyncStore<T extends StoreValue>({ moduleName, key, version, initializer }: StoreOptions<T>): Promise<Store<T>> {\n return new Promise(resolve => {\n const creatorsOfModules = asyncStoreCreators[moduleName] = asyncStoreCreators[moduleName] || Object.create(null)\n const k = key ?? 'default'\n const storeCreators = creatorsOfModules[k] = creatorsOfModules[k] || []\n storeCreators.push({ version, resolve, initializer })\n })\n}\n\n/**\n * Initializes the stores for `createAsyncStore()`.\n * @see https://github.com/unional/global-store#initializeAsyncStore\n */\nexport function initializeAsyncStore(moduleName: string, key?: string) {\n const creatorsOfModules = asyncStoreCreators[moduleName]\n if (!creatorsOfModules) return\n\n const keys = key ? [key] : Object.keys(creatorsOfModules)\n keys.forEach(key => resolveCreators(moduleName, key, creatorsOfModules[key], createStore))\n}\n","import { StoreOptions, StoreValue } from './types'\nimport { Stores } from './typesInternal'\nimport { freezeStoreValue, getStoreValue, initStoreValue, resetStoreValue } from './util'\n\nexport type Store<T extends StoreValue> = {\n /**\n * The store value.\n */\n readonly value: T,\n /**\n * Freezes the store value.\n * @param value Optional new store value.\n * If supplied, this value will be freezed and used as the store value.\n * You can use this update the store value and freeze part of it.\n * If not supplied,\n * the original value will be freezed and its array property will also be freezed.\n */\n freeze(value?: { [k in keyof T]: Readonly<T[k]> }): void,\n /**\n * Resets the store to its initial value.\n * You should only use this during testing.\n */\n reset(): void,\n}\n\nconst stores: Stores = Object.create(null) as Stores\n\n/**\n * Creates a store of type T.\n * @see https://www.npmjs.com/package/global-store\n */\nexport function createStore<\n T extends StoreValue\n>({ moduleName, key, version, initializer }: StoreOptions<T>): Store<T> {\n const id = { moduleName, key }\n initStoreValue(stores, id, version, initializer)\n\n return {\n get value() { return getStoreValue<T>(stores, id) },\n freeze(value) { return freezeStoreValue(stores, id, value) },\n reset() { return resetStoreValue(stores, id) }\n }\n}\n","export * from './createAsyncStore'\nexport * from './createStore'\nexport { createStore as default } from './createStore'\nexport * from './types'\n\n","import { ParsedVersion, toVersionArray } from './toVersionArray'\nimport { StoreVersion } from './types'\n\nexport function shouldInvokeInitializer(versions: StoreVersion[], version: StoreVersion) {\n const vs = versions.map(toVersionArray)\n const v = toVersionArray(version)\n return noMatchMajor(vs, v) || hasNewVersion(vs, v)\n}\n\nfunction noMatchMajor(versions: ParsedVersion[], version: ParsedVersion) {\n return !versions.some(v => v[0] === version[0])\n}\n\nfunction hasNewVersion(versions: ParsedVersion[], version: ParsedVersion) {\n return versions.filter(v => v[0] === version[0])\n .some(v => version[1] > v[1] || (version[1] === v[1] && version[2] > v[2]))\n}\n","import { StoreVersion } from './types'\n\nexport type ParsedVersion = [number, number, number]\n\nexport function toVersionArray(v: StoreVersion): ParsedVersion {\n return typeof v === 'number' ? [0, 0, v] :\n v.split('.').map(v => parseInt(v, 10)) as ParsedVersion\n}\n","import { compareVersion } from './compareVersion'\nimport { createStore } from './createStore'\nimport { shouldInvokeInitializer } from './shouldInvokeInitializer'\nimport { StoreInitializer, StoreValue, StoreVersion } from './types'\nimport { StoreCreator, StoreId, Stores } from './typesInternal'\n\nexport function getStoreValue<T extends StoreValue>(stores: Stores, id: StoreId): T {\n return getStore(stores, id).value as T\n}\n\nexport function initStoreValue<T extends StoreValue>(stores: Stores, id: StoreId, version: StoreVersion, initializer: StoreInitializer<T>) {\n const store = getStore(stores, id)\n if (shouldInvokeInitializer(store.versions, version)) {\n store.initializers.push(initializer as StoreInitializer<StoreValue>)\n store.value = initializer(store.value as T, store.versions)\n store.versions.push(version)\n }\n}\n\nexport function resetStoreValue(stores: Stores, id: StoreId) {\n const store = getStore(stores, id)\n const versions = store.versions\n store.versions = []\n store.value = store.initializers.reduce<StoreValue>((value, initializer, i) => {\n value = initializer(value, store.versions)\n store.versions.push(versions[i])\n return value\n }, {})\n}\n\nexport function getStore(stores: Stores, id: StoreId) {\n const moduleStore = stores[id.moduleName] = stores[id.moduleName] || Object.create(null)\n const key = id.key ?? 'default'\n return moduleStore[key] = moduleStore[key] || { versions: [], value: {}, initializers: [] }\n}\n\nexport function resolveCreators(moduleName: string, key: string, storeCreators: Array<StoreCreator<any>>, cs: typeof createStore) {\n sortByVersion(storeCreators).forEach(({ version, resolve, initializer }) => resolve(cs({ moduleName, key, version, initializer })))\n}\n\nexport function sortByVersion<S>(storeCreators: Array<StoreCreator<S>>) {\n return storeCreators.sort((a, b) => compareVersion(a.version, b.version))\n}\n\nexport function freezeStoreValue(stores: Stores, id: StoreId, value?: StoreValue) {\n const store = getStore(stores, id)\n store.value = value ?\n Object.isFrozen(value) ? value : Object.freeze(value) :\n freezeValue(store.value)\n}\n\nfunction freezeValue(storeValue: StoreValue) {\n if (Object.isFrozen(storeValue)) throw TypeError('Frozen value cannot be freezed again')\n\n Object.keys(storeValue).forEach(k => freezeIfIsArray(storeValue, k))\n // istanbul ignore next\n if (Object.getOwnPropertySymbols) {\n Object.getOwnPropertySymbols(storeValue).forEach(k => freezeIfIsArray(storeValue, k))\n }\n\n return Object.freeze(storeValue)\n}\n\nfunction freezeIfIsArray(storeValue: StoreValue, k: string | number | symbol) {\n const value = storeValue[k]\n if (Array.isArray(value)) {\n storeValue[k] = Object.freeze(value)\n }\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(733);\n"],"names":["processed","current","v1","toVersionArray","v2","asyncStoreCreators","moduleName","key","version","initializer","Promise","resolve","creatorsOfModules","Object","create","k","push","keys","forEach","resolveCreators","createStore","stores","id","initStoreValue","value","getStoreValue","freeze","freezeStoreValue","reset","resetStoreValue","versions","vs","map","v","some","noMatchMajor","filter","hasNewVersion","split","parseInt","getStore","moduleStore","initializers","sortByVersion","storeCreators","sort","a","b","compareVersion","freezeIfIsArray","storeValue","Array","isArray","store","shouldInvokeInitializer","reduce","i","cs","isFrozen","TypeError","getOwnPropertySymbols","freezeValue","__webpack_module_cache__","__webpack_exports__","__webpack_require__","moduleId","cachedModule","undefined","exports","module","__webpack_modules__","call"],"sourceRoot":""}
|