svas 0.1.5 → 0.1.7

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.
@@ -19,7 +19,7 @@ export declare class Collection<T extends Identifiable, E extends Error = Error>
19
19
  set<I = T>(item: Input<T, typeof this.map, I>, options?: SetOptions): Readable<T | E>;
20
20
  preset<I = T>(item: Input<T, typeof this.map, I>): void;
21
21
  reset(id: string): void;
22
- update(id: string, update: (item: T) => T | void): void;
22
+ update(id: string, update: (item: T) => T | void, options?: SetOptions): void;
23
23
  sync(): this;
24
24
  replace<I = T>(items: Array<Input<T, typeof this.map, I>>): void;
25
25
  private refresh;
@@ -56,8 +56,8 @@ export interface SetOptions {
56
56
  add?: boolean;
57
57
  /** Whether value is transient. Defaults to false. */
58
58
  stash?: boolean;
59
- /** Whether to sync the collection after setting the item. Defaults to true. */
60
- bind?: boolean;
59
+ /** Whether to sync the collection values after setting the item. Defaults to true. */
60
+ sync?: boolean;
61
61
  }
62
62
  export declare function collection<T extends Identifiable, E extends Error = Error>(options: Options<T, E>): Collection<T, E>;
63
63
  export {};
@@ -75,7 +75,7 @@ export class Collection {
75
75
  items.sort(this.sort);
76
76
  return items;
77
77
  });
78
- if (options?.bind === false)
78
+ if (options?.sync === false)
79
79
  return this.values?.get(value.id);
80
80
  else
81
81
  return this.values?.set(value.id, value, options);
@@ -89,16 +89,16 @@ export class Collection {
89
89
  const value = this.values?.reset(id);
90
90
  if (value === null || value instanceof Error)
91
91
  return;
92
- this.set(value, { bind: false });
92
+ this.set(value, { sync: false });
93
93
  }
94
- update(id, update) {
94
+ update(id, update, options) {
95
95
  if (this.values === undefined)
96
96
  throw new Error('Collection: values is not defined');
97
97
  const asis = this.values.extract(id);
98
98
  if (asis === null)
99
99
  return;
100
100
  const tobe = update(asis) ?? asis;
101
- this.set(tobe);
101
+ this.set(tobe, options);
102
102
  }
103
103
  sync() {
104
104
  const stale = this.timestamp === 0 || this.timestamp + this.revalidate < Date.now();
package/dist/combined.js CHANGED
@@ -1,24 +1,12 @@
1
- import { readable } from 'svelte/store';
1
+ import { derived } from 'svelte/store';
2
2
  export function combined(...stores) {
3
- return readable(null, (set) => {
4
- const values = new Array(stores.length).fill(null);
5
- const unsubs = stores.map((store, index) => store.subscribe((value) => {
6
- if (value instanceof Error) {
7
- values[index] = null;
8
- set(value);
9
- }
10
- else if (value === null) {
11
- values[index] = value;
12
- set(value);
13
- }
14
- else {
15
- values[index] = value;
16
- if (values.every((value) => value !== null))
17
- set(values);
18
- }
19
- }));
20
- return () => {
21
- unsubs.forEach((unsub) => unsub());
22
- };
3
+ return derived(stores, (values, set) => {
4
+ const error = values.find((value) => value instanceof Error);
5
+ if (error)
6
+ set(error);
7
+ else if (values.some((value) => value === null))
8
+ set(null);
9
+ else
10
+ set(values);
23
11
  });
24
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svas",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",