@anchorlib/svelte 1.0.0-beta.22 → 1.0.0-beta.24
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/{reactive.d.ts → client/index.d.ts} +1 -1
- package/dist/{reactive.js → client/index.js} +6 -5
- package/dist/index.d.ts +2 -12
- package/dist/index.js +3 -12
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +14 -0
- package/dist/storage/index.d.ts +1 -7
- package/dist/storage/index.js +0 -8
- package/package.json +14 -8
- package/readme.md +1 -1
- package/dist/anchor.d.ts +0 -86
- package/dist/anchor.js +0 -68
- package/dist/derive.d.ts +0 -17
- package/dist/derive.js +0 -34
- package/dist/fetch.d.ts +0 -62
- package/dist/fetch.js +0 -12
- package/dist/history.d.ts +0 -14
- package/dist/history.js +0 -16
- package/dist/immutable.d.ts +0 -49
- package/dist/immutable.js +0 -14
- package/dist/model.d.ts +0 -41
- package/dist/model.js +0 -20
- package/dist/observable.d.ts +0 -17
- package/dist/observable.js +0 -36
- package/dist/prop.d.ts +0 -21
- package/dist/prop.js +0 -19
- package/dist/ref.d.ts +0 -52
- package/dist/ref.js +0 -67
- package/dist/storage/kv.d.ts +0 -19
- package/dist/storage/kv.js +0 -26
- package/dist/storage/persistent.d.ts +0 -20
- package/dist/storage/persistent.js +0 -27
- package/dist/storage/session.d.ts +0 -20
- package/dist/storage/session.js +0 -27
- package/dist/storage/table.d.ts +0 -15
- package/dist/storage/table.js +0 -46
- package/dist/storage/types.d.ts +0 -16
- package/dist/storage/types.js +0 -0
- package/dist/types.d.ts +0 -12
- package/dist/types.js +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { createObserver, onGlobalCleanup, setCleanUpHandler, setTracker } from "@anchorlib/core";
|
|
1
|
+
import { anchor, createObserver, isBrowser, onGlobalCleanup, setCleanUpHandler, setTracker } from "@anchorlib/core";
|
|
2
2
|
import { onDestroy } from "svelte";
|
|
3
3
|
import { createSubscriber } from "svelte/reactivity";
|
|
4
4
|
|
|
5
|
-
//#region src/
|
|
5
|
+
//#region src/client/index.ts
|
|
6
|
+
anchor.configure({ globalScopeWarning: false });
|
|
6
7
|
const TRACKER_REGISTRY = /* @__PURE__ */ new WeakMap();
|
|
7
8
|
let bindingInitialized = false;
|
|
8
|
-
if (!bindingInitialized &&
|
|
9
|
+
if (!bindingInitialized && isBrowser()) {
|
|
9
10
|
bindingInitialized = true;
|
|
10
11
|
/**
|
|
11
12
|
* Sets up a tracker function that integrates Anchor's reactivity system with Svelte's reactivity.
|
|
@@ -19,7 +20,7 @@ if (!bindingInitialized && typeof window !== "undefined") {
|
|
|
19
20
|
setTracker((init, observers, key) => {
|
|
20
21
|
if (!TRACKER_REGISTRY.has(init)) {
|
|
21
22
|
let track;
|
|
22
|
-
const subscribe
|
|
23
|
+
const subscribe = createSubscriber((update) => {
|
|
23
24
|
const observer = createObserver(() => {
|
|
24
25
|
observer.reset();
|
|
25
26
|
update();
|
|
@@ -31,7 +32,7 @@ if (!bindingInitialized && typeof window !== "undefined") {
|
|
|
31
32
|
};
|
|
32
33
|
});
|
|
33
34
|
const assign = (prop) => {
|
|
34
|
-
subscribe
|
|
35
|
+
subscribe();
|
|
35
36
|
track?.(prop);
|
|
36
37
|
};
|
|
37
38
|
TRACKER_REGISTRY.set(init, assign);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { derivedRef } from "./derive.js";
|
|
4
|
-
import { fetchRef, streamRef } from "./fetch.js";
|
|
5
|
-
import { historyRef } from "./history.js";
|
|
6
|
-
import { immutableRef, writableRef } from "./immutable.js";
|
|
7
|
-
import { exceptionRef, modelRef } from "./model.js";
|
|
8
|
-
import { observedRef } from "./observable.js";
|
|
9
|
-
import { Props, PropsRef, propsRef } from "./prop.js";
|
|
10
|
-
import { REF_REGISTRY, constantRef, isRef, variableRef } from "./ref.js";
|
|
11
|
-
import { AnchorSettings, AsyncHandler, AsyncOptions, AsyncState, AsyncStatus, BatchHandler, Context, ContextProvider, Debouncer, DerivedRef, EffectHandler, FetchOptions, FetchState, FetchStatus, HistoryOptions, HistoryState, Immutable, ImmutableOutput, ImmutableRef, MicroBatch, MicroLooper, MicroPusher, MicroTask, ModelError, ModelInput, ModelObject, Mutable, MutablePart, MutableRef, PushHandler, State, StateChange, StateException, StateExceptionHandler, StateObserver, StateOptions, StateSubscriber, StateUnsubscribe, TaskHandler, Writable, anchor, debouncer, derived, effect, exception, fetchState, form, getContext, history, immutable, isImmutableRef, isMutableRef, isValueRef, microbatch, microloop, micropush, microtask, model, mutable, ordered, query, setContext, shortId, snapshot, streamState, stringify, subscribe, undoable, untrack, writable } from "@anchorlib/core";
|
|
12
|
-
export { type AnchorSettings, type AsyncHandler, type AsyncOptions, type AsyncState, AsyncStatus, type BatchHandler, ConstantRef, type Context, type ContextProvider, type Debouncer, DerivedRef, type EffectHandler, type FetchOptions, type FetchState, FetchStatus, type HistoryOptions, type HistoryState, type Immutable, type ImmutableOutput, ImmutableRef, type MicroBatch, type MicroLooper, type MicroPusher, type MicroTask, type ModelError, type ModelInput, type ModelObject, type Mutable, type MutablePart, MutableRef, Props, PropsRef, type PushHandler, REF_REGISTRY, type State, type StateChange, type StateException, type StateExceptionHandler, type StateObserver, type StateOptions, StateRef, type StateSubscriber, type StateUnsubscribe, type TaskHandler, VariableRef, type Writable, anchor, anchorRef, constantRef, debouncer, derived, derivedRef, effect, exception, exceptionRef, fetchRef, fetchState, flatRef, form, getContext, history, historyRef, immutable, immutableRef, isImmutableRef, isMutableRef, isRef, isValueRef, microbatch, microloop, micropush, microtask, model, modelRef, mutable, observedRef, ordered, orderedRef, propsRef, query, rawRef, reactiveRef, setContext, shortId, snapshot, streamRef, streamState, stringify, subscribe, undoable, untrack, variableRef, writable, writableRef };
|
|
1
|
+
import { ASYNC_STATUS, AnchorSettings, AsyncHandler, AsyncOptions, AsyncState, BatchHandler, CookieEntry, CookieJar, CookieOptions, Debouncer, DerivedRef, EffectHandler, FetchOptions, FetchState, FetchStatus, Future, HistoryOptions, HistoryState, Immutable, ImmutableOutput, ImmutableRef, MicroBatch, MicroLooper, MicroPusher, MicroTask, ModelError, ModelInput, ModelObject, Mutable, MutablePart, MutableRef, PushHandler, State, StateChange, StateException, StateExceptionHandler, StateObserver, StateOptions, StateSubscriber, StateUnsubscribe, TaskHandler, Writable, anchor, awaited, cookies, createContext, createLifecycle, debouncer, decodeCookies, derived, effect, encodeCookies, exception, fetchState, form, getContext, getCookieJar, history, immutable, isImmutableRef, isMutableRef, isValueRef, microbatch, microloop, micropush, microtask, model, mutable, ordered, plan, query, setContext, setCookieContext, setReactive, shortId, snapshot, streamState, stringify, subscribe, undoable, untrack, withIsolation, withScope, writable } from "@anchorlib/core";
|
|
2
|
+
export { ASYNC_STATUS, type AnchorSettings, type AsyncHandler, type AsyncOptions, type AsyncState, type BatchHandler, type CookieEntry, CookieJar, type CookieOptions, type Debouncer, DerivedRef, type EffectHandler, type FetchOptions, type FetchState, FetchStatus, type Future, type HistoryOptions, type HistoryState, type Immutable, type ImmutableOutput, ImmutableRef, type MicroBatch, type MicroLooper, type MicroPusher, type MicroTask, type ModelError, type ModelInput, type ModelObject, type Mutable, type MutablePart, MutableRef, type PushHandler, type State, type StateChange, type StateException, type StateExceptionHandler, type StateObserver, type StateOptions, type StateSubscriber, type StateUnsubscribe, type TaskHandler, type Writable, anchor, awaited, cookies, createContext, createLifecycle, debouncer, decodeCookies, derived, effect, encodeCookies, exception, fetchState, form, getContext, getCookieJar, history, immutable, isImmutableRef, isMutableRef, isValueRef, microbatch, microloop, micropush, microtask, model, mutable, ordered, plan, query, setContext, setCookieContext, setReactive, shortId, snapshot, streamState, stringify, subscribe, undoable, untrack, withIsolation, withScope, writable };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { derivedRef } from "./derive.js";
|
|
4
|
-
import { fetchRef, streamRef } from "./fetch.js";
|
|
5
|
-
import { historyRef } from "./history.js";
|
|
6
|
-
import { immutableRef, writableRef } from "./immutable.js";
|
|
7
|
-
import "./reactive.js";
|
|
8
|
-
import { exceptionRef, modelRef } from "./model.js";
|
|
9
|
-
import { observedRef } from "./observable.js";
|
|
10
|
-
import { propsRef } from "./prop.js";
|
|
11
|
-
import { AsyncStatus, DerivedRef, FetchStatus, ImmutableRef, MutableRef, anchor, debouncer, derived, effect, exception, fetchState, form, getContext, history, immutable, isImmutableRef, isMutableRef, isValueRef, microbatch, microloop, micropush, microtask, model, mutable, ordered, query, setContext, shortId, snapshot, streamState, stringify, subscribe, undoable, untrack, writable } from "@anchorlib/core";
|
|
1
|
+
import "./client/index.js";
|
|
2
|
+
import { ASYNC_STATUS, CookieJar, DerivedRef, FetchStatus, ImmutableRef, MutableRef, anchor, awaited, cookies, createContext, createLifecycle, debouncer, decodeCookies, derived, effect, encodeCookies, exception, fetchState, form, getContext, getCookieJar, history, immutable, isImmutableRef, isMutableRef, isValueRef, microbatch, microloop, micropush, microtask, model, mutable, ordered, plan, query, setContext, setCookieContext, setReactive, shortId, snapshot, streamState, stringify, subscribe, undoable, untrack, withIsolation, withScope, writable } from "@anchorlib/core";
|
|
12
3
|
|
|
13
|
-
export {
|
|
4
|
+
export { ASYNC_STATUS, CookieJar, DerivedRef, FetchStatus, ImmutableRef, MutableRef, anchor, awaited, cookies, createContext, createLifecycle, debouncer, decodeCookies, derived, effect, encodeCookies, exception, fetchState, form, getContext, getCookieJar, history, immutable, isImmutableRef, isMutableRef, isValueRef, microbatch, microloop, micropush, microtask, model, mutable, ordered, plan, query, setContext, setCookieContext, setReactive, shortId, snapshot, streamState, stringify, subscribe, undoable, untrack, withIsolation, withScope, writable };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isBrowser, setAsyncScope, setReactive } from "@anchorlib/core";
|
|
2
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
+
|
|
4
|
+
//#region src/server/index.ts
|
|
5
|
+
var AnchorASL = class extends AsyncLocalStorage {
|
|
6
|
+
store = /* @__PURE__ */ new Map();
|
|
7
|
+
getStore() {
|
|
8
|
+
return super.getStore() ?? this.store;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
setAsyncScope(new AnchorASL());
|
|
12
|
+
if (!isBrowser()) setReactive(false);
|
|
13
|
+
|
|
14
|
+
//#endregion
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
import { kvRef } from "./kv.js";
|
|
2
|
-
import { persistentRef } from "./persistent.js";
|
|
3
|
-
import { sessionRef } from "./session.js";
|
|
4
|
-
import { InferListRef, InferRef, TableRef } from "./types.js";
|
|
5
|
-
import { createTableRef } from "./table.js";
|
|
6
1
|
export * from "@anchorlib/storage";
|
|
7
|
-
export * from "@anchorlib/storage/db";
|
|
8
|
-
export { InferListRef, InferRef, TableRef, createTableRef, kvRef, persistentRef, sessionRef };
|
|
2
|
+
export * from "@anchorlib/storage/db";
|
package/dist/storage/index.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import "../reactive.js";
|
|
2
|
-
import { kvRef } from "./kv.js";
|
|
3
|
-
import { persistentRef } from "./persistent.js";
|
|
4
|
-
import { sessionRef } from "./session.js";
|
|
5
|
-
import { createTableRef } from "./table.js";
|
|
6
|
-
|
|
7
1
|
export * from "@anchorlib/storage"
|
|
8
2
|
|
|
9
3
|
export * from "@anchorlib/storage/db"
|
|
10
|
-
|
|
11
|
-
export { createTableRef, kvRef, persistentRef, sessionRef };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anchorlib/svelte",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.24",
|
|
4
4
|
"description": "Svelte bindings for Anchor reactive state management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"state",
|
|
@@ -29,10 +29,15 @@
|
|
|
29
29
|
"svelte": "./dist/index.js",
|
|
30
30
|
"import": "./dist/index.js"
|
|
31
31
|
},
|
|
32
|
+
"./client": {
|
|
33
|
+
"types": "./dist/client/index.d.ts",
|
|
34
|
+
"svelte": "./dist/client/index.js",
|
|
35
|
+
"import": "./dist/client/index.js"
|
|
36
|
+
},
|
|
32
37
|
"./reactive": {
|
|
33
|
-
"types": "./dist/
|
|
34
|
-
"svelte": "./dist/
|
|
35
|
-
"import": "./dist/
|
|
38
|
+
"types": "./dist/client/index.d.ts",
|
|
39
|
+
"svelte": "./dist/client/index.js",
|
|
40
|
+
"import": "./dist/client/index.js"
|
|
36
41
|
},
|
|
37
42
|
"./core": {
|
|
38
43
|
"types": "./dist/core/index.d.ts",
|
|
@@ -55,14 +60,15 @@
|
|
|
55
60
|
"access": "public"
|
|
56
61
|
},
|
|
57
62
|
"dependencies": {
|
|
58
|
-
"@anchorlib/core": "^1.0.0-beta.
|
|
59
|
-
"@anchorlib/storage": "^1.0.0-beta.
|
|
63
|
+
"@anchorlib/core": "^1.0.0-beta.24",
|
|
64
|
+
"@anchorlib/storage": "^1.0.0-beta.24"
|
|
60
65
|
},
|
|
61
66
|
"devDependencies": {
|
|
62
67
|
"@biomejs/biome": "2.3.3",
|
|
63
|
-
"@sveltejs/vite-plugin-svelte": "
|
|
68
|
+
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
|
64
69
|
"@testing-library/svelte": "5.2.8",
|
|
65
70
|
"@testing-library/user-event": "14.6.1",
|
|
71
|
+
"@types/bun": "1.3.1",
|
|
66
72
|
"@types/react": "^19.1.0",
|
|
67
73
|
"@vitest/coverage-v8": "^3.2.4",
|
|
68
74
|
"@vitest/ui": "^3.2.4",
|
|
@@ -70,7 +76,7 @@
|
|
|
70
76
|
"publint": "0.3.15",
|
|
71
77
|
"rimraf": "6.0.1",
|
|
72
78
|
"tsdown": "0.15.9",
|
|
73
|
-
"vite": "
|
|
79
|
+
"vite": "8.0.10",
|
|
74
80
|
"vitest": "^3.2.4"
|
|
75
81
|
},
|
|
76
82
|
"peerDependencies": {
|
package/readme.md
CHANGED
|
@@ -10,7 +10,7 @@ npm install @anchorlib/svelte
|
|
|
10
10
|
|
|
11
11
|
## Documentation
|
|
12
12
|
|
|
13
|
-
For full documentation, visit [Anchor for Svelte](https://
|
|
13
|
+
For full documentation, visit [Anchor for Svelte](https://airlib.dev/svelte/introduction.html)
|
|
14
14
|
|
|
15
15
|
## Quick Start
|
|
16
16
|
|
package/dist/anchor.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { Immutable, Linkable, LinkableSchema, ModelArray, ModelInput, ModelOutput, StateOptions } from "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/anchor.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use 'mutable()' instead.
|
|
7
|
-
* Creates a reactive state that can be used to manage state with Anchor.
|
|
8
|
-
* This overload is used when no schema is provided, or when using a LinkableSchema with StateOptions.
|
|
9
|
-
*
|
|
10
|
-
* @template T - The type of the initial value
|
|
11
|
-
* @template S - The schema type, extending LinkableSchema
|
|
12
|
-
* @param init - The initial value for the state
|
|
13
|
-
* @param options - Optional state options for the state
|
|
14
|
-
* @returns A reactive state containing the initial value
|
|
15
|
-
*/
|
|
16
|
-
declare function anchorRef<T extends Linkable, S extends LinkableSchema = LinkableSchema>(init: T, options?: StateOptions<S>): T;
|
|
17
|
-
/**
|
|
18
|
-
* @deprecated Use 'mutable()' instead.
|
|
19
|
-
* Creates a reactive state with a defined schema for validation and type inference.
|
|
20
|
-
*
|
|
21
|
-
* @template S - The schema type, extending LinkableSchema
|
|
22
|
-
* @template T - The type of the initial value, must extend ModelInput of the schema
|
|
23
|
-
* @param init - The initial value for the state
|
|
24
|
-
* @param schema - The schema to validate and type the state
|
|
25
|
-
* @param options - Optional state options for the state
|
|
26
|
-
* @returns A reactive state containing the output model based on the schema
|
|
27
|
-
*/
|
|
28
|
-
declare function anchorRef<S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema?: S, options?: StateOptions): ModelOutput<S>;
|
|
29
|
-
/**
|
|
30
|
-
* @deprecated Use 'mutable()' instead.
|
|
31
|
-
* Creates an immutable reactive state with a defined schema.
|
|
32
|
-
*
|
|
33
|
-
* @template S - The schema type, extending LinkableSchema
|
|
34
|
-
* @template T - The type of the initial value, must extend ModelInput of the schema
|
|
35
|
-
* @param init - The initial value for the state
|
|
36
|
-
* @param schema - The schema to validate and type the state
|
|
37
|
-
* @param options - State options with immutable flag set to true
|
|
38
|
-
* @returns A reactive state containing an immutable output model based on the schema
|
|
39
|
-
*/
|
|
40
|
-
declare function anchorRef<S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema?: S, options?: StateOptions & {
|
|
41
|
-
immutable: true;
|
|
42
|
-
}): Immutable<ModelOutput<S>>;
|
|
43
|
-
/**
|
|
44
|
-
* @deprecated Use 'mutable()' instead.
|
|
45
|
-
* Reactive state alias for anchorRef.
|
|
46
|
-
* @type {{<T, S=LinkableSchema extends LinkableSchema>(init: T, options?: StateOptions<S>): T, <S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema?: S, options?: StateOptions): ModelOutput<S>, <S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema?: S, options?: (StateOptions & {immutable: true})): Immutable<ModelOutput<S>>}}
|
|
47
|
-
*/
|
|
48
|
-
declare const reactiveRef: typeof anchorRef;
|
|
49
|
-
/**
|
|
50
|
-
* @deprecated Use 'ordered()' instead.
|
|
51
|
-
* Creates a reactive state that maintains a sorted array state based on a comparison function.
|
|
52
|
-
*
|
|
53
|
-
* @template T - The type of elements in the array
|
|
54
|
-
* @template S - The schema type for array elements, extending ModelArray
|
|
55
|
-
* @param init - The initial array value for the state
|
|
56
|
-
* @param compare - A function that defines the sort order of elements
|
|
57
|
-
* @param options - Optional state options for the state
|
|
58
|
-
* @returns A reactive state containing the sorted array
|
|
59
|
-
*/
|
|
60
|
-
declare function orderedRef<T extends unknown[], S extends ModelArray = ModelArray>(init: T, compare: (a: T[number], b: T[number]) => number, options?: StateOptions<S>): T;
|
|
61
|
-
/**
|
|
62
|
-
* @deprecated Use 'flat()' instead.
|
|
63
|
-
* Creates a reactive state that maintains a flat array state.
|
|
64
|
-
*
|
|
65
|
-
* @template T - The type of elements in the array
|
|
66
|
-
* @template S - The schema type for array elements, extending ModelArray
|
|
67
|
-
* @param init - The initial array value for the state
|
|
68
|
-
* @param options - Optional state options for the state
|
|
69
|
-
* @returns A reactive state containing the flat array
|
|
70
|
-
*/
|
|
71
|
-
declare function flatRef<T extends unknown[], S extends ModelArray = ModelArray>(init: T, options?: StateOptions<S>): T;
|
|
72
|
-
/**
|
|
73
|
-
* @deprecated Use 'raw()' instead.
|
|
74
|
-
* Creates a reactive state that mutates the underlying object.
|
|
75
|
-
*
|
|
76
|
-
* Unless you set the global options to `cloned: true`, you don't want to use this.
|
|
77
|
-
*
|
|
78
|
-
* @template T - The type of the initial value
|
|
79
|
-
* @template S - The schema type, extending LinkableSchema
|
|
80
|
-
* @param init - The initial value for the state
|
|
81
|
-
* @param options - Optional state options for the state
|
|
82
|
-
* @returns A reactive state containing the raw value
|
|
83
|
-
*/
|
|
84
|
-
declare function rawRef<T extends Linkable, S extends LinkableSchema = LinkableSchema>(init: T, options?: StateOptions<S>): T;
|
|
85
|
-
//#endregion
|
|
86
|
-
export { anchorRef, flatRef, orderedRef, rawRef, reactiveRef };
|
package/dist/anchor.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { anchor } from "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/anchor.ts
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated Use 'mutable()' instead.
|
|
6
|
-
* Creates a reactive state for state management with optional schema validation.
|
|
7
|
-
*
|
|
8
|
-
* @template T - The type of the initial value
|
|
9
|
-
* @template S - The schema type or options
|
|
10
|
-
* @param init - The initial value for the state
|
|
11
|
-
* @param schemaOptions - Either a schema or state options
|
|
12
|
-
* @param options - Additional state options when schema is provided
|
|
13
|
-
* @returns A reactive state containing the managed state
|
|
14
|
-
*/
|
|
15
|
-
function anchorRef(init, schemaOptions, options) {
|
|
16
|
-
return anchor(init, schemaOptions, options);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated Use 'mutable()' instead.
|
|
20
|
-
* Reactive state alias for anchorRef.
|
|
21
|
-
* @type {{<T, S=LinkableSchema extends LinkableSchema>(init: T, options?: StateOptions<S>): T, <S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema?: S, options?: StateOptions): ModelOutput<S>, <S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema?: S, options?: (StateOptions & {immutable: true})): Immutable<ModelOutput<S>>}}
|
|
22
|
-
*/
|
|
23
|
-
const reactiveRef = anchorRef;
|
|
24
|
-
/**
|
|
25
|
-
* @deprecated Use 'ordered()' instead.
|
|
26
|
-
* Creates a reactive state that maintains a sorted array state based on a comparison function.
|
|
27
|
-
*
|
|
28
|
-
* @template T - The type of elements in the array
|
|
29
|
-
* @template S - The schema type for array elements, extending ModelArray
|
|
30
|
-
* @param init - The initial array value for the state
|
|
31
|
-
* @param compare - A function that defines the sort order of elements
|
|
32
|
-
* @param options - Optional state options for the state
|
|
33
|
-
* @returns A reactive state containing the sorted array
|
|
34
|
-
*/
|
|
35
|
-
function orderedRef(init, compare, options) {
|
|
36
|
-
return anchor.ordered(init, compare, options);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @deprecated Use 'flat()' instead.
|
|
40
|
-
* Creates a reactive state that maintains a flat array state.
|
|
41
|
-
*
|
|
42
|
-
* @template T - The type of elements in the array
|
|
43
|
-
* @template S - The schema type for array elements, extending ModelArray
|
|
44
|
-
* @param init - The initial array value for the state
|
|
45
|
-
* @param options - Optional state options for the state
|
|
46
|
-
* @returns A reactive state containing the flat array
|
|
47
|
-
*/
|
|
48
|
-
function flatRef(init, options) {
|
|
49
|
-
return anchor.flat(init, options);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @deprecated Use 'raw()' instead.
|
|
53
|
-
* Creates a reactive state that mutates the underlying object.
|
|
54
|
-
*
|
|
55
|
-
* Unless you set the global options to `cloned: true`, you don't want to use this.
|
|
56
|
-
*
|
|
57
|
-
* @template T - The type of the initial value
|
|
58
|
-
* @template S - The schema type, extending LinkableSchema
|
|
59
|
-
* @param init - The initial value for the state
|
|
60
|
-
* @param options - Optional state options for the state
|
|
61
|
-
* @returns A reactive state containing the raw value
|
|
62
|
-
*/
|
|
63
|
-
function rawRef(init, options) {
|
|
64
|
-
return anchor.raw(init, options);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
//#endregion
|
|
68
|
-
export { anchorRef, flatRef, orderedRef, rawRef, reactiveRef };
|
package/dist/derive.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ConstantRef } from "./types.js";
|
|
2
|
-
|
|
3
|
-
//#region src/derive.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use `derived()` instead.
|
|
7
|
-
* Creates a derived state from a source state with an optional transformation.
|
|
8
|
-
*
|
|
9
|
-
* @template T - The type of the input state
|
|
10
|
-
* @template R - The type of the transformed output
|
|
11
|
-
* @param state - The source state
|
|
12
|
-
* @param derive - A function that transforms the current state value
|
|
13
|
-
* @returns A read-only reference containing the derived state value
|
|
14
|
-
*/
|
|
15
|
-
declare function derivedRef<T, R>(state: T, derive: (current: T) => R): ConstantRef<R>;
|
|
16
|
-
//#endregion
|
|
17
|
-
export { derivedRef };
|
package/dist/derive.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { REF_REGISTRY } from "./ref.js";
|
|
2
|
-
import { anchor, subscribe } from "@anchorlib/core";
|
|
3
|
-
import { onDestroy } from "svelte";
|
|
4
|
-
|
|
5
|
-
//#region src/derive.ts
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated Use `derived()` instead.
|
|
8
|
-
* Creates a derived state from a source state with an optional transformation.
|
|
9
|
-
*
|
|
10
|
-
* @template T - The type of the input state
|
|
11
|
-
* @template R - The type of the transformed output
|
|
12
|
-
* @param state - The source state
|
|
13
|
-
* @param derive - A function that transforms the current state value
|
|
14
|
-
* @returns A read-only reference containing the derived state value
|
|
15
|
-
*/
|
|
16
|
-
function derivedRef(state, derive) {
|
|
17
|
-
const valueRef = anchor({}, { recursive: false });
|
|
18
|
-
const stateRef = { get value() {
|
|
19
|
-
return valueRef.value;
|
|
20
|
-
} };
|
|
21
|
-
REF_REGISTRY.set(stateRef, valueRef);
|
|
22
|
-
const unsubscribe = subscribe(state, (current) => {
|
|
23
|
-
valueRef.value = derive(current);
|
|
24
|
-
});
|
|
25
|
-
onDestroy(() => {
|
|
26
|
-
anchor.destroy(valueRef);
|
|
27
|
-
unsubscribe();
|
|
28
|
-
REF_REGISTRY.delete(stateRef);
|
|
29
|
-
});
|
|
30
|
-
return stateRef;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
export { derivedRef };
|
package/dist/fetch.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { FetchOptions, FetchState, StreamOptions } from "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/fetch.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use 'fetchState()' or 'asyncState()' instead.
|
|
7
|
-
* Creates a reactive state that manages the state of a fetch request.
|
|
8
|
-
* This overload is for GET or DELETE requests, which typically do not have a request body.
|
|
9
|
-
*
|
|
10
|
-
* @template R The type of the data expected in the response.
|
|
11
|
-
* @param init The initial value for the fetch state.
|
|
12
|
-
* @param options The options for the fetch request, including the URL and method.
|
|
13
|
-
* @returns A `FetchState` object representing the state of the request.
|
|
14
|
-
*/
|
|
15
|
-
declare function fetchRef<R>(init: R, options: FetchOptions & {
|
|
16
|
-
method: 'GET' | 'DELETE';
|
|
17
|
-
}): FetchState<R>;
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated Use 'fetchState()' or 'asyncState()' instead.
|
|
20
|
-
* Creates a readable Svelte store that manages the state of a fetch request.
|
|
21
|
-
* This overload is for POST, PUT, or PATCH requests, which typically include a request body.
|
|
22
|
-
*
|
|
23
|
-
* @template R The type of the data expected in the response.
|
|
24
|
-
* @template P The type of the request body.
|
|
25
|
-
* @param init The initial value for the fetch state.
|
|
26
|
-
* @param options The options for the fetch request, including the URL, method, and body.
|
|
27
|
-
* @returns A `FetchState` object representing the state of the request.
|
|
28
|
-
*/
|
|
29
|
-
declare function fetchRef<R, P>(init: R, options: FetchOptions & {
|
|
30
|
-
method: 'POST' | 'PUT' | 'PATCH';
|
|
31
|
-
body: P;
|
|
32
|
-
}): FetchState<R>;
|
|
33
|
-
/**
|
|
34
|
-
* @deprecated Use 'streamState()' instead.
|
|
35
|
-
* Creates a reactive state that manages the state of a streaming request.
|
|
36
|
-
* This overload is for GET or DELETE requests, which typically do not have a request body.
|
|
37
|
-
*
|
|
38
|
-
* @template R The type of the data expected in the response.
|
|
39
|
-
* @param init The initial value for the fetch state.
|
|
40
|
-
* @param options The options for the stream request, including the URL and method.
|
|
41
|
-
* @returns A `FetchState` object representing the state of the request.
|
|
42
|
-
*/
|
|
43
|
-
declare function streamRef<R>(init: R, options: StreamOptions<R> & {
|
|
44
|
-
method: 'GET' | 'DELETE';
|
|
45
|
-
}): FetchState<R>;
|
|
46
|
-
/**
|
|
47
|
-
* @deprecated Use 'streamState()' instead.
|
|
48
|
-
* Creates a reactive state that manages the state of a streaming request.
|
|
49
|
-
* This overload is for POST, PUT, or PATCH requests, which typically include a request body.
|
|
50
|
-
*
|
|
51
|
-
* @template R The type of the data expected in the response.
|
|
52
|
-
* @template P The type of the request body.
|
|
53
|
-
* @param init The initial value for the fetch state.
|
|
54
|
-
* @param options The options for the stream request, including the URL, method, and body.
|
|
55
|
-
* @returns A `FetchState` object representing the state of the request.
|
|
56
|
-
*/
|
|
57
|
-
declare function streamRef<R, P>(init: R, options: StreamOptions<R> & {
|
|
58
|
-
method: 'POST' | 'PUT' | 'PATCH';
|
|
59
|
-
body: P;
|
|
60
|
-
}): FetchState<R>;
|
|
61
|
-
//#endregion
|
|
62
|
-
export { fetchRef, streamRef };
|
package/dist/fetch.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { fetchState, streamState } from "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/fetch.ts
|
|
4
|
-
function fetchRef(init, options) {
|
|
5
|
-
return fetchState(init, options);
|
|
6
|
-
}
|
|
7
|
-
function streamRef(init, options) {
|
|
8
|
-
return streamState(init, options);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
export { fetchRef, streamRef };
|
package/dist/history.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { HistoryOptions, HistoryState, State } from "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/history.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use 'history()' instead.
|
|
7
|
-
* Creates a reactive state that reflects the history state of a given Anchor state.
|
|
8
|
-
* @param state The initial Anchor state.
|
|
9
|
-
* @param options Optional history options.
|
|
10
|
-
* @returns A `HistoryState` object representing the state of the history.
|
|
11
|
-
*/
|
|
12
|
-
declare function historyRef<T extends State>(state: T, options?: HistoryOptions): HistoryState;
|
|
13
|
-
//#endregion
|
|
14
|
-
export { historyRef };
|
package/dist/history.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { history } from "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/history.ts
|
|
4
|
-
/**
|
|
5
|
-
* @deprecated Use 'history()' instead.
|
|
6
|
-
* Creates a reactive state that reflects the history state of a given Anchor state.
|
|
7
|
-
* @param state The initial Anchor state.
|
|
8
|
-
* @param options Optional history options.
|
|
9
|
-
* @returns A `HistoryState` object representing the state of the history.
|
|
10
|
-
*/
|
|
11
|
-
function historyRef(state, options) {
|
|
12
|
-
return history(state, options);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { historyRef };
|
package/dist/immutable.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Immutable, ImmutableOutput, LinkableSchema, ModelInput, Mutable, MutablePart, MutationKey, State, StateBaseOptions, StateOptions } from "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/immutable.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use 'immutable()' instead.
|
|
7
|
-
* Creates an immutable state from a state object.
|
|
8
|
-
*
|
|
9
|
-
* @template T The type of the state object.
|
|
10
|
-
* @template S The type of the linkable schema.
|
|
11
|
-
* @param init The initial state object.
|
|
12
|
-
* @param options Optional state options.
|
|
13
|
-
* @returns An immutable state.
|
|
14
|
-
*/
|
|
15
|
-
declare function immutableRef<T extends State, S extends LinkableSchema = LinkableSchema>(init: T, options?: StateOptions<S>): Immutable<T>;
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated Use 'immutable()' instead.
|
|
18
|
-
* Creates an immutable state from a model input and a schema.
|
|
19
|
-
*
|
|
20
|
-
* @template S The type of the linkable schema.
|
|
21
|
-
* @template T The type of the model input.
|
|
22
|
-
* @param init The initial model input.
|
|
23
|
-
* @param schema The linkable schema.
|
|
24
|
-
* @param options Optional base state options.
|
|
25
|
-
* @returns An immutable state.
|
|
26
|
-
*/
|
|
27
|
-
declare function immutableRef<S extends LinkableSchema, T extends ModelInput<S>>(init: T, schema: S, options?: StateBaseOptions): ImmutableOutput<S>;
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated Use 'writable()' instead.
|
|
30
|
-
* Creates a writable state from a state object.
|
|
31
|
-
*
|
|
32
|
-
* @template T The type of the state object.
|
|
33
|
-
* @param state The initial state object.
|
|
34
|
-
* @returns A mutable state.
|
|
35
|
-
*/
|
|
36
|
-
declare function writableRef<T extends State>(state: T): Mutable<T>;
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated Use 'writable()' instead.
|
|
39
|
-
* Creates a writable state from a state object and a list of contracts.
|
|
40
|
-
*
|
|
41
|
-
* @template T The type of the state object.
|
|
42
|
-
* @template K The type of the mutation keys.
|
|
43
|
-
* @param state The initial state object.
|
|
44
|
-
* @param contracts A list of mutation keys.
|
|
45
|
-
* @returns A mutable part of the state.
|
|
46
|
-
*/
|
|
47
|
-
declare function writableRef<T extends State, K extends MutationKey<T>[]>(state: T, contracts: K): MutablePart<T, K>;
|
|
48
|
-
//#endregion
|
|
49
|
-
export { immutableRef, writableRef };
|
package/dist/immutable.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { anchor } from "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/immutable.ts
|
|
4
|
-
/** Implementation of `immutableRef` overloads. */
|
|
5
|
-
function immutableRef(init, schemaOptions, options) {
|
|
6
|
-
return anchor.immutable(init, schemaOptions, options);
|
|
7
|
-
}
|
|
8
|
-
/** Implementation of `writableRef` overloads. */
|
|
9
|
-
function writableRef(state, contracts) {
|
|
10
|
-
return anchor.writable(state, contracts);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
export { immutableRef, writableRef };
|
package/dist/model.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ImmutableOutput, LinkableSchema, ModelInput, ModelOutput, ObjLike, StateBaseOptions, StateExceptionMap } from "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/model.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use 'model()' instead.
|
|
7
|
-
* Creates a model with mutable state.
|
|
8
|
-
*
|
|
9
|
-
* @template S - The linkable schema type
|
|
10
|
-
* @template T - The model input type that extends the schema
|
|
11
|
-
* @param schema - The schema to use for the model
|
|
12
|
-
* @param init - The initial value for the model
|
|
13
|
-
* @param options - Optional state configuration
|
|
14
|
-
* @returns A model output.
|
|
15
|
-
*/
|
|
16
|
-
declare function modelRef<S extends LinkableSchema, T extends ModelInput<S>>(schema: S, init: T, options?: StateBaseOptions): ModelOutput<S>;
|
|
17
|
-
/**
|
|
18
|
-
* @deprecated Use 'model()' instead.
|
|
19
|
-
* Creates a model with immutable state.
|
|
20
|
-
*
|
|
21
|
-
* @template S - The linkable schema type
|
|
22
|
-
* @template T - The model input type that extends the schema
|
|
23
|
-
* @param schema - The schema to use for the model
|
|
24
|
-
* @param init - The initial value for the model
|
|
25
|
-
* @param options - State configuration with immutable flag set to true
|
|
26
|
-
* @returns An immutable model output.
|
|
27
|
-
*/
|
|
28
|
-
declare function modelRef<S extends LinkableSchema, T extends ModelInput<S>>(schema: S, init: T, options: StateBaseOptions & {
|
|
29
|
-
immutable: true;
|
|
30
|
-
}): ImmutableOutput<S>;
|
|
31
|
-
/**
|
|
32
|
-
* @deprecated Use 'exception()' instead.
|
|
33
|
-
* Creates a state that maps exceptions for a given state object or array.
|
|
34
|
-
*
|
|
35
|
-
* @template T - The type of the input state, must be an object-like or array type
|
|
36
|
-
* @param state - The input state object or array to create exception mappings for
|
|
37
|
-
* @returns A StateExceptionMap for the provided state.
|
|
38
|
-
*/
|
|
39
|
-
declare function exceptionRef<T extends ObjLike | Array<unknown>>(state: T): StateExceptionMap<T>;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { exceptionRef, modelRef };
|
package/dist/model.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { anchor } from "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/model.ts
|
|
4
|
-
function modelRef(schema, init, options) {
|
|
5
|
-
return anchor(init, schema, options);
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated Use 'exception()' instead.
|
|
9
|
-
* Creates a state that maps exceptions for a given state object or array.
|
|
10
|
-
*
|
|
11
|
-
* @template T - The type of the input state, must be an object-like or array type
|
|
12
|
-
* @param state - The input state object or array to create exception mappings for
|
|
13
|
-
* @returns A StateExceptionMap for the provided state.
|
|
14
|
-
*/
|
|
15
|
-
function exceptionRef(state) {
|
|
16
|
-
return anchor.catch(state);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
export { exceptionRef, modelRef };
|
package/dist/observable.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ConstantRef } from "./types.js";
|
|
2
|
-
|
|
3
|
-
//#region src/observable.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated use `effect()` instead.
|
|
7
|
-
* Creates a read-only reference that observes a reactive function and updates its value
|
|
8
|
-
* when the observed value changes. The function automatically handles observer lifecycle
|
|
9
|
-
* and cleanup using Svelte's onDestroy hook.
|
|
10
|
-
*
|
|
11
|
-
* @template R - The type of the observed value
|
|
12
|
-
* @param observe - A function that returns the value to be observed
|
|
13
|
-
* @returns A read-only reference containing the observed value
|
|
14
|
-
*/
|
|
15
|
-
declare function observedRef<R>(observe: () => R): ConstantRef<R>;
|
|
16
|
-
//#endregion
|
|
17
|
-
export { observedRef };
|
package/dist/observable.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { REF_REGISTRY } from "./ref.js";
|
|
2
|
-
import { anchor, createObserver } from "@anchorlib/core";
|
|
3
|
-
import { onDestroy } from "svelte";
|
|
4
|
-
|
|
5
|
-
//#region src/observable.ts
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated use `effect()` instead.
|
|
8
|
-
* Creates a read-only reference that observes a reactive function and updates its value
|
|
9
|
-
* when the observed value changes. The function automatically handles observer lifecycle
|
|
10
|
-
* and cleanup using Svelte's onDestroy hook.
|
|
11
|
-
*
|
|
12
|
-
* @template R - The type of the observed value
|
|
13
|
-
* @param observe - A function that returns the value to be observed
|
|
14
|
-
* @returns A read-only reference containing the observed value
|
|
15
|
-
*/
|
|
16
|
-
function observedRef(observe) {
|
|
17
|
-
const observer = createObserver(() => {
|
|
18
|
-
update();
|
|
19
|
-
});
|
|
20
|
-
const valueRef = anchor({ value: observer.run(observe) }, { recursive: false });
|
|
21
|
-
const stateRef = { get value() {
|
|
22
|
-
return valueRef.value;
|
|
23
|
-
} };
|
|
24
|
-
REF_REGISTRY.set(stateRef, valueRef);
|
|
25
|
-
const update = () => {
|
|
26
|
-
valueRef.value = observer.run(observe);
|
|
27
|
-
};
|
|
28
|
-
onDestroy(() => {
|
|
29
|
-
observer.destroy();
|
|
30
|
-
REF_REGISTRY.delete(stateRef);
|
|
31
|
-
});
|
|
32
|
-
return stateRef;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
export { observedRef };
|
package/dist/prop.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ConstantRef } from "./types.js";
|
|
2
|
-
import { KeyLike, State } from "@anchorlib/core";
|
|
3
|
-
|
|
4
|
-
//#region src/prop.d.ts
|
|
5
|
-
type Props = {
|
|
6
|
-
[key: string]: KeyLike | State;
|
|
7
|
-
};
|
|
8
|
-
type PropsRef<T extends Props> = { [K in keyof T]: T[K] extends State ? ConstantRef<T[K]> : T[K] };
|
|
9
|
-
/**
|
|
10
|
-
* Creates a reactive state object from the provided props.
|
|
11
|
-
* For each property in the input props:
|
|
12
|
-
* - If the value is a State object, it will be converted to a derived state
|
|
13
|
-
* - Otherwise, the value will be kept as is
|
|
14
|
-
* @deprecated
|
|
15
|
-
* @template T - The type of props extending Props
|
|
16
|
-
* @param {T} props - The input props object containing KeyLike or State values
|
|
17
|
-
* @returns {PropsRef<T>} A new object with State values converted to reactive states
|
|
18
|
-
*/
|
|
19
|
-
declare function propsRef<T extends Props>(props: T): T;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { Props, PropsRef, propsRef };
|
package/dist/prop.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/prop.ts
|
|
4
|
-
/**
|
|
5
|
-
* Creates a reactive state object from the provided props.
|
|
6
|
-
* For each property in the input props:
|
|
7
|
-
* - If the value is a State object, it will be converted to a derived state
|
|
8
|
-
* - Otherwise, the value will be kept as is
|
|
9
|
-
* @deprecated
|
|
10
|
-
* @template T - The type of props extending Props
|
|
11
|
-
* @param {T} props - The input props object containing KeyLike or State values
|
|
12
|
-
* @returns {PropsRef<T>} A new object with State values converted to reactive states
|
|
13
|
-
*/
|
|
14
|
-
function propsRef(props) {
|
|
15
|
-
return props;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
export { propsRef };
|
package/dist/ref.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { ConstantRef, StateRef, VariableRef } from "./types.js";
|
|
2
|
-
|
|
3
|
-
//#region src/ref.d.ts
|
|
4
|
-
declare const REF_REGISTRY: WeakMap<ConstantRef<unknown>, StateRef<unknown>>;
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use 'mutable()' instead.
|
|
7
|
-
* Creates a readable reference that can be subscribed to for reactive updates.
|
|
8
|
-
* This function initializes a reactive reference with a given initial value and provides
|
|
9
|
-
* mechanisms for subscribing to changes and publishing updates to subscribers.
|
|
10
|
-
*
|
|
11
|
-
* @template T The type of the value being referenced
|
|
12
|
-
* @param init - The initial value for the reference
|
|
13
|
-
* @returns A readable reference object with subscribe and publish capabilities
|
|
14
|
-
*/
|
|
15
|
-
declare function variableRef<T>(init: T): VariableRef<T>;
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated Use 'mutable()' instead.
|
|
18
|
-
* Creates a constant (read-only) reference that can be subscribed to for reactive updates.
|
|
19
|
-
* This function initializes a reactive reference with a given initial value that cannot be modified
|
|
20
|
-
* after creation.
|
|
21
|
-
*
|
|
22
|
-
* @template T The type of the value being referenced
|
|
23
|
-
* @param init - The initial value for the reference
|
|
24
|
-
* @param constant - If true, the reference will be read-only and cannot be updated.
|
|
25
|
-
* @returns A constant reference object with subscribe capability but no write access
|
|
26
|
-
*/
|
|
27
|
-
declare function variableRef<T>(init: T, constant: true): ConstantRef<T>;
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated Use 'immutable()' instead.
|
|
30
|
-
* Creates a constant (read-only) reference that can be subscribed to for reactive updates.
|
|
31
|
-
* This function initializes a reactive reference with a given initial value that cannot be modified
|
|
32
|
-
* after creation. It's useful for values that should remain constant throughout the component lifecycle
|
|
33
|
-
* but still need to be reactively tracked.
|
|
34
|
-
*
|
|
35
|
-
* @template T The type of the value being referenced
|
|
36
|
-
* @param init - The initial value for the constant reference
|
|
37
|
-
* @returns A constant reference object with subscribe capability but no write access
|
|
38
|
-
*/
|
|
39
|
-
declare function constantRef<T>(init: T): ConstantRef<T>;
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated Use 'isValueRef()' instead.
|
|
42
|
-
* Checks if a given value is a writable reference.
|
|
43
|
-
* This function uses the REF_REGISTRY to determine if the provided value
|
|
44
|
-
* is a registered writable reference.
|
|
45
|
-
*
|
|
46
|
-
* @template T The type of the value that the reference holds
|
|
47
|
-
* @param ref - The value to check
|
|
48
|
-
* @returns True if the value is a writable reference, false otherwise
|
|
49
|
-
*/
|
|
50
|
-
declare function isRef<T>(ref: unknown): ref is VariableRef<T>;
|
|
51
|
-
//#endregion
|
|
52
|
-
export { REF_REGISTRY, constantRef, isRef, variableRef };
|
package/dist/ref.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { anchor } from "@anchorlib/core";
|
|
2
|
-
import { onDestroy } from "svelte";
|
|
3
|
-
|
|
4
|
-
//#region src/ref.ts
|
|
5
|
-
const REF_REGISTRY = /* @__PURE__ */ new WeakMap();
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated Use 'mutable()' instead.
|
|
8
|
-
* Creates a readable reference that can be subscribed to for reactive updates.
|
|
9
|
-
* This function initializes a reactive reference with a given initial value and provides
|
|
10
|
-
* mechanisms for subscribing to changes and publishing updates to subscribers.
|
|
11
|
-
*
|
|
12
|
-
* @template T The type of the value being referenced
|
|
13
|
-
* @param init - The initial value for the reference
|
|
14
|
-
* @param constant - If true, the reference will be read-only and cannot be updated.
|
|
15
|
-
* @returns A readable reference object with subscribe and publish capabilities
|
|
16
|
-
*/
|
|
17
|
-
function variableRef(init, constant) {
|
|
18
|
-
const valueRef = anchor({ value: init }, { recursive: true });
|
|
19
|
-
const set = (value) => {
|
|
20
|
-
if (constant === true || value === valueRef.value) return;
|
|
21
|
-
valueRef.value = value;
|
|
22
|
-
};
|
|
23
|
-
onDestroy(() => {
|
|
24
|
-
REF_REGISTRY.delete(stateRef);
|
|
25
|
-
anchor.destroy(valueRef);
|
|
26
|
-
});
|
|
27
|
-
const stateRef = {
|
|
28
|
-
get value() {
|
|
29
|
-
return valueRef.value;
|
|
30
|
-
},
|
|
31
|
-
set value(value) {
|
|
32
|
-
set(value);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
REF_REGISTRY.set(stateRef, valueRef);
|
|
36
|
-
return stateRef;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* @deprecated Use 'immutable()' instead.
|
|
40
|
-
* Creates a constant (read-only) reference that can be subscribed to for reactive updates.
|
|
41
|
-
* This function initializes a reactive reference with a given initial value that cannot be modified
|
|
42
|
-
* after creation. It's useful for values that should remain constant throughout the component lifecycle
|
|
43
|
-
* but still need to be reactively tracked.
|
|
44
|
-
*
|
|
45
|
-
* @template T The type of the value being referenced
|
|
46
|
-
* @param init - The initial value for the constant reference
|
|
47
|
-
* @returns A constant reference object with subscribe capability but no write access
|
|
48
|
-
*/
|
|
49
|
-
function constantRef(init) {
|
|
50
|
-
return variableRef(init, true);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* @deprecated Use 'isValueRef()' instead.
|
|
54
|
-
* Checks if a given value is a writable reference.
|
|
55
|
-
* This function uses the REF_REGISTRY to determine if the provided value
|
|
56
|
-
* is a registered writable reference.
|
|
57
|
-
*
|
|
58
|
-
* @template T The type of the value that the reference holds
|
|
59
|
-
* @param ref - The value to check
|
|
60
|
-
* @returns True if the value is a writable reference, false otherwise
|
|
61
|
-
*/
|
|
62
|
-
function isRef(ref) {
|
|
63
|
-
return REF_REGISTRY.has(ref);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
export { REF_REGISTRY, constantRef, isRef, variableRef };
|
package/dist/storage/kv.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { KVState, Storable } from "@anchorlib/storage/db";
|
|
2
|
-
|
|
3
|
-
//#region src/storage/kv.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use `kv()` instead.
|
|
7
|
-
* Creates a reactive key-value store state.
|
|
8
|
-
*
|
|
9
|
-
* This function initializes a key-value store with the given name and initial value,
|
|
10
|
-
* and automatically cleans up the store subscription when the component is destroyed.
|
|
11
|
-
*
|
|
12
|
-
* @template T - The type of the stored value, must extend Storable
|
|
13
|
-
* @param name - The unique identifier for the key-value store
|
|
14
|
-
* @param init - The initial value for the store
|
|
15
|
-
* @returns A reactive key-value store state.
|
|
16
|
-
*/
|
|
17
|
-
declare function kvRef<T extends Storable>(name: string, init: T): KVState<T>;
|
|
18
|
-
//#endregion
|
|
19
|
-
export { kvRef };
|
package/dist/storage/kv.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { onDestroy } from "svelte";
|
|
2
|
-
import { kv } from "@anchorlib/storage/db";
|
|
3
|
-
|
|
4
|
-
//#region src/storage/kv.ts
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use `kv()` instead.
|
|
7
|
-
* Creates a reactive key-value store state.
|
|
8
|
-
*
|
|
9
|
-
* This function initializes a key-value store with the given name and initial value,
|
|
10
|
-
* and automatically cleans up the store subscription when the component is destroyed.
|
|
11
|
-
*
|
|
12
|
-
* @template T - The type of the stored value, must extend Storable
|
|
13
|
-
* @param name - The unique identifier for the key-value store
|
|
14
|
-
* @param init - The initial value for the store
|
|
15
|
-
* @returns A reactive key-value store state.
|
|
16
|
-
*/
|
|
17
|
-
function kvRef(name, init) {
|
|
18
|
-
const state = kv(name, init);
|
|
19
|
-
onDestroy(() => {
|
|
20
|
-
kv.leave(state);
|
|
21
|
-
});
|
|
22
|
-
return state;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
export { kvRef };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { LinkableSchema, ObjLike, StateOptions } from "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/storage/persistent.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use `persistent()` instead.
|
|
7
|
-
* Creates a persistent reactive state using the provided name, initial value, and options.
|
|
8
|
-
* The persistentRef is tied to the browser's local storage, meaning its value will persist
|
|
9
|
-
* across page reloads and browser sessions until explicitly cleared.
|
|
10
|
-
*
|
|
11
|
-
* @template T - The type of the initial value, must extend object-like structure.
|
|
12
|
-
* @template S - The schema type for linkable validation, defaults to LinkableSchema.
|
|
13
|
-
* @param name - A unique string identifier for the local storage key.
|
|
14
|
-
* @param init - The initial value to be stored in local storage.
|
|
15
|
-
* @param options - Optional configuration for state behavior and validation schema.
|
|
16
|
-
* @returns A reactive state that provides reactive access and modification capabilities.
|
|
17
|
-
*/
|
|
18
|
-
declare function persistentRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(name: string, init: T, options?: StateOptions<S>): T;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { persistentRef };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { onDestroy } from "svelte";
|
|
2
|
-
import { persistent } from "@anchorlib/storage";
|
|
3
|
-
|
|
4
|
-
//#region src/storage/persistent.ts
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use `persistent()` instead.
|
|
7
|
-
* Creates a persistent reactive state using the provided name, initial value, and options.
|
|
8
|
-
* The persistentRef is tied to the browser's local storage, meaning its value will persist
|
|
9
|
-
* across page reloads and browser sessions until explicitly cleared.
|
|
10
|
-
*
|
|
11
|
-
* @template T - The type of the initial value, must extend object-like structure.
|
|
12
|
-
* @template S - The schema type for linkable validation, defaults to LinkableSchema.
|
|
13
|
-
* @param name - A unique string identifier for the local storage key.
|
|
14
|
-
* @param init - The initial value to be stored in local storage.
|
|
15
|
-
* @param options - Optional configuration for state behavior and validation schema.
|
|
16
|
-
* @returns A reactive state that provides reactive access and modification capabilities.
|
|
17
|
-
*/
|
|
18
|
-
function persistentRef(name, init, options) {
|
|
19
|
-
const state = persistent(name, init, options);
|
|
20
|
-
onDestroy(() => {
|
|
21
|
-
persistent.leave(state);
|
|
22
|
-
});
|
|
23
|
-
return state;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
export { persistentRef };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { LinkableSchema, ObjLike, StateOptions } from "@anchorlib/core";
|
|
2
|
-
|
|
3
|
-
//#region src/storage/session.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use `session()` instead.
|
|
7
|
-
* Creates a session-scoped reactive state using the provided name, initial value, and options.
|
|
8
|
-
* The sessionRef is tied to the browser's session storage, meaning its value will persist
|
|
9
|
-
* across page reloads but not after the session ends (e.g., tab/window closed).
|
|
10
|
-
*
|
|
11
|
-
* @template T - The type of the initial value, must extend object-like structure.
|
|
12
|
-
* @template S - The schema type for linkable validation, defaults to LinkableSchema.
|
|
13
|
-
* @param name - A unique string identifier for the session storage key.
|
|
14
|
-
* @param init - The initial value to be stored in session storage.
|
|
15
|
-
* @param options - Optional configuration for state behavior and validation schema.
|
|
16
|
-
* @returns A reactive state that provides reactive access and modification capabilities.
|
|
17
|
-
*/
|
|
18
|
-
declare function sessionRef<T extends ObjLike, S extends LinkableSchema = LinkableSchema>(name: string, init: T, options?: StateOptions<S>): T;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { sessionRef };
|
package/dist/storage/session.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { onDestroy } from "svelte";
|
|
2
|
-
import { session } from "@anchorlib/storage";
|
|
3
|
-
|
|
4
|
-
//#region src/storage/session.ts
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use `session()` instead.
|
|
7
|
-
* Creates a session-scoped reactive state using the provided name, initial value, and options.
|
|
8
|
-
* The sessionRef is tied to the browser's session storage, meaning its value will persist
|
|
9
|
-
* across page reloads but not after the session ends (e.g., tab/window closed).
|
|
10
|
-
*
|
|
11
|
-
* @template T - The type of the initial value, must extend object-like structure.
|
|
12
|
-
* @template S - The schema type for linkable validation, defaults to LinkableSchema.
|
|
13
|
-
* @param name - A unique string identifier for the session storage key.
|
|
14
|
-
* @param init - The initial value to be stored in session storage.
|
|
15
|
-
* @param options - Optional configuration for state behavior and validation schema.
|
|
16
|
-
* @returns A reactive state that provides reactive access and modification capabilities.
|
|
17
|
-
*/
|
|
18
|
-
function sessionRef(name, init, options) {
|
|
19
|
-
const state = session(name, init, options);
|
|
20
|
-
onDestroy(() => {
|
|
21
|
-
session.leave(state);
|
|
22
|
-
});
|
|
23
|
-
return state;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
export { sessionRef };
|
package/dist/storage/table.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { TableRef } from "./types.js";
|
|
2
|
-
import { InferRec, ReactiveTable, Rec, Row } from "@anchorlib/storage/db";
|
|
3
|
-
|
|
4
|
-
//#region src/storage/table.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated Use `createTable()` instead.
|
|
8
|
-
*/
|
|
9
|
-
declare function createTableRef<T extends ReactiveTable<Rec>>(table: T): TableRef<InferRec<T>>;
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated Use `createTable()` instead.
|
|
12
|
-
*/
|
|
13
|
-
declare function createTableRef<T extends Rec, R extends Row<T> = Row<T>>(name: string, version?: number, indexes?: (keyof R)[], remIndexes?: (keyof R)[], dbName?: string): TableRef<T, R>;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { createTableRef };
|
package/dist/storage/table.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { onDestroy } from "svelte";
|
|
2
|
-
import { createTable } from "@anchorlib/storage/db";
|
|
3
|
-
|
|
4
|
-
//#region src/storage/table.ts
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated Use `createTable()` instead.
|
|
7
|
-
*/
|
|
8
|
-
function createTableRef(tableName, version = 1, indexes, remIndexes, dbName = tableName) {
|
|
9
|
-
if (typeof tableName === "string") tableName = createTable(tableName, version, indexes, remIndexes, dbName);
|
|
10
|
-
const tableRef = tableName;
|
|
11
|
-
return {
|
|
12
|
-
get(id) {
|
|
13
|
-
const state = tableRef.get(id);
|
|
14
|
-
onDestroy(() => {
|
|
15
|
-
tableRef.leave(id);
|
|
16
|
-
});
|
|
17
|
-
return state;
|
|
18
|
-
},
|
|
19
|
-
add(payload) {
|
|
20
|
-
const state = tableRef.add(payload);
|
|
21
|
-
onDestroy(() => {
|
|
22
|
-
tableRef.leave(state.data.id);
|
|
23
|
-
});
|
|
24
|
-
return state;
|
|
25
|
-
},
|
|
26
|
-
list(filter, limit, direction) {
|
|
27
|
-
return tableRef.list(filter, limit, direction);
|
|
28
|
-
},
|
|
29
|
-
listByIndex(name, filter, limit, direction) {
|
|
30
|
-
return tableRef.listByIndex(name, filter, limit, direction);
|
|
31
|
-
},
|
|
32
|
-
remove(id) {
|
|
33
|
-
return tableRef.remove(id);
|
|
34
|
-
},
|
|
35
|
-
seed(seeds) {
|
|
36
|
-
tableRef.seed(seeds);
|
|
37
|
-
return this;
|
|
38
|
-
},
|
|
39
|
-
table() {
|
|
40
|
-
return tableRef;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
//#endregion
|
|
46
|
-
export { createTableRef };
|
package/dist/storage/types.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { FilterFn, ReactiveTable, Rec, Row, RowListState, RowState } from "@anchorlib/storage/db";
|
|
2
|
-
|
|
3
|
-
//#region src/storage/types.d.ts
|
|
4
|
-
interface TableRef<T extends Rec, R$1 extends Row<T> = Row<T>> {
|
|
5
|
-
get(id: string): RowState<R$1>;
|
|
6
|
-
add(payload: T): RowState<R$1>;
|
|
7
|
-
remove(id: string): RowState<R$1>;
|
|
8
|
-
list(filter?: IDBKeyRange | FilterFn<R$1>, limit?: number, direction?: IDBCursorDirection): RowListState<R$1>;
|
|
9
|
-
listByIndex(name: keyof R$1, filter?: IDBKeyRange | FilterFn<R$1>, limit?: number, direction?: IDBCursorDirection): RowListState<R$1>;
|
|
10
|
-
seed<T extends R$1[]>(seeds: T): this;
|
|
11
|
-
table(): ReactiveTable<T>;
|
|
12
|
-
}
|
|
13
|
-
type InferRef<T> = T extends TableRef<Rec, infer R> ? R : never;
|
|
14
|
-
type InferListRef<T> = T extends TableRef<Rec, infer R> ? R[] : never;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { InferListRef, InferRef, TableRef };
|
package/dist/storage/types.js
DELETED
|
File without changes
|
package/dist/types.d.ts
DELETED
package/dist/types.js
DELETED
|
File without changes
|