@signaldb/svelte 2.0.0-beta.2 → 2.0.0-beta.21
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/dist/base/core/src/AsyncDataAdapter.d.ts +112 -0
- package/dist/base/core/src/AsyncDataAdapter.js +549 -0
- package/dist/base/core/src/AutoFetchDataAdapter.d.ts +112 -0
- package/dist/base/core/src/AutoFetchDataAdapter.js +612 -0
- package/dist/base/core/src/Collection/Cursor.d.ts +165 -0
- package/dist/base/core/src/Collection/Cursor.js +352 -0
- package/dist/base/core/src/Collection/Observer.d.ts +95 -0
- package/dist/base/core/src/Collection/Observer.js +227 -0
- package/dist/base/core/src/Collection/index.d.ts +341 -0
- package/dist/base/core/src/Collection/index.js +761 -0
- package/dist/base/core/src/Collection/types.d.ts +28 -0
- package/dist/base/core/src/Collection/types.js +2 -0
- package/dist/base/core/src/DataAdapter.d.ts +54 -0
- package/dist/base/core/src/DataAdapter.js +2 -0
- package/dist/base/core/src/DefaultDataAdapter.d.ts +35 -0
- package/dist/base/core/src/DefaultDataAdapter.js +408 -0
- package/dist/base/core/src/WorkerDataAdapter.d.ts +79 -0
- package/dist/base/core/src/WorkerDataAdapter.js +749 -0
- package/dist/base/core/src/WorkerDataAdapterHost.d.ts +64 -0
- package/dist/base/core/src/WorkerDataAdapterHost.js +430 -0
- package/dist/base/core/src/createIndex.d.ts +7 -0
- package/dist/base/core/src/createIndex.js +120 -0
- package/dist/base/core/src/createIndexProvider.d.ts +8 -0
- package/dist/base/core/src/createIndexProvider.js +11 -0
- package/dist/base/core/src/createReactivityAdapter.d.ts +8 -0
- package/dist/base/core/src/createReactivityAdapter.js +11 -0
- package/dist/base/core/src/createStorageAdapter.d.ts +9 -0
- package/dist/base/core/src/createStorageAdapter.js +11 -0
- package/dist/base/core/src/getIndexInfo.d.ts +39 -0
- package/dist/base/core/src/getIndexInfo.js +188 -0
- package/dist/base/core/src/index.d.ts +26 -0
- package/dist/base/core/src/index.js +39 -0
- package/dist/base/core/src/types/Dependency.d.ts +4 -0
- package/dist/base/core/src/types/Dependency.js +2 -0
- package/dist/base/core/src/types/IndexProvider.d.ts +26 -0
- package/dist/base/core/src/types/IndexProvider.js +2 -0
- package/dist/base/core/src/types/Modifier.d.ts +46 -0
- package/dist/base/core/src/types/Modifier.js +3 -0
- package/dist/base/core/src/types/ReactivityAdapter.d.ts +6 -0
- package/dist/base/core/src/types/ReactivityAdapter.js +2 -0
- package/dist/base/core/src/types/Selector.d.ts +46 -0
- package/dist/base/core/src/types/Selector.js +3 -0
- package/dist/base/core/src/types/Signal.d.ts +4 -0
- package/dist/base/core/src/types/Signal.js +2 -0
- package/dist/base/core/src/types/StorageAdapter.d.ts +28 -0
- package/dist/base/core/src/types/StorageAdapter.js +2 -0
- package/dist/base/core/src/utils/EventEmitter.d.ts +71 -0
- package/dist/base/core/src/utils/EventEmitter.js +144 -0
- package/dist/base/core/src/utils/applyQueryOptions.d.ts +15 -0
- package/dist/base/core/src/utils/applyQueryOptions.js +36 -0
- package/dist/base/core/src/utils/batchOnNextTick.d.ts +16 -0
- package/dist/base/core/src/utils/batchOnNextTick.js +72 -0
- package/dist/base/core/src/utils/compact.d.ts +9 -0
- package/dist/base/core/src/utils/compact.js +21 -0
- package/dist/base/core/src/utils/createSignal.d.ts +14 -0
- package/dist/base/core/src/utils/createSignal.js +38 -0
- package/dist/base/core/src/utils/deepClone.d.ts +17 -0
- package/dist/base/core/src/utils/deepClone.js +68 -0
- package/dist/base/core/src/utils/get.d.ts +9 -0
- package/dist/base/core/src/utils/get.js +27 -0
- package/dist/base/core/src/utils/getMatchingKeys.d.ts +19 -0
- package/dist/base/core/src/utils/getMatchingKeys.js +49 -0
- package/dist/base/core/src/utils/idIndexQuery.d.ts +20 -0
- package/dist/base/core/src/utils/idIndexQuery.js +49 -0
- package/dist/base/core/src/utils/incrementalQueryUpdate.d.ts +62 -0
- package/dist/base/core/src/utils/incrementalQueryUpdate.js +197 -0
- package/dist/base/core/src/utils/intersection.d.ts +9 -0
- package/dist/base/core/src/utils/intersection.js +16 -0
- package/dist/base/core/src/utils/isEqual.d.ts +14 -0
- package/dist/base/core/src/utils/isEqual.js +43 -0
- package/dist/base/core/src/utils/isFieldExpression.d.ts +11 -0
- package/dist/base/core/src/utils/isFieldExpression.js +52 -0
- package/dist/base/core/src/utils/match.d.ts +12 -0
- package/dist/base/core/src/utils/match.js +16 -0
- package/dist/base/core/src/utils/modify.d.ts +14 -0
- package/dist/base/core/src/utils/modify.js +29 -0
- package/dist/base/core/src/utils/project.d.ts +15 -0
- package/dist/base/core/src/utils/project.js +43 -0
- package/dist/base/core/src/utils/projectItems.d.ts +12 -0
- package/dist/base/core/src/utils/projectItems.js +25 -0
- package/dist/base/core/src/utils/queryDelta.d.ts +83 -0
- package/dist/base/core/src/utils/queryDelta.js +231 -0
- package/dist/base/core/src/utils/queryId.d.ts +9 -0
- package/dist/base/core/src/utils/queryId.js +61 -0
- package/dist/base/core/src/utils/randomId.d.ts +7 -0
- package/dist/base/core/src/utils/randomId.js +12 -0
- package/dist/base/core/src/utils/reactiveOrAsync.d.ts +59 -0
- package/dist/base/core/src/utils/reactiveOrAsync.js +93 -0
- package/dist/base/core/src/utils/serializeValue.d.ts +12 -0
- package/dist/base/core/src/utils/serializeValue.js +27 -0
- package/dist/base/core/src/utils/set.d.ts +13 -0
- package/dist/base/core/src/utils/set.js +43 -0
- package/dist/base/core/src/utils/sortItems.d.ts +12 -0
- package/dist/base/core/src/utils/sortItems.js +23 -0
- package/dist/base/core/src/utils/storageIndexQuery.d.ts +20 -0
- package/dist/base/core/src/utils/storageIndexQuery.js +75 -0
- package/dist/base/core/src/utils/uniqueBy.d.ts +10 -0
- package/dist/base/core/src/utils/uniqueBy.js +19 -0
- package/dist/index.cjs +38 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +38 -0
- package/dist/index.mjs.map +1 -0
- package/dist/reactivity-adapters/svelte/index.svelte.d.ts +10 -0
- package/dist/reactivity-adapters/svelte/index.svelte.js +36 -0
- package/package.json +3 -3
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = sortItems;
|
|
7
|
+
const fast_sort_1 = require("fast-sort");
|
|
8
|
+
const get_1 = __importDefault(require("./get"));
|
|
9
|
+
/**
|
|
10
|
+
* Sorts an array of items based on multiple fields and their specified sort order.
|
|
11
|
+
* Uses the `fast-sort` library for efficient sorting.
|
|
12
|
+
* @template T - The type of the items in the array.
|
|
13
|
+
* @param items - The array of items to be sorted.
|
|
14
|
+
* @param sortFields - An object defining the sort order for each field.
|
|
15
|
+
* - Keys are the field names, and values are either `1` (ascending) or `-1` (descending).
|
|
16
|
+
* @returns A new array of items sorted based on the specified fields and their order.
|
|
17
|
+
*/
|
|
18
|
+
function sortItems(items, sortFields) {
|
|
19
|
+
return (0, fast_sort_1.sort)(items).by(Object.entries(sortFields).map(([key, value]) => {
|
|
20
|
+
const order = value === 1 ? 'asc' : 'desc';
|
|
21
|
+
return { [order]: (i) => (0, get_1.default)(i, key) };
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BaseItem } from '../Collection/types';
|
|
2
|
+
import type StorageAdapter from '../types/StorageAdapter';
|
|
3
|
+
import type { AsynchronousQueryFunction } from '../types/IndexProvider';
|
|
4
|
+
/**
|
|
5
|
+
* Builds the index provider a data adapter uses to narrow a selector down through
|
|
6
|
+
* a storage adapter's index.
|
|
7
|
+
*
|
|
8
|
+
* Every adapter that keeps its data in a `StorageAdapter` needs exactly this, and
|
|
9
|
+
* each of them used to carry its own copy — three transcriptions of one set of
|
|
10
|
+
* rules about null, `$exists`, inclusion and exclusion, which is how they drift
|
|
11
|
+
* apart without anyone noticing. The index is keyed by `serializeValue(value)`,
|
|
12
|
+
* which is what `getMatchingKeys` produces, so the two only agree while they stay
|
|
13
|
+
* in one place.
|
|
14
|
+
* @template T - The type of the items in the collection.
|
|
15
|
+
* @template I - The type of the unique identifier for the items.
|
|
16
|
+
* @param storage - The storage adapter holding the index.
|
|
17
|
+
* @param field - The indexed field this provider answers for.
|
|
18
|
+
* @returns A query function for `getIndexInfo`.
|
|
19
|
+
*/
|
|
20
|
+
export default function storageIndexQuery<T extends BaseItem<I>, I = any>(storage: Pick<StorageAdapter<T, I>, 'readIndex'>, field: string): AsynchronousQueryFunction<T, I>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = storageIndexQuery;
|
|
7
|
+
const getMatchingKeys_1 = __importDefault(require("./getMatchingKeys"));
|
|
8
|
+
/**
|
|
9
|
+
* Builds the index provider a data adapter uses to narrow a selector down through
|
|
10
|
+
* a storage adapter's index.
|
|
11
|
+
*
|
|
12
|
+
* Every adapter that keeps its data in a `StorageAdapter` needs exactly this, and
|
|
13
|
+
* each of them used to carry its own copy — three transcriptions of one set of
|
|
14
|
+
* rules about null, `$exists`, inclusion and exclusion, which is how they drift
|
|
15
|
+
* apart without anyone noticing. The index is keyed by `serializeValue(value)`,
|
|
16
|
+
* which is what `getMatchingKeys` produces, so the two only agree while they stay
|
|
17
|
+
* in one place.
|
|
18
|
+
* @template T - The type of the items in the collection.
|
|
19
|
+
* @template I - The type of the unique identifier for the items.
|
|
20
|
+
* @param storage - The storage adapter holding the index.
|
|
21
|
+
* @param field - The indexed field this provider answers for.
|
|
22
|
+
* @returns A query function for `getIndexInfo`.
|
|
23
|
+
*/
|
|
24
|
+
function storageIndexQuery(storage, field) {
|
|
25
|
+
return async (flatSelector) => {
|
|
26
|
+
if (!Object.hasOwnProperty.call(flatSelector, field)) {
|
|
27
|
+
// The field is not in the selector, so this index says nothing about it.
|
|
28
|
+
return { matched: false };
|
|
29
|
+
}
|
|
30
|
+
const index = await storage.readIndex(field);
|
|
31
|
+
const fieldSelector = flatSelector[field];
|
|
32
|
+
// A query for null, or for the field being absent, is the one case the index
|
|
33
|
+
// cannot answer by naming keys — it is answered by naming every key it is
|
|
34
|
+
// *not*, and the selector has to stay for the matcher to confirm it.
|
|
35
|
+
const filtersForNull = fieldSelector == null || fieldSelector.$exists === false;
|
|
36
|
+
const keys = filtersForNull
|
|
37
|
+
? { include: null, exclude: [...index.keys()].filter(key => key != null) }
|
|
38
|
+
: (0, getMatchingKeys_1.default)(field, flatSelector);
|
|
39
|
+
if (keys.include == null && keys.exclude == null)
|
|
40
|
+
return { matched: false };
|
|
41
|
+
let includedIds = [];
|
|
42
|
+
if (keys.include == null) {
|
|
43
|
+
for (const set of index.values()) {
|
|
44
|
+
for (const id of set)
|
|
45
|
+
includedIds.push(id);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
for (const key of keys.include) {
|
|
50
|
+
const idSet = index.get(key);
|
|
51
|
+
if (idSet) {
|
|
52
|
+
for (const id of idSet)
|
|
53
|
+
includedIds.push(id);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (keys.exclude != null) {
|
|
58
|
+
const excludedIds = new Set();
|
|
59
|
+
for (const key of keys.exclude) {
|
|
60
|
+
const idSet = index.get(key);
|
|
61
|
+
if (idSet) {
|
|
62
|
+
for (const id of idSet)
|
|
63
|
+
excludedIds.add(id);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
includedIds = includedIds.filter(id => !excludedIds.has(id));
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
matched: true,
|
|
70
|
+
ids: includedIds,
|
|
71
|
+
fields: [field],
|
|
72
|
+
keepSelector: filtersForNull,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters an array to ensure unique values based on a specified key or transformation function.
|
|
3
|
+
* @template T - The type of the elements in the array.
|
|
4
|
+
* @param array - The array to filter for unique values.
|
|
5
|
+
* @param fn - A key or transformation function to determine uniqueness.
|
|
6
|
+
* - If a key is provided, it will use the corresponding property of each element for uniqueness.
|
|
7
|
+
* - If a function is provided, it will use the return value of the function applied to each element for uniqueness.
|
|
8
|
+
* @returns A new array containing only unique elements based on the specified key or transformation.
|
|
9
|
+
*/
|
|
10
|
+
export default function uniqueBy<T>(array: T[], fn: keyof T | ((item: T) => any)): T[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = uniqueBy;
|
|
4
|
+
/**
|
|
5
|
+
* Filters an array to ensure unique values based on a specified key or transformation function.
|
|
6
|
+
* @template T - The type of the elements in the array.
|
|
7
|
+
* @param array - The array to filter for unique values.
|
|
8
|
+
* @param fn - A key or transformation function to determine uniqueness.
|
|
9
|
+
* - If a key is provided, it will use the corresponding property of each element for uniqueness.
|
|
10
|
+
* - If a function is provided, it will use the return value of the function applied to each element for uniqueness.
|
|
11
|
+
* @returns A new array containing only unique elements based on the specified key or transformation.
|
|
12
|
+
*/
|
|
13
|
+
function uniqueBy(array, fn) {
|
|
14
|
+
const set = new Set();
|
|
15
|
+
return array.filter((element) => {
|
|
16
|
+
const value = typeof fn === 'function' ? fn(element) : element[fn];
|
|
17
|
+
return !set.has(value) && set.add(value);
|
|
18
|
+
});
|
|
19
|
+
}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const reactivity = require("svelte/reactivity");
|
|
4
|
+
const core = require("@signaldb/core");
|
|
5
|
+
class SvelteDependency {
|
|
6
|
+
#subscribe;
|
|
7
|
+
#update;
|
|
8
|
+
#onDisposeCallbacks;
|
|
9
|
+
constructor() {
|
|
10
|
+
this.#onDisposeCallbacks = [];
|
|
11
|
+
this.#subscribe = reactivity.createSubscriber((update) => {
|
|
12
|
+
this.#update = update;
|
|
13
|
+
return () => this.dispose();
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
depend() {
|
|
17
|
+
this.#subscribe();
|
|
18
|
+
}
|
|
19
|
+
notify() {
|
|
20
|
+
this.#update?.();
|
|
21
|
+
}
|
|
22
|
+
onDispose(callback) {
|
|
23
|
+
this.#onDisposeCallbacks.push(callback);
|
|
24
|
+
}
|
|
25
|
+
dispose() {
|
|
26
|
+
this.#onDisposeCallbacks.forEach((callback) => callback());
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const svelteReactivityAdapter = core.createReactivityAdapter({
|
|
30
|
+
create: () => new SvelteDependency(),
|
|
31
|
+
isInScope: () => $effect.tracking(),
|
|
32
|
+
onDispose(callback, svelteDependency) {
|
|
33
|
+
svelteDependency.onDispose(callback);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
exports.SvelteDependency = SvelteDependency;
|
|
37
|
+
exports.default = svelteReactivityAdapter;
|
|
38
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../index.svelte.ts"],"sourcesContent":["import { createSubscriber } from 'svelte/reactivity'\nimport { createReactivityAdapter } from '@signaldb/core'\n\nexport class SvelteDependency {\n #subscribe: () => void\n #update: (() => void) | undefined\n #onDisposeCallbacks: (() => void)[]\n\n constructor() {\n this.#onDisposeCallbacks = []\n\n this.#subscribe = createSubscriber((update) => {\n this.#update = update\n return () => this.dispose()\n })\n }\n\n depend() {\n this.#subscribe()\n }\n\n notify() {\n // The #update can potentially be undefined because it only becomes\n // available after #subscribe is called for the first time within a scope.\n this.#update?.()\n }\n\n onDispose(callback: () => void) {\n this.#onDisposeCallbacks.push(callback)\n }\n\n dispose() {\n this.#onDisposeCallbacks.forEach(callback => callback())\n }\n}\n\nconst svelteReactivityAdapter = createReactivityAdapter({\n create: () => new SvelteDependency(),\n isInScope: () => $effect.tracking(),\n onDispose(callback, svelteDependency: SvelteDependency) {\n svelteDependency.onDispose(callback)\n },\n})\n\nexport default svelteReactivityAdapter\n"],"names":["createSubscriber","createReactivityAdapter"],"mappings":";;;;AAGO,MAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAc;AACZ,SAAK,sBAAsB,CAAA;AAE3B,SAAK,aAAaA,4BAAiB,CAAC,WAAW;AAC7C,WAAK,UAAU;AACf,aAAO,MAAM,KAAK,QAAA;AAAA,IACpB,CAAC;AAAA,EACH;AAAA,EAEA,SAAS;AACP,SAAK,WAAA;AAAA,EACP;AAAA,EAEA,SAAS;AAGP,SAAK,UAAA;AAAA,EACP;AAAA,EAEA,UAAU,UAAsB;AAC9B,SAAK,oBAAoB,KAAK,QAAQ;AAAA,EACxC;AAAA,EAEA,UAAU;AACR,SAAK,oBAAoB,QAAQ,CAAA,aAAY,SAAA,CAAU;AAAA,EACzD;AACF;AAEA,MAAM,0BAA0BC,KAAAA,wBAAwB;AAAA,EACtD,QAAQ,MAAM,IAAI,iBAAA;AAAA,EAClB,WAAW,MAAM,QAAQ,SAAA;AAAA,EACzB,UAAU,UAAU,kBAAoC;AACtD,qBAAiB,UAAU,QAAQ;AAAA,EACrC;AACF,CAAC;;;"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createSubscriber } from "svelte/reactivity";
|
|
2
|
+
import { createReactivityAdapter } from "@signaldb/core";
|
|
3
|
+
class SvelteDependency {
|
|
4
|
+
#subscribe;
|
|
5
|
+
#update;
|
|
6
|
+
#onDisposeCallbacks;
|
|
7
|
+
constructor() {
|
|
8
|
+
this.#onDisposeCallbacks = [];
|
|
9
|
+
this.#subscribe = createSubscriber((update) => {
|
|
10
|
+
this.#update = update;
|
|
11
|
+
return () => this.dispose();
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
depend() {
|
|
15
|
+
this.#subscribe();
|
|
16
|
+
}
|
|
17
|
+
notify() {
|
|
18
|
+
this.#update?.();
|
|
19
|
+
}
|
|
20
|
+
onDispose(callback) {
|
|
21
|
+
this.#onDisposeCallbacks.push(callback);
|
|
22
|
+
}
|
|
23
|
+
dispose() {
|
|
24
|
+
this.#onDisposeCallbacks.forEach((callback) => callback());
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const svelteReactivityAdapter = createReactivityAdapter({
|
|
28
|
+
create: () => new SvelteDependency(),
|
|
29
|
+
isInScope: () => $effect.tracking(),
|
|
30
|
+
onDispose(callback, svelteDependency) {
|
|
31
|
+
svelteDependency.onDispose(callback);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
export {
|
|
35
|
+
SvelteDependency,
|
|
36
|
+
svelteReactivityAdapter as default
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../index.svelte.ts"],"sourcesContent":["import { createSubscriber } from 'svelte/reactivity'\nimport { createReactivityAdapter } from '@signaldb/core'\n\nexport class SvelteDependency {\n #subscribe: () => void\n #update: (() => void) | undefined\n #onDisposeCallbacks: (() => void)[]\n\n constructor() {\n this.#onDisposeCallbacks = []\n\n this.#subscribe = createSubscriber((update) => {\n this.#update = update\n return () => this.dispose()\n })\n }\n\n depend() {\n this.#subscribe()\n }\n\n notify() {\n // The #update can potentially be undefined because it only becomes\n // available after #subscribe is called for the first time within a scope.\n this.#update?.()\n }\n\n onDispose(callback: () => void) {\n this.#onDisposeCallbacks.push(callback)\n }\n\n dispose() {\n this.#onDisposeCallbacks.forEach(callback => callback())\n }\n}\n\nconst svelteReactivityAdapter = createReactivityAdapter({\n create: () => new SvelteDependency(),\n isInScope: () => $effect.tracking(),\n onDispose(callback, svelteDependency: SvelteDependency) {\n svelteDependency.onDispose(callback)\n },\n})\n\nexport default svelteReactivityAdapter\n"],"names":[],"mappings":";;AAGO,MAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAc;AACZ,SAAK,sBAAsB,CAAA;AAE3B,SAAK,aAAa,iBAAiB,CAAC,WAAW;AAC7C,WAAK,UAAU;AACf,aAAO,MAAM,KAAK,QAAA;AAAA,IACpB,CAAC;AAAA,EACH;AAAA,EAEA,SAAS;AACP,SAAK,WAAA;AAAA,EACP;AAAA,EAEA,SAAS;AAGP,SAAK,UAAA;AAAA,EACP;AAAA,EAEA,UAAU,UAAsB;AAC9B,SAAK,oBAAoB,KAAK,QAAQ;AAAA,EACxC;AAAA,EAEA,UAAU;AACR,SAAK,oBAAoB,QAAQ,CAAA,aAAY,SAAA,CAAU;AAAA,EACzD;AACF;AAEA,MAAM,0BAA0B,wBAAwB;AAAA,EACtD,QAAQ,MAAM,IAAI,iBAAA;AAAA,EAClB,WAAW,MAAM,QAAQ,SAAA;AAAA,EACzB,UAAU,UAAU,kBAAoC;AACtD,qBAAiB,UAAU,QAAQ;AAAA,EACrC;AACF,CAAC;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class SvelteDependency {
|
|
2
|
+
#private;
|
|
3
|
+
constructor();
|
|
4
|
+
depend(): void;
|
|
5
|
+
notify(): void;
|
|
6
|
+
onDispose(callback: () => void): void;
|
|
7
|
+
dispose(): void;
|
|
8
|
+
}
|
|
9
|
+
declare const svelteReactivityAdapter: import("@signaldb/core").ReactivityAdapter<SvelteDependency>;
|
|
10
|
+
export default svelteReactivityAdapter;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createSubscriber } from 'svelte/reactivity';
|
|
2
|
+
import { createReactivityAdapter } from '@signaldb/core';
|
|
3
|
+
export class SvelteDependency {
|
|
4
|
+
#subscribe;
|
|
5
|
+
#update;
|
|
6
|
+
#onDisposeCallbacks;
|
|
7
|
+
constructor() {
|
|
8
|
+
this.#onDisposeCallbacks = [];
|
|
9
|
+
this.#subscribe = createSubscriber((update) => {
|
|
10
|
+
this.#update = update;
|
|
11
|
+
return () => this.dispose();
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
depend() {
|
|
15
|
+
this.#subscribe();
|
|
16
|
+
}
|
|
17
|
+
notify() {
|
|
18
|
+
// The #update can potentially be undefined because it only becomes
|
|
19
|
+
// available after #subscribe is called for the first time within a scope.
|
|
20
|
+
this.#update?.();
|
|
21
|
+
}
|
|
22
|
+
onDispose(callback) {
|
|
23
|
+
this.#onDisposeCallbacks.push(callback);
|
|
24
|
+
}
|
|
25
|
+
dispose() {
|
|
26
|
+
this.#onDisposeCallbacks.forEach(callback => callback());
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const svelteReactivityAdapter = createReactivityAdapter({
|
|
30
|
+
create: () => new SvelteDependency(),
|
|
31
|
+
isInScope: () => $effect.tracking(),
|
|
32
|
+
onDispose(callback, svelteDependency) {
|
|
33
|
+
svelteDependency.onDispose(callback);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
export default svelteReactivityAdapter;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signaldb/svelte",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.21",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc -d --noEmit false",
|
|
7
7
|
"analyze-bundle": "bundle-analyzer ./dist --upload-token=$BUNDLE_ANALYZER_UPLOAD_TOKEN --bundle-name=@signaldb/svelte",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"svelte": "^5.7.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@sveltejs/vite-plugin-svelte": "
|
|
49
|
-
"svelte": "5.
|
|
48
|
+
"@sveltejs/vite-plugin-svelte": "7.1.2",
|
|
49
|
+
"svelte": "5.56.1"
|
|
50
50
|
}
|
|
51
51
|
}
|