svelte-common 4.18.2 → 4.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/util.mjs +11 -6
package/package.json
CHANGED
package/src/util.mjs
CHANGED
|
@@ -96,7 +96,7 @@ function liveDuration(seconds) {
|
|
|
96
96
|
*/
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
* Create a store where
|
|
99
|
+
* Create a store where all the object keys are prefixed.
|
|
100
100
|
* @param {WriteableStore} store
|
|
101
101
|
* @param {string} prefix
|
|
102
102
|
* @returns {WriteableStore}
|
|
@@ -105,12 +105,16 @@ export function keyPrefixStore(store, prefix) {
|
|
|
105
105
|
const subscriptions = new Set();
|
|
106
106
|
|
|
107
107
|
let forwardSubscription;
|
|
108
|
+
let forwardObject;
|
|
108
109
|
|
|
109
110
|
return {
|
|
110
111
|
set: object =>
|
|
111
112
|
store.set(
|
|
112
|
-
Object.
|
|
113
|
-
|
|
113
|
+
Object.assign(
|
|
114
|
+
forwardObject,
|
|
115
|
+
Object.fromEntries(
|
|
116
|
+
Object.entries(object).map(([k, v]) => [prefix + k, v])
|
|
117
|
+
)
|
|
114
118
|
)
|
|
115
119
|
),
|
|
116
120
|
|
|
@@ -118,12 +122,13 @@ export function keyPrefixStore(store, prefix) {
|
|
|
118
122
|
subscriptions.add(s);
|
|
119
123
|
|
|
120
124
|
if (!forwardSubscription) {
|
|
121
|
-
forwardSubscription = store.subscribe(
|
|
125
|
+
forwardSubscription = store.subscribe(o => {
|
|
126
|
+
forwardObject = o;
|
|
122
127
|
const object =
|
|
123
|
-
|
|
128
|
+
forwardObject === undefined
|
|
124
129
|
? {}
|
|
125
130
|
: Object.fromEntries(
|
|
126
|
-
Object.entries(
|
|
131
|
+
Object.entries(forwardObject)
|
|
127
132
|
.filter(([k, v]) => k.startsWith(prefix))
|
|
128
133
|
.map(([k, v]) => [k.substring(prefix.length), v])
|
|
129
134
|
);
|