@stencil/store 2.2.0 → 2.2.1-dev.1763340412.50ef6ed
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/dist/index.cjs +84 -13
- package/dist/index.js +65 -13
- package/package.json +14 -13
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var StencilCore = require('@stencil/core');
|
|
4
|
+
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
6
|
+
var n = Object.create(null);
|
|
7
|
+
if (e) {
|
|
8
|
+
Object.keys(e).forEach(function (k) {
|
|
9
|
+
if (k !== 'default') {
|
|
10
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return e[k]; }
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
n.default = e;
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var StencilCore__namespace = /*#__PURE__*/_interopNamespaceDefault(StencilCore);
|
|
4
23
|
|
|
5
24
|
const appendToMap = (map, propName, value) => {
|
|
6
25
|
const items = map.get(propName);
|
|
@@ -39,17 +58,22 @@ const cleanupElements = debounce((map) => {
|
|
|
39
58
|
map.set(key, map.get(key).filter(isConnected));
|
|
40
59
|
}
|
|
41
60
|
}, 2_000);
|
|
61
|
+
const core = StencilCore__namespace;
|
|
62
|
+
const forceUpdate = core.forceUpdate;
|
|
63
|
+
const getRenderingRef = core.getRenderingRef;
|
|
42
64
|
const stencilSubscription = () => {
|
|
43
|
-
if (typeof
|
|
65
|
+
if (typeof getRenderingRef !== 'function' || typeof forceUpdate !== 'function') {
|
|
44
66
|
// If we are not in a stencil project, we do nothing.
|
|
45
67
|
// This function is not really exported by @stencil/core.
|
|
46
68
|
return {};
|
|
47
69
|
}
|
|
70
|
+
const ensureForceUpdate = forceUpdate;
|
|
71
|
+
const ensureGetRenderingRef = getRenderingRef;
|
|
48
72
|
const elmsToUpdate = new Map();
|
|
49
73
|
return {
|
|
50
74
|
dispose: () => elmsToUpdate.clear(),
|
|
51
75
|
get: (propName) => {
|
|
52
|
-
const elm =
|
|
76
|
+
const elm = ensureGetRenderingRef();
|
|
53
77
|
if (elm) {
|
|
54
78
|
appendToMap(elmsToUpdate, propName, elm);
|
|
55
79
|
}
|
|
@@ -57,12 +81,12 @@ const stencilSubscription = () => {
|
|
|
57
81
|
set: (propName) => {
|
|
58
82
|
const elements = elmsToUpdate.get(propName);
|
|
59
83
|
if (elements) {
|
|
60
|
-
elmsToUpdate.set(propName, elements.filter(
|
|
84
|
+
elmsToUpdate.set(propName, elements.filter(ensureForceUpdate));
|
|
61
85
|
}
|
|
62
86
|
cleanupElements(elmsToUpdate);
|
|
63
87
|
},
|
|
64
88
|
reset: () => {
|
|
65
|
-
elmsToUpdate.forEach((elms) => elms.forEach(
|
|
89
|
+
elmsToUpdate.forEach((elms) => elms.forEach(ensureForceUpdate));
|
|
66
90
|
cleanupElements(elmsToUpdate);
|
|
67
91
|
},
|
|
68
92
|
};
|
|
@@ -70,8 +94,11 @@ const stencilSubscription = () => {
|
|
|
70
94
|
|
|
71
95
|
const unwrap = (val) => (typeof val === 'function' ? val() : val);
|
|
72
96
|
const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) => {
|
|
73
|
-
const
|
|
74
|
-
|
|
97
|
+
const resolveDefaultState = () => (unwrap(defaultState) ?? {});
|
|
98
|
+
const initialState = resolveDefaultState();
|
|
99
|
+
let states = new Map(Object.entries(initialState));
|
|
100
|
+
const proxyAvailable = typeof Proxy !== 'undefined';
|
|
101
|
+
const plainState = proxyAvailable ? null : {};
|
|
75
102
|
const handlers = {
|
|
76
103
|
dispose: [],
|
|
77
104
|
get: [],
|
|
@@ -83,7 +110,10 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
|
|
|
83
110
|
const reset = () => {
|
|
84
111
|
// When resetting the state, the default state may be a function - unwrap it to invoke it.
|
|
85
112
|
// otherwise, the state won't be properly reset
|
|
86
|
-
states = new Map(Object.entries(
|
|
113
|
+
states = new Map(Object.entries(resolveDefaultState()));
|
|
114
|
+
if (!proxyAvailable) {
|
|
115
|
+
syncPlainStateKeys();
|
|
116
|
+
}
|
|
87
117
|
handlers.reset.forEach((cb) => cb());
|
|
88
118
|
};
|
|
89
119
|
const dispose = () => {
|
|
@@ -100,12 +130,14 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
|
|
|
100
130
|
const oldValue = states.get(propName);
|
|
101
131
|
if (shouldUpdate(value, oldValue, propName)) {
|
|
102
132
|
states.set(propName, value);
|
|
133
|
+
if (!proxyAvailable) {
|
|
134
|
+
ensurePlainProperty(propName);
|
|
135
|
+
}
|
|
103
136
|
handlers.set.forEach((cb) => cb(propName, value, oldValue));
|
|
104
137
|
}
|
|
105
138
|
};
|
|
106
|
-
const state = (
|
|
107
|
-
? {
|
|
108
|
-
: new Proxy(unwrappedState, {
|
|
139
|
+
const state = (proxyAvailable
|
|
140
|
+
? new Proxy(initialState, {
|
|
109
141
|
get(_, propName) {
|
|
110
142
|
return get(propName);
|
|
111
143
|
},
|
|
@@ -125,7 +157,11 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
|
|
|
125
157
|
set(propName, value);
|
|
126
158
|
return true;
|
|
127
159
|
},
|
|
128
|
-
})
|
|
160
|
+
})
|
|
161
|
+
: (() => {
|
|
162
|
+
syncPlainStateKeys();
|
|
163
|
+
return plainState;
|
|
164
|
+
})());
|
|
129
165
|
const on = (eventName, callback) => {
|
|
130
166
|
handlers[eventName].push(callback);
|
|
131
167
|
return () => {
|
|
@@ -138,7 +174,10 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
|
|
|
138
174
|
cb(newValue);
|
|
139
175
|
}
|
|
140
176
|
};
|
|
141
|
-
const resetHandler = () =>
|
|
177
|
+
const resetHandler = () => {
|
|
178
|
+
const snapshot = resolveDefaultState();
|
|
179
|
+
cb(snapshot[propName]);
|
|
180
|
+
};
|
|
142
181
|
// Register the handlers
|
|
143
182
|
const unSet = on('set', setHandler);
|
|
144
183
|
const unReset = on('reset', resetHandler);
|
|
@@ -181,6 +220,38 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
|
|
|
181
220
|
changeListeners.delete(listener);
|
|
182
221
|
}
|
|
183
222
|
};
|
|
223
|
+
function ensurePlainProperty(key) {
|
|
224
|
+
if (proxyAvailable || !plainState) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (Object.prototype.hasOwnProperty.call(plainState, key)) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
Object.defineProperty(plainState, key, {
|
|
231
|
+
configurable: true,
|
|
232
|
+
enumerable: true,
|
|
233
|
+
get() {
|
|
234
|
+
return get(key);
|
|
235
|
+
},
|
|
236
|
+
set(value) {
|
|
237
|
+
set(key, value);
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
function syncPlainStateKeys() {
|
|
242
|
+
if (proxyAvailable || !plainState) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const knownKeys = new Set(states.keys());
|
|
246
|
+
for (const key of Object.keys(plainState)) {
|
|
247
|
+
if (!knownKeys.has(key)) {
|
|
248
|
+
delete plainState[key];
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
for (const key of knownKeys) {
|
|
252
|
+
ensurePlainProperty(key);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
184
255
|
return {
|
|
185
256
|
state,
|
|
186
257
|
get,
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as StencilCore from '@stencil/core';
|
|
2
2
|
|
|
3
3
|
const appendToMap = (map, propName, value) => {
|
|
4
4
|
const items = map.get(propName);
|
|
@@ -37,17 +37,22 @@ const cleanupElements = debounce((map) => {
|
|
|
37
37
|
map.set(key, map.get(key).filter(isConnected));
|
|
38
38
|
}
|
|
39
39
|
}, 2_000);
|
|
40
|
+
const core = StencilCore;
|
|
41
|
+
const forceUpdate = core.forceUpdate;
|
|
42
|
+
const getRenderingRef = core.getRenderingRef;
|
|
40
43
|
const stencilSubscription = () => {
|
|
41
|
-
if (typeof getRenderingRef !== 'function') {
|
|
44
|
+
if (typeof getRenderingRef !== 'function' || typeof forceUpdate !== 'function') {
|
|
42
45
|
// If we are not in a stencil project, we do nothing.
|
|
43
46
|
// This function is not really exported by @stencil/core.
|
|
44
47
|
return {};
|
|
45
48
|
}
|
|
49
|
+
const ensureForceUpdate = forceUpdate;
|
|
50
|
+
const ensureGetRenderingRef = getRenderingRef;
|
|
46
51
|
const elmsToUpdate = new Map();
|
|
47
52
|
return {
|
|
48
53
|
dispose: () => elmsToUpdate.clear(),
|
|
49
54
|
get: (propName) => {
|
|
50
|
-
const elm =
|
|
55
|
+
const elm = ensureGetRenderingRef();
|
|
51
56
|
if (elm) {
|
|
52
57
|
appendToMap(elmsToUpdate, propName, elm);
|
|
53
58
|
}
|
|
@@ -55,12 +60,12 @@ const stencilSubscription = () => {
|
|
|
55
60
|
set: (propName) => {
|
|
56
61
|
const elements = elmsToUpdate.get(propName);
|
|
57
62
|
if (elements) {
|
|
58
|
-
elmsToUpdate.set(propName, elements.filter(
|
|
63
|
+
elmsToUpdate.set(propName, elements.filter(ensureForceUpdate));
|
|
59
64
|
}
|
|
60
65
|
cleanupElements(elmsToUpdate);
|
|
61
66
|
},
|
|
62
67
|
reset: () => {
|
|
63
|
-
elmsToUpdate.forEach((elms) => elms.forEach(
|
|
68
|
+
elmsToUpdate.forEach((elms) => elms.forEach(ensureForceUpdate));
|
|
64
69
|
cleanupElements(elmsToUpdate);
|
|
65
70
|
},
|
|
66
71
|
};
|
|
@@ -68,8 +73,11 @@ const stencilSubscription = () => {
|
|
|
68
73
|
|
|
69
74
|
const unwrap = (val) => (typeof val === 'function' ? val() : val);
|
|
70
75
|
const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) => {
|
|
71
|
-
const
|
|
72
|
-
|
|
76
|
+
const resolveDefaultState = () => (unwrap(defaultState) ?? {});
|
|
77
|
+
const initialState = resolveDefaultState();
|
|
78
|
+
let states = new Map(Object.entries(initialState));
|
|
79
|
+
const proxyAvailable = typeof Proxy !== 'undefined';
|
|
80
|
+
const plainState = proxyAvailable ? null : {};
|
|
73
81
|
const handlers = {
|
|
74
82
|
dispose: [],
|
|
75
83
|
get: [],
|
|
@@ -81,7 +89,10 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
|
|
|
81
89
|
const reset = () => {
|
|
82
90
|
// When resetting the state, the default state may be a function - unwrap it to invoke it.
|
|
83
91
|
// otherwise, the state won't be properly reset
|
|
84
|
-
states = new Map(Object.entries(
|
|
92
|
+
states = new Map(Object.entries(resolveDefaultState()));
|
|
93
|
+
if (!proxyAvailable) {
|
|
94
|
+
syncPlainStateKeys();
|
|
95
|
+
}
|
|
85
96
|
handlers.reset.forEach((cb) => cb());
|
|
86
97
|
};
|
|
87
98
|
const dispose = () => {
|
|
@@ -98,12 +109,14 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
|
|
|
98
109
|
const oldValue = states.get(propName);
|
|
99
110
|
if (shouldUpdate(value, oldValue, propName)) {
|
|
100
111
|
states.set(propName, value);
|
|
112
|
+
if (!proxyAvailable) {
|
|
113
|
+
ensurePlainProperty(propName);
|
|
114
|
+
}
|
|
101
115
|
handlers.set.forEach((cb) => cb(propName, value, oldValue));
|
|
102
116
|
}
|
|
103
117
|
};
|
|
104
|
-
const state = (
|
|
105
|
-
? {
|
|
106
|
-
: new Proxy(unwrappedState, {
|
|
118
|
+
const state = (proxyAvailable
|
|
119
|
+
? new Proxy(initialState, {
|
|
107
120
|
get(_, propName) {
|
|
108
121
|
return get(propName);
|
|
109
122
|
},
|
|
@@ -123,7 +136,11 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
|
|
|
123
136
|
set(propName, value);
|
|
124
137
|
return true;
|
|
125
138
|
},
|
|
126
|
-
})
|
|
139
|
+
})
|
|
140
|
+
: (() => {
|
|
141
|
+
syncPlainStateKeys();
|
|
142
|
+
return plainState;
|
|
143
|
+
})());
|
|
127
144
|
const on = (eventName, callback) => {
|
|
128
145
|
handlers[eventName].push(callback);
|
|
129
146
|
return () => {
|
|
@@ -136,7 +153,10 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
|
|
|
136
153
|
cb(newValue);
|
|
137
154
|
}
|
|
138
155
|
};
|
|
139
|
-
const resetHandler = () =>
|
|
156
|
+
const resetHandler = () => {
|
|
157
|
+
const snapshot = resolveDefaultState();
|
|
158
|
+
cb(snapshot[propName]);
|
|
159
|
+
};
|
|
140
160
|
// Register the handlers
|
|
141
161
|
const unSet = on('set', setHandler);
|
|
142
162
|
const unReset = on('reset', resetHandler);
|
|
@@ -179,6 +199,38 @@ const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) =>
|
|
|
179
199
|
changeListeners.delete(listener);
|
|
180
200
|
}
|
|
181
201
|
};
|
|
202
|
+
function ensurePlainProperty(key) {
|
|
203
|
+
if (proxyAvailable || !plainState) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (Object.prototype.hasOwnProperty.call(plainState, key)) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
Object.defineProperty(plainState, key, {
|
|
210
|
+
configurable: true,
|
|
211
|
+
enumerable: true,
|
|
212
|
+
get() {
|
|
213
|
+
return get(key);
|
|
214
|
+
},
|
|
215
|
+
set(value) {
|
|
216
|
+
set(key, value);
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function syncPlainStateKeys() {
|
|
221
|
+
if (proxyAvailable || !plainState) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const knownKeys = new Set(states.keys());
|
|
225
|
+
for (const key of Object.keys(plainState)) {
|
|
226
|
+
if (!knownKeys.has(key)) {
|
|
227
|
+
delete plainState[key];
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
for (const key of knownKeys) {
|
|
231
|
+
ensurePlainProperty(key);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
182
234
|
return {
|
|
183
235
|
state,
|
|
184
236
|
get,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stencil/store",
|
|
3
3
|
"author": "StencilJS Team",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.1-dev.1763340412.50ef6ed",
|
|
5
5
|
"description": "Store is a lightweight shared state library by the StencilJS core team. Implements a simple key/value map that efficiently re-renders components when necessary.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://stenciljs.com/docs/stencil-store",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"npm": ">=6.0.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "run-s build
|
|
37
|
-
"build.clean": "
|
|
36
|
+
"build": "run-s build.clean build.rollup",
|
|
37
|
+
"build.clean": "rimraf dist",
|
|
38
38
|
"build.rollup": "rollup -c rollup.config.js",
|
|
39
39
|
"prettier": "npm run prettier.base -- --write",
|
|
40
|
-
"prettier.base": "prettier --cache
|
|
40
|
+
"prettier.base": "prettier --cache \"src/**/*.ts\"",
|
|
41
41
|
"prettier.dry-run": "npm run prettier.base -- --list-different",
|
|
42
42
|
"release": "np",
|
|
43
43
|
"test": "run-s test.*",
|
|
@@ -53,16 +53,17 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@ionic/prettier-config": "^4.0.0",
|
|
56
|
-
"@rollup/plugin-typescript": "^12.
|
|
57
|
-
"@stencil/core": "^4.
|
|
58
|
-
"@types/node": "^24.
|
|
59
|
-
"@vitest/coverage-v8": "^
|
|
56
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
57
|
+
"@stencil/core": "^4.38.2",
|
|
58
|
+
"@types/node": "^24.9.2",
|
|
59
|
+
"@vitest/coverage-v8": "^4.0.5",
|
|
60
60
|
"np": "^10.2.0",
|
|
61
|
-
"npm-run-all2": "^8.0.
|
|
62
|
-
"prettier": "^3.
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
61
|
+
"npm-run-all2": "^8.0.4",
|
|
62
|
+
"prettier": "^3.6.2",
|
|
63
|
+
"rimraf": "^6.0.1",
|
|
64
|
+
"rollup": "^4.52.5",
|
|
65
|
+
"typescript": "~5.9.3",
|
|
66
|
+
"vitest": "^4.0.5"
|
|
66
67
|
},
|
|
67
68
|
"prettier": "@ionic/prettier-config"
|
|
68
69
|
}
|