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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "4.18.1",
3
+ "version": "4.19.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/sorting.mjs CHANGED
@@ -53,7 +53,11 @@ export function sortable(th, store) {
53
53
  }
54
54
  }
55
55
 
56
- orderBy[peer.id] = sort;
56
+ if (sort == SORT_NONE) {
57
+ delete orderBy[peer.id];
58
+ } else {
59
+ orderBy[peer.id] = sort;
60
+ }
57
61
  }
58
62
  }
59
63
  store.set(orderBy);
package/src/util.mjs CHANGED
@@ -96,7 +96,7 @@ function liveDuration(seconds) {
96
96
  */
97
97
 
98
98
  /**
99
- * Create a store where al the object keys are prefixed
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
- store.subscribe(prefixedKeyObject => {
108
- const object =
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
- const prefixedKeyObject = Object.fromEntries(
123
- Object.entries(object).map(([k, v]) => [prefix + k, v])
124
- );
125
- store.set(prefixedKeyObject);
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
- return () => subscriptions.delete(s);
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
  }