global-store 1.0.0-beta.21 → 1.0.0-beta.23
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/LICENSE +1 -1
- package/dist/global-store.js +2 -0
- package/dist/global-store.js.map +1 -0
- package/index.js.flow +2 -2
- package/lib/compareVersion.d.ts +2 -1
- package/lib/compareVersion.d.ts.map +1 -0
- package/lib/compareVersion.js +5 -10
- package/lib/compareVersion.js.map +1 -1
- package/lib/createAsyncStore.d.ts +3 -2
- package/lib/createAsyncStore.d.ts.map +1 -0
- package/lib/createAsyncStore.js +16 -60
- package/lib/createAsyncStore.js.map +1 -1
- package/lib/createStore.d.ts +3 -2
- package/lib/createStore.d.ts.map +1 -0
- package/lib/createStore.js +14 -13
- package/lib/createStore.js.map +1 -1
- package/lib/index.d.ts +5 -4
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +4 -22
- package/lib/index.js.map +1 -1
- package/lib/shouldInvokeInitializer.d.ts +2 -1
- package/lib/shouldInvokeInitializer.d.ts.map +1 -0
- package/lib/shouldInvokeInitializer.js +8 -11
- package/lib/shouldInvokeInitializer.js.map +1 -1
- package/lib/toVersionArray.d.ts +3 -2
- package/lib/toVersionArray.d.ts.map +1 -0
- package/lib/toVersionArray.js +2 -7
- package/lib/toVersionArray.js.map +1 -1
- package/lib/types.d.ts +8 -3
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +1 -2
- package/lib/typesInternal.d.ts +5 -4
- package/lib/typesInternal.d.ts.map +1 -0
- package/lib/typesInternal.js +1 -2
- package/lib/util.d.ts +4 -3
- package/lib/util.d.ts.map +1 -0
- package/lib/util.js +24 -40
- package/lib/util.js.map +1 -1
- package/package.json +44 -65
- package/{README.md → readme.md} +18 -20
- package/dist/compareVersion.d.ts +0 -7
- package/dist/createAsyncStore.d.ts +0 -12
- package/dist/createStore.d.ts +0 -28
- package/dist/global-store.es.js +0 -127
- package/dist/global-store.es.js.map +0 -1
- package/dist/global-store.es5.js +0 -2
- package/dist/global-store.es5.js.map +0 -1
- package/dist/global-store.systemjs.js +0 -141
- package/dist/global-store.systemjs.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/shouldInvokeInitializer.d.ts +0 -2
- package/dist/toVersionArray.d.ts +0 -3
- package/dist/types.d.ts +0 -9
- package/dist/util.d.ts +0 -14
- package/libm/compareVersion.d.ts +0 -7
- package/libm/compareVersion.js +0 -13
- package/libm/compareVersion.js.map +0 -1
- package/libm/createAsyncStore.d.ts +0 -12
- package/libm/createAsyncStore.js +0 -27
- package/libm/createAsyncStore.js.map +0 -1
- package/libm/createStore.d.ts +0 -28
- package/libm/createStore.js +0 -16
- package/libm/createStore.js.map +0 -1
- package/libm/index.d.ts +0 -4
- package/libm/index.js +0 -5
- package/libm/index.js.map +0 -1
- package/libm/shouldInvokeInitializer.d.ts +0 -2
- package/libm/shouldInvokeInitializer.js +0 -14
- package/libm/shouldInvokeInitializer.js.map +0 -1
- package/libm/toVersionArray.d.ts +0 -3
- package/libm/toVersionArray.js +0 -5
- package/libm/toVersionArray.js.map +0 -1
- package/libm/types.d.ts +0 -9
- package/libm/types.js +0 -2
- package/libm/types.js.map +0 -1
- package/libm/typesInternal.d.ts +0 -16
- package/libm/typesInternal.js +0 -2
- package/libm/typesInternal.js.map +0 -1
- package/libm/util.d.ts +0 -14
- package/libm/util.js +0 -57
- package/libm/util.js.map +0 -1
- package/ts/compareVersion.spec.ts +0 -9
- package/ts/compareVersion.ts +0 -14
- package/ts/createAsyncStore.spec.ts +0 -142
- package/ts/createAsyncStore.ts +0 -31
- package/ts/createStore.spec.ts +0 -217
- package/ts/createStore.ts +0 -43
- package/ts/index.spec.ts +0 -7
- package/ts/index.ts +0 -5
- package/ts/shouldInvokeInitializer.spec.ts +0 -41
- package/ts/shouldInvokeInitializer.ts +0 -17
- package/ts/toVersionArray.ts +0 -8
- package/ts/types.ts +0 -12
- package/ts/typesInternal.ts +0 -21
- package/ts/util.ts +0 -69
package/package.json
CHANGED
|
@@ -1,92 +1,71 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "global-store",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.23",
|
|
4
4
|
"description": "A library provides version stable stores for libraries.",
|
|
5
|
-
"homepage": "https://github.com/
|
|
5
|
+
"homepage": "https://github.com/stable-packages/store/tree/main/packages/global-store",
|
|
6
6
|
"bugs": {
|
|
7
|
-
"url": "https://github.com/
|
|
7
|
+
"url": "https://github.com/stable-packages/store/issues"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git://github.com/
|
|
11
|
+
"url": "git+https://github.com/stable-packages/store.git",
|
|
12
|
+
"directory": "packages/global-store"
|
|
12
13
|
},
|
|
13
14
|
"license": "MIT",
|
|
14
15
|
"author": {
|
|
15
16
|
"name": "Homa Wong",
|
|
16
17
|
"email": "homawong@gmail.com"
|
|
17
18
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"types": "
|
|
19
|
+
"sideEffects": true,
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": "./lib/index.js",
|
|
22
|
+
"types": "./lib/index.d.ts",
|
|
22
23
|
"files": [
|
|
23
24
|
"dist",
|
|
24
25
|
"lib",
|
|
25
|
-
"libm",
|
|
26
26
|
"index.js.flow",
|
|
27
|
-
"
|
|
27
|
+
"!**/*.spec.*"
|
|
28
28
|
],
|
|
29
|
-
"scripts": {
|
|
30
|
-
"build": "run-p build:es5 build:esnext bundle",
|
|
31
|
-
"build:es5": "tsc -p tsconfig.es5.json",
|
|
32
|
-
"build:esnext": "tsc -p tsconfig.esnext.json",
|
|
33
|
-
"bundle": "run-p bundle:webpack bundle:rollup",
|
|
34
|
-
"bundle:webpack": "webpack",
|
|
35
|
-
"bundle:rollup": "rollup -c rollup.config.mjs",
|
|
36
|
-
"clean": "rimraf dist lib libm",
|
|
37
|
-
"coverage": "jest --coverage",
|
|
38
|
-
"cs": "changeset",
|
|
39
|
-
"depcheck": "depcheck",
|
|
40
|
-
"lint": "eslint --ext=js,ts .",
|
|
41
|
-
"_postinstall": "husky install",
|
|
42
|
-
"prepack": "pinst --disable",
|
|
43
|
-
"postpack": "pinst --enable",
|
|
44
|
-
"size": "size-limit",
|
|
45
|
-
"test": "jest",
|
|
46
|
-
"test:watch": "jest --watch",
|
|
47
|
-
"verify": "npm-run-all clean -p build:es5 build:esnext -p size bundle lint depcheck coverage",
|
|
48
|
-
"watch": "yarn test:watch"
|
|
49
|
-
},
|
|
50
29
|
"devDependencies": {
|
|
51
|
-
"@babel/core": "^7.
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"
|
|
58
|
-
"@types/jest": "^27.4.0",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^5.23.0",
|
|
60
|
-
"assertron": "^9.0.0",
|
|
30
|
+
"@babel/core": "^7.18.10",
|
|
31
|
+
"@repobuddy/jest": "^4.0.0",
|
|
32
|
+
"@repobuddy/typescript": "^2.0.0",
|
|
33
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
34
|
+
"@size-limit/preset-small-lib": "^8.0.1",
|
|
35
|
+
"@types/jest": "^29.5.12",
|
|
36
|
+
"assertron": "^11.6.0",
|
|
61
37
|
"depcheck": "^1.4.3",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"eslint-plugin-harmony": "^7.0.2",
|
|
65
|
-
"husky": "^8.0.1",
|
|
66
|
-
"jest": "^28.0.0",
|
|
67
|
-
"jest-junit": "^13.0.0",
|
|
68
|
-
"jest-validate": "^28.0.0",
|
|
38
|
+
"jest": "^29.7.0",
|
|
39
|
+
"jest-junit": "^16.0.0",
|
|
69
40
|
"jest-watch-suspend": "^1.1.2",
|
|
70
|
-
"jest-watch-toggle-config": "^2.0
|
|
71
|
-
"jest-watch-typeahead": "^
|
|
41
|
+
"jest-watch-toggle-config-2": "^2.1.0",
|
|
42
|
+
"jest-watch-typeahead": "^2.2.2",
|
|
72
43
|
"npm-run-all": "^4.1.5",
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"ts-loader": "^9.2.6",
|
|
81
|
-
"type-plus": "^4.0.0",
|
|
82
|
-
"typescript": "^4.5.4",
|
|
83
|
-
"webpack": "^5.64.4",
|
|
84
|
-
"webpack-cli": "^4.9.1"
|
|
44
|
+
"rimraf": "^5.0.0",
|
|
45
|
+
"rollup": "^2.78.0",
|
|
46
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
47
|
+
"size-limit": "^8.0.1",
|
|
48
|
+
"ts-jest": "^29.1.2",
|
|
49
|
+
"tslib": "^2.4.0",
|
|
50
|
+
"type-plus": "8.0.0-beta.10"
|
|
85
51
|
},
|
|
86
52
|
"size-limit": [
|
|
87
53
|
{
|
|
88
|
-
"
|
|
54
|
+
"path": "./lib/index.js",
|
|
55
|
+
"limit": "2 KB"
|
|
89
56
|
}
|
|
90
57
|
],
|
|
91
|
-
"
|
|
92
|
-
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "run-p build:ts bundle",
|
|
60
|
+
"build:ts": "tsc",
|
|
61
|
+
"bundle": "rollup -c rollup.config.mjs",
|
|
62
|
+
"clean": "rimraf cjs coverage dist esm tslib lib libm --glob *.tsbuildinfo",
|
|
63
|
+
"coverage": "jest --coverage",
|
|
64
|
+
"depcheck": "depcheck",
|
|
65
|
+
"size": "size-limit",
|
|
66
|
+
"test": "jest",
|
|
67
|
+
"test:watch": "jest --watch",
|
|
68
|
+
"verify": "npm-run-all clean -p build lint depcheck coverage -p size",
|
|
69
|
+
"w": "pnpm test:watch"
|
|
70
|
+
}
|
|
71
|
+
}
|
package/{README.md → readme.md}
RENAMED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[![NPM version][npm-image]][npm-url]
|
|
4
4
|
[![NPM downloads][downloads-image]][downloads-url]
|
|
5
|
-
![badge-size-
|
|
5
|
+
![badge-size-es6-url]
|
|
6
6
|
|
|
7
7
|
[![GitHub NodeJS][github-nodejs]][github-action-url]
|
|
8
8
|
[![Codecov][codecov-image]][codecov-url]
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
Once this library reaches `1.0`, it will forever be backward compatible.
|
|
15
15
|
Meaning there will never be a breaking change or `2.0` version of this library.
|
|
16
16
|
|
|
17
|
-
PLEASE NOTE: This document describes the new `1.0.0-beta` version (finally!!
|
|
17
|
+
PLEASE NOTE: This document describes the new `1.0.0-beta` version (finally!! 🎉).
|
|
18
18
|
|
|
19
19
|
For the current stable version, please check out [here](https://github.com/unional/global-store/blob/v0.8.2/README.md).
|
|
20
20
|
|
|
@@ -79,7 +79,7 @@ Type: `<T>(options: StoreOptions<T>) => Store<T>`
|
|
|
79
79
|
|
|
80
80
|
Creates a store of type `T`.
|
|
81
81
|
|
|
82
|
-
`T` is inferred by [`initializer`](#
|
|
82
|
+
`T` is inferred by [`initializer`](#storeoptionsinitializer).
|
|
83
83
|
|
|
84
84
|
```ts
|
|
85
85
|
import { createStore } from 'global-store'
|
|
@@ -137,9 +137,9 @@ Type: `StoreVersion = string | number`
|
|
|
137
137
|
|
|
138
138
|
The version of the store.
|
|
139
139
|
|
|
140
|
-
This is used during initialization to determine should the [`StoreOptions#initializer`](#
|
|
140
|
+
This is used during initialization to determine should the [`StoreOptions#initializer`](#storeoptionsinitializer) be called (and in what order for [`createAsyncStore()`](#createasyncstore)).
|
|
141
141
|
|
|
142
|
-
It will be added to the `processedVersions` argument of the [`StoreOptions#initializer()`](#
|
|
142
|
+
It will be added to the `processedVersions` argument of the [`StoreOptions#initializer()`](#storeoptionsinitializer) after it is being called.
|
|
143
143
|
|
|
144
144
|
When specified as a string (recommended),
|
|
145
145
|
it must be in this format: `major.minor.patch`.
|
|
@@ -154,17 +154,17 @@ Type: `<T extends StoreValue>(current: StoreValue, processedVersions: StoreVersi
|
|
|
154
154
|
The function to initialize the store.
|
|
155
155
|
|
|
156
156
|
Since there may be multiple copies of your library loaded,
|
|
157
|
-
multiple calls to the store creation function (e.g. [`createStore()`](#
|
|
157
|
+
multiple calls to the store creation function (e.g. [`createStore()`](#createstore)) may occur.
|
|
158
158
|
For the first call, the `current` argument will be an empty object.
|
|
159
159
|
For subsequence calls, it will be the value returned by the last call.
|
|
160
160
|
|
|
161
161
|
The `processedVersions` contains all the versions the have been processed so far.
|
|
162
162
|
You can use it to help determine what do you need to do.
|
|
163
163
|
|
|
164
|
-
For [`createAsyncStore`](#
|
|
164
|
+
For [`createAsyncStore`](#createasyncstore),
|
|
165
165
|
the `initializer` function will be called in the order of `version`.
|
|
166
166
|
|
|
167
|
-
For [`createStore`](#
|
|
167
|
+
For [`createStore`](#createstore),
|
|
168
168
|
since there is no way to control the load order,
|
|
169
169
|
they can be called by a newer version of your library before an older version.
|
|
170
170
|
This means your `initializer` needs to be future-proof.
|
|
@@ -204,17 +204,17 @@ This is mostly used in tests so that the tests would not interfere with each oth
|
|
|
204
204
|
|
|
205
205
|
### createAsyncStore()
|
|
206
206
|
|
|
207
|
-
A `async` variant of [`createStore()`](#
|
|
207
|
+
A `async` variant of [`createStore()`](#createstore).
|
|
208
208
|
It will return a promise,
|
|
209
|
-
which will resolve when the [`initializeAsyncStore()`](#
|
|
209
|
+
which will resolve when the [`initializeAsyncStore()`](#initializeasyncstore) is called.
|
|
210
210
|
|
|
211
|
-
One benefit of using this over [`createStore()`](#
|
|
211
|
+
One benefit of using this over [`createStore()`](#createstore) is that the initializers will be called in the order of `version`.
|
|
212
212
|
|
|
213
213
|
This makes initialization much easier to handle.
|
|
214
214
|
|
|
215
215
|
### initializeAsyncStore()
|
|
216
216
|
|
|
217
|
-
Calling [`initializeAsyncStore()`](#
|
|
217
|
+
Calling [`initializeAsyncStore()`](#initializeasyncstore) will start the initialization process of [`createAsyncStore()`](#createasyncstore).
|
|
218
218
|
|
|
219
219
|
It takes two arguments:
|
|
220
220
|
|
|
@@ -231,17 +231,15 @@ If not, there will be multiple copies of [global-store] loaded and will complete
|
|
|
231
231
|
Except the consuming application, which will declare [global-store] as a regular dependency,
|
|
232
232
|
all libraries should declare [global-store] as a peer dependency.
|
|
233
233
|
|
|
234
|
-
[badge-size-
|
|
235
|
-
[codecov-image]: https://codecov.io/gh/
|
|
236
|
-
[codecov-url]: https://codecov.io/gh/
|
|
234
|
+
[badge-size-es6-url]: https://img.shields.io/bundlephobia/min/global-store
|
|
235
|
+
[codecov-image]: https://codecov.io/gh/stable-packages/store/branch/main/graph/badge.svg
|
|
236
|
+
[codecov-url]: https://app.codecov.io/gh/stable-packages/store/tree/main/packages%2Fglobal-store
|
|
237
237
|
[downloads-image]: https://img.shields.io/npm/dm/global-store.svg?style=flat
|
|
238
238
|
[downloads-url]: https://npmjs.org/package/global-store
|
|
239
|
-
[github-nodejs]: https://github.com/
|
|
240
|
-
[github-action-url]: https://github.com/
|
|
241
|
-
[global-store]: https://github.com/
|
|
239
|
+
[github-nodejs]: https://github.com/stable-packages/store/workflows/release/badge.svg
|
|
240
|
+
[github-action-url]: https://github.com/stable-packages/store/actions
|
|
241
|
+
[global-store]: https://github.com/stable-packages/store/tree/main/packages/global-store
|
|
242
242
|
[npm-image]: https://img.shields.io/npm/v/global-store.svg?style=flat
|
|
243
243
|
[npm-url]: https://npmjs.org/package/global-store
|
|
244
|
-
[downloads-image]: https://img.shields.io/npm/dm/global-store.svg?style=flat
|
|
245
|
-
[downloads-url]: https://npmjs.org/package/global-store
|
|
246
244
|
[vscode-image]: https://img.shields.io/badge/vscode-ready-green.svg
|
|
247
245
|
[vscode-url]: https://code.visualstudio.com/
|
package/dist/compareVersion.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Store } from './createStore';
|
|
2
|
-
import { StoreOptions, StoreValue } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a store of type T asynchronously.
|
|
5
|
-
* @see https://github.com/unional/global-store#createAsyncStore
|
|
6
|
-
*/
|
|
7
|
-
export declare function createAsyncStore<T extends StoreValue>({ moduleName, key, version, initializer }: StoreOptions<T>): Promise<Store<T>>;
|
|
8
|
-
/**
|
|
9
|
-
* Initializes the stores for `createAsyncStore()`.
|
|
10
|
-
* @see https://github.com/unional/global-store#initializeAsyncStore
|
|
11
|
-
*/
|
|
12
|
-
export declare function initializeAsyncStore(moduleName: string, key?: string): void;
|
package/dist/createStore.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { StoreOptions, StoreValue } from './types';
|
|
2
|
-
export declare type Store<T extends StoreValue> = {
|
|
3
|
-
/**
|
|
4
|
-
* The store value.
|
|
5
|
-
*/
|
|
6
|
-
readonly value: T;
|
|
7
|
-
/**
|
|
8
|
-
* Freezes the store value.
|
|
9
|
-
* @param value Optional new store value.
|
|
10
|
-
* If supplied, this value will be freezed and used as the store value.
|
|
11
|
-
* You can use this update the store value and freeze part of it.
|
|
12
|
-
* If not supplied,
|
|
13
|
-
* the original value will be freezed and its array property will also be freezed.
|
|
14
|
-
*/
|
|
15
|
-
freeze(value?: {
|
|
16
|
-
[k in keyof T]: Readonly<T[k]>;
|
|
17
|
-
}): void;
|
|
18
|
-
/**
|
|
19
|
-
* Resets the store to its initial value.
|
|
20
|
-
* You should only use this during testing.
|
|
21
|
-
*/
|
|
22
|
-
reset(): void;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Creates a store of type T.
|
|
26
|
-
* @see https://www.npmjs.com/package/global-store
|
|
27
|
-
*/
|
|
28
|
-
export declare function createStore<T extends StoreValue>({ moduleName, key, version, initializer }: StoreOptions<T>): Store<T>;
|
package/dist/global-store.es.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
function toVersionArray(v) {
|
|
2
|
-
return typeof v === 'number' ? [0, 0, v] :
|
|
3
|
-
v.split('.').map(v => parseInt(v, 10));
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Compare version.
|
|
8
|
-
* Positive when processed > current
|
|
9
|
-
* Negative when processed < current
|
|
10
|
-
*/
|
|
11
|
-
function compareVersion(processed, current) {
|
|
12
|
-
const v1 = toVersionArray(processed);
|
|
13
|
-
const v2 = toVersionArray(current);
|
|
14
|
-
return v1[0] !== v2[0] ? v1[0] - v2[0] :
|
|
15
|
-
v1[1] !== v2[1] ? v1[1] - v2[1] : v1[2] - v2[2];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function shouldInvokeInitializer(versions, version) {
|
|
19
|
-
const vs = versions.map(toVersionArray);
|
|
20
|
-
const v = toVersionArray(version);
|
|
21
|
-
return noMatchMajor(vs, v) || hasNewVersion(vs, v);
|
|
22
|
-
}
|
|
23
|
-
function noMatchMajor(versions, version) {
|
|
24
|
-
return !versions.some(v => v[0] === version[0]);
|
|
25
|
-
}
|
|
26
|
-
function hasNewVersion(versions, version) {
|
|
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
|
-
}
|
|
30
|
-
|
|
31
|
-
function getStoreValue(stores, id) {
|
|
32
|
-
return getStore(stores, id).value;
|
|
33
|
-
}
|
|
34
|
-
function initStoreValue(stores, id, version, initializer) {
|
|
35
|
-
const store = getStore(stores, id);
|
|
36
|
-
if (shouldInvokeInitializer(store.versions, version)) {
|
|
37
|
-
store.initializers.push(initializer);
|
|
38
|
-
store.value = initializer(store.value, store.versions);
|
|
39
|
-
store.versions.push(version);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function resetStoreValue(stores, id) {
|
|
43
|
-
const store = getStore(stores, id);
|
|
44
|
-
const versions = store.versions;
|
|
45
|
-
store.versions = [];
|
|
46
|
-
store.value = store.initializers.reduce((value, initializer, i) => {
|
|
47
|
-
value = initializer(value, store.versions);
|
|
48
|
-
store.versions.push(versions[i]);
|
|
49
|
-
return value;
|
|
50
|
-
}, {});
|
|
51
|
-
}
|
|
52
|
-
function getStore(stores, id) {
|
|
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: [] };
|
|
56
|
-
}
|
|
57
|
-
function resolveCreators(moduleName, key, storeCreators, cs) {
|
|
58
|
-
sortByVersion(storeCreators).forEach(({ version, resolve, initializer }) => resolve(cs({ moduleName, key, version, initializer })));
|
|
59
|
-
}
|
|
60
|
-
function sortByVersion(storeCreators) {
|
|
61
|
-
return storeCreators.sort((a, b) => compareVersion(a.version, b.version));
|
|
62
|
-
}
|
|
63
|
-
function freezeStoreValue(stores, id, value) {
|
|
64
|
-
const store = getStore(stores, id);
|
|
65
|
-
store.value = value ?
|
|
66
|
-
Object.isFrozen(value) ? value : Object.freeze(value) :
|
|
67
|
-
freezeValue(store.value);
|
|
68
|
-
}
|
|
69
|
-
function freezeValue(storeValue) {
|
|
70
|
-
if (Object.isFrozen(storeValue))
|
|
71
|
-
throw TypeError('Frozen value cannot be freezed again');
|
|
72
|
-
Object.keys(storeValue).forEach(k => freezeIfIsArray(storeValue, k));
|
|
73
|
-
// istanbul ignore next
|
|
74
|
-
if (Object.getOwnPropertySymbols) {
|
|
75
|
-
Object.getOwnPropertySymbols(storeValue).forEach(k => freezeIfIsArray(storeValue, k));
|
|
76
|
-
}
|
|
77
|
-
return Object.freeze(storeValue);
|
|
78
|
-
}
|
|
79
|
-
function freezeIfIsArray(storeValue, k) {
|
|
80
|
-
const value = storeValue[k];
|
|
81
|
-
if (Array.isArray(value)) {
|
|
82
|
-
storeValue[k] = Object.freeze(value);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const stores = Object.create(null);
|
|
87
|
-
/**
|
|
88
|
-
* Creates a store of type T.
|
|
89
|
-
* @see https://www.npmjs.com/package/global-store
|
|
90
|
-
*/
|
|
91
|
-
function createStore({ moduleName, key, version, initializer }) {
|
|
92
|
-
const id = { moduleName, key };
|
|
93
|
-
initStoreValue(stores, id, version, initializer);
|
|
94
|
-
return {
|
|
95
|
-
get value() { return getStoreValue(stores, id); },
|
|
96
|
-
freeze(value) { return freezeStoreValue(stores, id, value); },
|
|
97
|
-
reset() { return resetStoreValue(stores, id); }
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const asyncStoreCreators = Object.create(null);
|
|
102
|
-
/**
|
|
103
|
-
* Creates a store of type T asynchronously.
|
|
104
|
-
* @see https://github.com/unional/global-store#createAsyncStore
|
|
105
|
-
*/
|
|
106
|
-
async function createAsyncStore({ moduleName, key, version, initializer }) {
|
|
107
|
-
return new Promise(resolve => {
|
|
108
|
-
const creatorsOfModules = asyncStoreCreators[moduleName] = asyncStoreCreators[moduleName] || Object.create(null);
|
|
109
|
-
const k = key ?? 'default';
|
|
110
|
-
const storeCreators = creatorsOfModules[k] = creatorsOfModules[k] || [];
|
|
111
|
-
storeCreators.push({ version, resolve, initializer });
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Initializes the stores for `createAsyncStore()`.
|
|
116
|
-
* @see https://github.com/unional/global-store#initializeAsyncStore
|
|
117
|
-
*/
|
|
118
|
-
function initializeAsyncStore(moduleName, key) {
|
|
119
|
-
const creatorsOfModules = asyncStoreCreators[moduleName];
|
|
120
|
-
if (!creatorsOfModules)
|
|
121
|
-
return;
|
|
122
|
-
const keys = key ? [key] : Object.keys(creatorsOfModules);
|
|
123
|
-
keys.forEach(key => resolveCreators(moduleName, key, creatorsOfModules[key], createStore));
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export { createAsyncStore, createStore, createStore as default, initializeAsyncStore };
|
|
127
|
-
//# sourceMappingURL=global-store.es.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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 = 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 = Object.create(null) as 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"],"names":[],"mappings":"AAIM,SAAU,cAAc,CAAC,CAAe,EAAA;AAC5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AE,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
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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=Object.create(null);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
|
-
//# sourceMappingURL=global-store.es5.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAqBC,OAAOC,OAAO,MAMzC,4BAA6D,G,IAAEC,EAAU,aAAEC,EAAG,MAAEC,EAAO,UAAEC,EAAW,c,qBAAsBC,SAAO,W,2BAC/H,MAAO,CAAP,EAAO,IAAIA,SAAQ,SAAAC,GACjB,IAAMC,EAAoBT,EAAmBG,GAAcH,EAAmBG,IAAeF,OAAOC,OAAO,MACrGQ,EAAIN,MAAAA,EAAAA,EAAO,WACKK,EAAkBC,GAAKD,EAAkBC,IAAM,IACvDC,KAAK,CAAEN,QAAO,EAAEG,QAAO,EAAEF,YAAW,eAQtD,gCAAqCH,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AAW,SAGhI,kBAIA,4BAAiCU,EAAgBC,EAAaE,GAC5D,IAAM6B,EAAQb,EAASnB,EAAQC,GAC/B+B,EAAM7B,MAAQA,EACZlB,OAAOoD,SAASlC,GAASA,EAAQlB,OAAOoB,OAAOF,GAInD,SAAqB0B,GACnB,GAAI5C,OAAOoD,SAASR,GAAa,MAAMS,UAAU,wCAQjD,OANArD,OAAOW,KAAKiC,GAAYhC,SAAQ,SAAAH,GAAK,OAAAkC,EAAgBC,EAAYnC,MAE7DT,OAAOsD,uBACTtD,OAAOsD,sBAAsBV,GAAYhC,SAAQ,SAAAH,GAAK,OAAAkC,EAAgBC,EAAYnC,MAG7ET,OAAOoB,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 = Object.create(null) as 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 = 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","Object","create","moduleName","key","version","initializer","Promise","resolve","creatorsOfModules","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":""}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
System.register([], (function (exports) {
|
|
2
|
-
'use strict';
|
|
3
|
-
return {
|
|
4
|
-
execute: (function () {
|
|
5
|
-
|
|
6
|
-
exports({
|
|
7
|
-
createAsyncStore: createAsyncStore,
|
|
8
|
-
createStore: createStore,
|
|
9
|
-
default: createStore,
|
|
10
|
-
initializeAsyncStore: initializeAsyncStore
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
function toVersionArray(v) {
|
|
14
|
-
return typeof v === 'number' ? [0, 0, v] :
|
|
15
|
-
v.split('.').map(v => parseInt(v, 10));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Compare version.
|
|
20
|
-
* Positive when processed > current
|
|
21
|
-
* Negative when processed < current
|
|
22
|
-
*/
|
|
23
|
-
function compareVersion(processed, current) {
|
|
24
|
-
const v1 = toVersionArray(processed);
|
|
25
|
-
const v2 = toVersionArray(current);
|
|
26
|
-
return v1[0] !== v2[0] ? v1[0] - v2[0] :
|
|
27
|
-
v1[1] !== v2[1] ? v1[1] - v2[1] : v1[2] - v2[2];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function shouldInvokeInitializer(versions, version) {
|
|
31
|
-
const vs = versions.map(toVersionArray);
|
|
32
|
-
const v = toVersionArray(version);
|
|
33
|
-
return noMatchMajor(vs, v) || hasNewVersion(vs, v);
|
|
34
|
-
}
|
|
35
|
-
function noMatchMajor(versions, version) {
|
|
36
|
-
return !versions.some(v => v[0] === version[0]);
|
|
37
|
-
}
|
|
38
|
-
function hasNewVersion(versions, version) {
|
|
39
|
-
return versions.filter(v => v[0] === version[0])
|
|
40
|
-
.some(v => version[1] > v[1] || (version[1] === v[1] && version[2] > v[2]));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function getStoreValue(stores, id) {
|
|
44
|
-
return getStore(stores, id).value;
|
|
45
|
-
}
|
|
46
|
-
function initStoreValue(stores, id, version, initializer) {
|
|
47
|
-
const store = getStore(stores, id);
|
|
48
|
-
if (shouldInvokeInitializer(store.versions, version)) {
|
|
49
|
-
store.initializers.push(initializer);
|
|
50
|
-
store.value = initializer(store.value, store.versions);
|
|
51
|
-
store.versions.push(version);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function resetStoreValue(stores, id) {
|
|
55
|
-
const store = getStore(stores, id);
|
|
56
|
-
const versions = store.versions;
|
|
57
|
-
store.versions = [];
|
|
58
|
-
store.value = store.initializers.reduce((value, initializer, i) => {
|
|
59
|
-
value = initializer(value, store.versions);
|
|
60
|
-
store.versions.push(versions[i]);
|
|
61
|
-
return value;
|
|
62
|
-
}, {});
|
|
63
|
-
}
|
|
64
|
-
function getStore(stores, id) {
|
|
65
|
-
const moduleStore = stores[id.moduleName] = stores[id.moduleName] || Object.create(null);
|
|
66
|
-
const key = id.key ?? 'default';
|
|
67
|
-
return moduleStore[key] = moduleStore[key] || { versions: [], value: {}, initializers: [] };
|
|
68
|
-
}
|
|
69
|
-
function resolveCreators(moduleName, key, storeCreators, cs) {
|
|
70
|
-
sortByVersion(storeCreators).forEach(({ version, resolve, initializer }) => resolve(cs({ moduleName, key, version, initializer })));
|
|
71
|
-
}
|
|
72
|
-
function sortByVersion(storeCreators) {
|
|
73
|
-
return storeCreators.sort((a, b) => compareVersion(a.version, b.version));
|
|
74
|
-
}
|
|
75
|
-
function freezeStoreValue(stores, id, value) {
|
|
76
|
-
const store = getStore(stores, id);
|
|
77
|
-
store.value = value ?
|
|
78
|
-
Object.isFrozen(value) ? value : Object.freeze(value) :
|
|
79
|
-
freezeValue(store.value);
|
|
80
|
-
}
|
|
81
|
-
function freezeValue(storeValue) {
|
|
82
|
-
if (Object.isFrozen(storeValue))
|
|
83
|
-
throw TypeError('Frozen value cannot be freezed again');
|
|
84
|
-
Object.keys(storeValue).forEach(k => freezeIfIsArray(storeValue, k));
|
|
85
|
-
// istanbul ignore next
|
|
86
|
-
if (Object.getOwnPropertySymbols) {
|
|
87
|
-
Object.getOwnPropertySymbols(storeValue).forEach(k => freezeIfIsArray(storeValue, k));
|
|
88
|
-
}
|
|
89
|
-
return Object.freeze(storeValue);
|
|
90
|
-
}
|
|
91
|
-
function freezeIfIsArray(storeValue, k) {
|
|
92
|
-
const value = storeValue[k];
|
|
93
|
-
if (Array.isArray(value)) {
|
|
94
|
-
storeValue[k] = Object.freeze(value);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const stores = Object.create(null);
|
|
99
|
-
/**
|
|
100
|
-
* Creates a store of type T.
|
|
101
|
-
* @see https://www.npmjs.com/package/global-store
|
|
102
|
-
*/
|
|
103
|
-
function createStore({ moduleName, key, version, initializer }) {
|
|
104
|
-
const id = { moduleName, key };
|
|
105
|
-
initStoreValue(stores, id, version, initializer);
|
|
106
|
-
return {
|
|
107
|
-
get value() { return getStoreValue(stores, id); },
|
|
108
|
-
freeze(value) { return freezeStoreValue(stores, id, value); },
|
|
109
|
-
reset() { return resetStoreValue(stores, id); }
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const asyncStoreCreators = Object.create(null);
|
|
114
|
-
/**
|
|
115
|
-
* Creates a store of type T asynchronously.
|
|
116
|
-
* @see https://github.com/unional/global-store#createAsyncStore
|
|
117
|
-
*/
|
|
118
|
-
async function createAsyncStore({ moduleName, key, version, initializer }) {
|
|
119
|
-
return new Promise(resolve => {
|
|
120
|
-
const creatorsOfModules = asyncStoreCreators[moduleName] = asyncStoreCreators[moduleName] || Object.create(null);
|
|
121
|
-
const k = key ?? 'default';
|
|
122
|
-
const storeCreators = creatorsOfModules[k] = creatorsOfModules[k] || [];
|
|
123
|
-
storeCreators.push({ version, resolve, initializer });
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Initializes the stores for `createAsyncStore()`.
|
|
128
|
-
* @see https://github.com/unional/global-store#initializeAsyncStore
|
|
129
|
-
*/
|
|
130
|
-
function initializeAsyncStore(moduleName, key) {
|
|
131
|
-
const creatorsOfModules = asyncStoreCreators[moduleName];
|
|
132
|
-
if (!creatorsOfModules)
|
|
133
|
-
return;
|
|
134
|
-
const keys = key ? [key] : Object.keys(creatorsOfModules);
|
|
135
|
-
keys.forEach(key => resolveCreators(moduleName, key, creatorsOfModules[key], createStore));
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
})
|
|
139
|
-
};
|
|
140
|
-
}));
|
|
141
|
-
//# sourceMappingURL=global-store.systemjs.js.map
|