svelte-common 4.18.1 → 4.19.0
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/sorting.mjs +5 -1
- package/src/util.mjs +36 -20
package/package.json
CHANGED
package/src/sorting.mjs
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}
|
|
@@ -104,30 +104,46 @@ function liveDuration(seconds) {
|
|
|
104
104
|
export function keyPrefixStore(store, prefix) {
|
|
105
105
|
const subscriptions = new Set();
|
|
106
106
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
prefixedKeyObject === undefined
|
|
110
|
-
? {}
|
|
111
|
-
: Object.fromEntries(
|
|
112
|
-
Object.entries(prefixedKeyObject)
|
|
113
|
-
.filter(([k, v]) => k.startsWith(prefix))
|
|
114
|
-
.map(([k, v]) => [k.substring(prefix.length), v])
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
subscriptions.forEach(subscription => subscription(object));
|
|
118
|
-
});
|
|
107
|
+
let forwardSubscription;
|
|
108
|
+
let forwardObject;
|
|
119
109
|
|
|
120
110
|
return {
|
|
121
|
-
set: object =>
|
|
122
|
-
|
|
123
|
-
Object.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
111
|
+
set: object =>
|
|
112
|
+
store.set(
|
|
113
|
+
Object.assign(
|
|
114
|
+
forwardObject,
|
|
115
|
+
Object.fromEntries(
|
|
116
|
+
Object.entries(object).map(([k, v]) => [prefix + k, v])
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
),
|
|
127
120
|
|
|
128
121
|
subscribe: s => {
|
|
129
122
|
subscriptions.add(s);
|
|
130
|
-
|
|
123
|
+
|
|
124
|
+
if (!forwardSubscription) {
|
|
125
|
+
forwardSubscription = store.subscribe(o => {
|
|
126
|
+
forwardObject = o;
|
|
127
|
+
const object =
|
|
128
|
+
forwardObject === undefined
|
|
129
|
+
? {}
|
|
130
|
+
: Object.fromEntries(
|
|
131
|
+
Object.entries(forwardObject)
|
|
132
|
+
.filter(([k, v]) => k.startsWith(prefix))
|
|
133
|
+
.map(([k, v]) => [k.substring(prefix.length), v])
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
subscriptions.forEach(subscription => subscription(object));
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return () => {
|
|
141
|
+
subscriptions.delete(s);
|
|
142
|
+
if (subscriptions.size === 0) {
|
|
143
|
+
forwardSubscription();
|
|
144
|
+
forwardSubscription = undefined;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
131
147
|
}
|
|
132
148
|
};
|
|
133
149
|
}
|