svelte-common 4.19.14 → 4.19.16
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/filter.mjs +11 -0
- package/src/util.mjs +25 -20
package/package.json
CHANGED
package/src/filter.mjs
CHANGED
|
@@ -14,6 +14,17 @@ export function filter(filterBy, getters = {}) {
|
|
|
14
14
|
if (value instanceof RegExp) {
|
|
15
15
|
return value.test(av);
|
|
16
16
|
}
|
|
17
|
+
if (value instanceof Date) {
|
|
18
|
+
switch (typeof av) {
|
|
19
|
+
case "object":
|
|
20
|
+
if (av instanceof Date) {
|
|
21
|
+
return av.getTime() == value.getTime();
|
|
22
|
+
}
|
|
23
|
+
break;
|
|
24
|
+
case "string":
|
|
25
|
+
return value.toString().match(av);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
17
28
|
|
|
18
29
|
switch (typeof av) {
|
|
19
30
|
case "object":
|
package/src/util.mjs
CHANGED
|
@@ -98,10 +98,10 @@ function liveDuration(seconds) {
|
|
|
98
98
|
/**
|
|
99
99
|
* Create a derived store where all the object keys are prefixed.
|
|
100
100
|
* ```
|
|
101
|
-
* { a: 1, b: 2 } -> {
|
|
101
|
+
* { a: 1, b: 2 } -> { foo_a: 1 foo_b: 2 } // prefix: foo_
|
|
102
102
|
* ```
|
|
103
|
-
* @param {WriteableStore} store
|
|
104
|
-
* @param {string} prefix
|
|
103
|
+
* @param {WriteableStore} store we derive from
|
|
104
|
+
* @param {string} prefix for each key
|
|
105
105
|
* @returns {WriteableStore}
|
|
106
106
|
*/
|
|
107
107
|
export function keyPrefixStore(store, prefix) {
|
|
@@ -110,8 +110,27 @@ export function keyPrefixStore(store, prefix) {
|
|
|
110
110
|
let forwardSubscription;
|
|
111
111
|
let forwardObject;
|
|
112
112
|
|
|
113
|
+
function subscribeMyself() {
|
|
114
|
+
if (!forwardSubscription) {
|
|
115
|
+
forwardSubscription = store.subscribe(o => {
|
|
116
|
+
forwardObject = o;
|
|
117
|
+
const object =
|
|
118
|
+
forwardObject === undefined
|
|
119
|
+
? {}
|
|
120
|
+
: Object.fromEntries(
|
|
121
|
+
Object.entries(forwardObject)
|
|
122
|
+
.filter(([k, v]) => k.startsWith(prefix))
|
|
123
|
+
.map(([k, v]) => [k.substring(prefix.length), v])
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
subscriptions.forEach(subscription => subscription(object));
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
113
131
|
return {
|
|
114
|
-
set: object =>
|
|
132
|
+
set: object => {
|
|
133
|
+
subscribeMyself();
|
|
115
134
|
store.set(
|
|
116
135
|
Object.assign(
|
|
117
136
|
forwardObject,
|
|
@@ -119,26 +138,12 @@ export function keyPrefixStore(store, prefix) {
|
|
|
119
138
|
Object.entries(object).map(([k, v]) => [prefix + k, v])
|
|
120
139
|
)
|
|
121
140
|
)
|
|
122
|
-
),
|
|
141
|
+
); },
|
|
123
142
|
|
|
124
143
|
subscribe: s => {
|
|
125
144
|
subscriptions.add(s);
|
|
126
145
|
|
|
127
|
-
|
|
128
|
-
forwardSubscription = store.subscribe(o => {
|
|
129
|
-
forwardObject = o;
|
|
130
|
-
const object =
|
|
131
|
-
forwardObject === undefined
|
|
132
|
-
? {}
|
|
133
|
-
: Object.fromEntries(
|
|
134
|
-
Object.entries(forwardObject)
|
|
135
|
-
.filter(([k, v]) => k.startsWith(prefix))
|
|
136
|
-
.map(([k, v]) => [k.substring(prefix.length), v])
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
subscriptions.forEach(subscription => subscription(object));
|
|
140
|
-
});
|
|
141
|
-
}
|
|
146
|
+
subscribeMyself();
|
|
142
147
|
|
|
143
148
|
return () => {
|
|
144
149
|
subscriptions.delete(s);
|