@manyducks.co/dolla 2.0.0-alpha.3 → 2.0.0-alpha.31
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/README.md +31 -951
- package/dist/core/batch.d.ts +17 -0
- package/dist/core/context.d.ts +94 -0
- package/dist/core/dolla.d.ts +161 -0
- package/dist/core/markup.d.ts +91 -0
- package/dist/core/nodes/dom.d.ts +13 -0
- package/dist/core/nodes/html.d.ts +39 -0
- package/dist/core/nodes/observer.d.ts +30 -0
- package/dist/core/nodes/outlet.d.ts +19 -0
- package/dist/core/nodes/portal.d.ts +22 -0
- package/dist/core/nodes/repeat.d.ts +36 -0
- package/dist/core/nodes/view.d.ts +92 -0
- package/dist/core/ref.d.ts +29 -0
- package/dist/core/state.d.ts +126 -0
- package/dist/core/stats.d.ts +31 -0
- package/dist/core/store.d.ts +62 -0
- package/dist/core/symbols.d.ts +7 -0
- package/dist/index.d.ts +18 -11
- package/dist/index.js +1157 -1159
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +2 -2
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +3 -3
- package/dist/jsx-runtime.js +2 -2
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/markup-D1i09ddt.js +1563 -0
- package/dist/markup-D1i09ddt.js.map +1 -0
- package/dist/modules/http.d.ts +5 -5
- package/dist/modules/i18n.d.ts +129 -0
- package/dist/modules/router.d.ts +37 -48
- package/dist/typeChecking.d.ts +2 -2
- package/dist/types.d.ts +12 -13
- package/dist/utils.d.ts +14 -2
- package/dist/views/default-crash-view.d.ts +1 -1
- package/dist/views/passthrough.d.ts +2 -2
- package/docs/http.md +29 -0
- package/docs/i18n.md +38 -0
- package/docs/index.md +10 -0
- package/docs/router.md +77 -0
- package/docs/setup.md +31 -0
- package/docs/state.md +141 -0
- package/docs/stores.md +62 -0
- package/docs/views.md +308 -0
- package/index.d.ts +2 -2
- package/notes/TODO.md +6 -0
- package/notes/context-vars.md +21 -0
- package/notes/readme-scratch.md +222 -0
- package/notes/route-middleware.md +42 -0
- package/notes/scratch.md +195 -7
- package/notes/stores.md +73 -0
- package/package.json +12 -14
- package/tests/{signals.test.js → state.test.js} +6 -6
- package/vite.config.js +0 -10
- package/dist/markup.d.ts +0 -100
- package/dist/modules/dolla.d.ts +0 -111
- package/dist/modules/language.d.ts +0 -41
- package/dist/modules/render.d.ts +0 -17
- package/dist/nodes/cond.d.ts +0 -26
- package/dist/nodes/html.d.ts +0 -26
- package/dist/nodes/observer.d.ts +0 -29
- package/dist/nodes/outlet.d.ts +0 -22
- package/dist/nodes/portal.d.ts +0 -19
- package/dist/nodes/repeat.d.ts +0 -34
- package/dist/nodes/text.d.ts +0 -19
- package/dist/passthrough-DrtCifRF.js +0 -1228
- package/dist/passthrough-DrtCifRF.js.map +0 -1
- package/dist/signals.d.ts +0 -101
- package/dist/view.d.ts +0 -50
- /package/dist/{routing.d.ts → modules/router.utils.d.ts} +0 -0
- /package/dist/{routing.test.d.ts → modules/router.utils.test.d.ts} +0 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { strictEqual } from "../utils";
|
|
2
|
+
import { IS_STATE } from "./symbols";
|
|
3
|
+
/**
|
|
4
|
+
* Stops the observer that created it when called.
|
|
5
|
+
*/
|
|
6
|
+
export type StopFunction = () => void;
|
|
7
|
+
type Unwrapped<T> = T extends State<infer V> ? V : T;
|
|
8
|
+
/**
|
|
9
|
+
* Extracts value types from an array of states.
|
|
10
|
+
*/
|
|
11
|
+
export type StateValues<T extends MaybeState<any>[]> = {
|
|
12
|
+
[K in keyof T]: Unwrapped<T[K]>;
|
|
13
|
+
};
|
|
14
|
+
export interface CreateStateOptions<T> {
|
|
15
|
+
/**
|
|
16
|
+
* Determines if the `next` value is equal to the `current` value.
|
|
17
|
+
* If this function returns true, watchers will be notified of changes. If it returns false, watchers will not be notified.
|
|
18
|
+
* Default equals check is `===` (strict) equality.
|
|
19
|
+
*
|
|
20
|
+
* @param next - The new value being set.
|
|
21
|
+
* @param current - The current value being replaced.
|
|
22
|
+
*/
|
|
23
|
+
equals?: (next: T, current: T) => boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface WatchOptions<T> {
|
|
26
|
+
/**
|
|
27
|
+
* If true the watch callback will be called for the first time on the next change.
|
|
28
|
+
* Callback is immediately called with the state's current value by default.
|
|
29
|
+
*/
|
|
30
|
+
lazy?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface State<T> {
|
|
33
|
+
/**
|
|
34
|
+
* Returns the current value.
|
|
35
|
+
*/
|
|
36
|
+
get(): T;
|
|
37
|
+
/**
|
|
38
|
+
* Watch this state's value with a `callback` function.
|
|
39
|
+
* The `callback` is only called if the value is not equal to the current value.
|
|
40
|
+
*
|
|
41
|
+
* > NOTE: If watching a state inside a view, use the `.watch` method on the `ViewContext`. That method will automatically
|
|
42
|
+
* clean up all watchers when the view is disconnected. Watchers created here must be cleaned up manually.
|
|
43
|
+
*/
|
|
44
|
+
watch(callback: (value: T) => void, options?: WatchOptions<T>): StopFunction;
|
|
45
|
+
}
|
|
46
|
+
/** A new value for a state, or a callback that receives the current value and returns a new one. */
|
|
47
|
+
export type SetAction<I, O = I> = O | SetFunction<I, O>;
|
|
48
|
+
export type SetFunction<I, O = I> = (current: I) => O;
|
|
49
|
+
/** Callback that updates the value of a state. */
|
|
50
|
+
export type Setter<I, O = I> = (value: SetAction<I, O>) => void;
|
|
51
|
+
export type MaybeState<T> = State<T> | T;
|
|
52
|
+
export declare function isState<T>(value: any): value is State<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves a plain value from a variable that may be a state.
|
|
55
|
+
*/
|
|
56
|
+
export declare function toValue<T>(source: MaybeState<T>): T;
|
|
57
|
+
/**
|
|
58
|
+
* Ensures a variable that may be a state or plain value is a state.
|
|
59
|
+
*/
|
|
60
|
+
export declare function toState<T>(value: MaybeState<T>): State<T>;
|
|
61
|
+
/**
|
|
62
|
+
* ValueHolder implements the core functionality of a State.
|
|
63
|
+
* It holds a value, which can be retrieved with `get`, updated with `set` and observed with `watch`.
|
|
64
|
+
* The user-facing API splits up access into a read-only State and a setter function.
|
|
65
|
+
*/
|
|
66
|
+
export declare class ValueHolder<T> implements State<T> {
|
|
67
|
+
value: T;
|
|
68
|
+
watchers: ((value: T) => void)[];
|
|
69
|
+
equals: typeof strictEqual;
|
|
70
|
+
constructor(value: T, options?: CreateStateOptions<T>);
|
|
71
|
+
get(): T;
|
|
72
|
+
set(action: T | SetFunction<T>): void;
|
|
73
|
+
watch(callback: (value: T) => void, options?: WatchOptions<T>): () => void;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Signal is the implementation of a read-only State.
|
|
77
|
+
*/
|
|
78
|
+
export declare class Signal<T> implements State<T> {
|
|
79
|
+
[IS_STATE]: boolean;
|
|
80
|
+
__value: State<T>;
|
|
81
|
+
constructor(value: State<T>);
|
|
82
|
+
get(): T;
|
|
83
|
+
watch(callback: (value: T) => void, options?: WatchOptions<T>): StopFunction;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates a state and setter.
|
|
87
|
+
*/
|
|
88
|
+
export declare function createState<T>(value: T, options?: CreateStateOptions<T>): [State<T>, Setter<T>];
|
|
89
|
+
/**
|
|
90
|
+
* Creates a state and setter.
|
|
91
|
+
*/
|
|
92
|
+
export declare function createState<T>(value?: T, options?: CreateStateOptions<T | undefined>): [State<T | undefined>, Setter<T | undefined>];
|
|
93
|
+
export interface DeriveOptions {
|
|
94
|
+
equals?: (next: unknown, current: unknown) => boolean;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Derives a new `State` from one or more existing states.
|
|
98
|
+
*
|
|
99
|
+
* @param sources - Array of source states to track.
|
|
100
|
+
* @param fn - A function called to recompute the value when any tracked source states receive a new value.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* // With one source...
|
|
104
|
+
* const [$count, setCount] = createState(5);
|
|
105
|
+
* const $doubled = derive([$count], count => count * 2);
|
|
106
|
+
* // ... or many:
|
|
107
|
+
* const [$greeting, setGreeting] = createState("Hello");
|
|
108
|
+
* const [$name, setName] = createState("World");
|
|
109
|
+
* const $hello = derive([$greeting, name], (greeting, name) => `${greeting}, ${name}!`);
|
|
110
|
+
*/
|
|
111
|
+
export declare function derive<Sources extends MaybeState<any>[], T>(sources: [...Sources], fn: (...values: StateValues<Sources>) => T | State<T>, options?: DeriveOptions): State<T>;
|
|
112
|
+
export interface StateWatcher {
|
|
113
|
+
/**
|
|
114
|
+
* Watch one or more states, calling the provided `fn` each time one of their values changes.
|
|
115
|
+
*
|
|
116
|
+
* @param states - An array of states or plain values. States will be unwrapped before being passed to `fn`.
|
|
117
|
+
* @param fn - A function that takes the values of `states` in the same order they were passed.
|
|
118
|
+
*/
|
|
119
|
+
watch<I extends MaybeState<any>[]>(states: [...I], fn: (...currentValues: StateValues<I>) => void): StopFunction;
|
|
120
|
+
/**
|
|
121
|
+
* Stop all watch callbacks registered to this watcher.
|
|
122
|
+
*/
|
|
123
|
+
stopAll(): void;
|
|
124
|
+
}
|
|
125
|
+
export declare function createWatcher(): StateWatcher;
|
|
126
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Emitter } from "@manyducks.co/emitter";
|
|
2
|
+
import type { Dolla } from "./dolla";
|
|
3
|
+
interface StatsStore {
|
|
4
|
+
emitter: Emitter<StatsStoreEvents>;
|
|
5
|
+
stats: {
|
|
6
|
+
watcherCount: number;
|
|
7
|
+
viewCount: number;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
type StatsStoreEvents = {
|
|
11
|
+
/**
|
|
12
|
+
* Emitted when any stats are updated in the store.
|
|
13
|
+
*/
|
|
14
|
+
statsChanged: [];
|
|
15
|
+
_incrementWatcherCount: [amount: number];
|
|
16
|
+
_incrementViewCount: [amount: number];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Tracks runtime statistics.
|
|
20
|
+
*/
|
|
21
|
+
export declare class Stats {
|
|
22
|
+
#private;
|
|
23
|
+
constructor(dolla: Dolla);
|
|
24
|
+
}
|
|
25
|
+
export declare function _createStore(): StatsStore;
|
|
26
|
+
export declare function _getStore(): StatsStore;
|
|
27
|
+
export declare function _onWatcherAdded(): void;
|
|
28
|
+
export declare function _onWatcherRemoved(): void;
|
|
29
|
+
export declare function _onViewMounted(): void;
|
|
30
|
+
export declare function _onViewUnmounted(): void;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Emitter } from "@manyducks.co/emitter";
|
|
2
|
+
import { type WildcardListenerMap, type ComponentContext, type ElementContext } from "./context.js";
|
|
3
|
+
import type { Logger } from "./dolla.js";
|
|
4
|
+
import { type MaybeState, type StateValues, type StopFunction } from "./state.js";
|
|
5
|
+
export type StoreFunction<Options, Value> = (this: StoreContext, options: Options, context: StoreContext) => Value;
|
|
6
|
+
export type StoreFactory<Options, Value> = Options extends undefined ? () => Store<Options, Value> : (options: Options) => Store<Options, Value>;
|
|
7
|
+
export interface StoreContext extends Logger, ComponentContext {
|
|
8
|
+
/**
|
|
9
|
+
* True while this store is attached to a context that is currently mounted in the view tree.
|
|
10
|
+
*/
|
|
11
|
+
readonly isMounted: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Registers a callback to run just after this store is mounted.
|
|
14
|
+
*/
|
|
15
|
+
onMount(callback: () => void): void;
|
|
16
|
+
/**
|
|
17
|
+
* Registers a callback to run just after this store is unmounted.
|
|
18
|
+
*/
|
|
19
|
+
onUnmount(callback: () => void): void;
|
|
20
|
+
/**
|
|
21
|
+
* Watch a set of states. The callback is called when any of the states receive a new value.
|
|
22
|
+
* Watchers will be automatically stopped when this store is unmounted.
|
|
23
|
+
*/
|
|
24
|
+
watch<T extends MaybeState<any>[]>(states: [...T], callback: (...values: StateValues<T>) => void): StopFunction;
|
|
25
|
+
}
|
|
26
|
+
type StoreEvents = {
|
|
27
|
+
mounted: [];
|
|
28
|
+
unmounted: [];
|
|
29
|
+
};
|
|
30
|
+
export declare class Store<Options, Value> {
|
|
31
|
+
readonly key: string;
|
|
32
|
+
private _fn;
|
|
33
|
+
private _options;
|
|
34
|
+
/**
|
|
35
|
+
* Value is guaranteed to be set after `attach` is called.
|
|
36
|
+
*/
|
|
37
|
+
value: Value;
|
|
38
|
+
isMounted: boolean;
|
|
39
|
+
_elementContext: ElementContext;
|
|
40
|
+
_emitter: Emitter<StoreEvents>;
|
|
41
|
+
_wildcardListeners: WildcardListenerMap;
|
|
42
|
+
_logger: Logger;
|
|
43
|
+
_watcher: import("./state.js").StateWatcher;
|
|
44
|
+
get name(): string;
|
|
45
|
+
constructor(key: string, fn: StoreFunction<Options, Value>, options: Options);
|
|
46
|
+
/**
|
|
47
|
+
* Attaches this Store to the elementContext.
|
|
48
|
+
* Returns false if there was already an instance attached, and true otherwise.
|
|
49
|
+
*/
|
|
50
|
+
attach(elementContext: ElementContext): boolean;
|
|
51
|
+
handleMount(): void;
|
|
52
|
+
handleUnmount(): void;
|
|
53
|
+
}
|
|
54
|
+
export declare function isStoreFactory<Options, Value>(value: any): value is StoreFactory<Options, Value>;
|
|
55
|
+
export declare function isStore<Options, Value>(value: any): value is Store<Options, Value>;
|
|
56
|
+
/**
|
|
57
|
+
* Defines a new store.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createStore<Options = undefined, Value = unknown>(fn: StoreFunction<Options, Value>): StoreFactory<Options, Value>;
|
|
60
|
+
export declare class StoreError extends Error {
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const IS_STATE: unique symbol;
|
|
2
|
+
export declare const IS_REF: unique symbol;
|
|
3
|
+
export declare const IS_MARKUP: unique symbol;
|
|
4
|
+
export declare const IS_MARKUP_ELEMENT: unique symbol;
|
|
5
|
+
export declare const IS_STORE: unique symbol;
|
|
6
|
+
export declare const IS_STORE_FACTORY: unique symbol;
|
|
7
|
+
export declare const IS_ROUTER: unique symbol;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type {
|
|
3
|
-
|
|
1
|
+
export { createState, derive, isState, toState, toValue } from "./core/state.js";
|
|
2
|
+
export type { MaybeState, Setter, State, StopFunction } from "./core/state.js";
|
|
3
|
+
export { createRef, isRef, type Ref } from "./core/ref.js";
|
|
4
|
+
export { createStore, type Store, type StoreFactory, type StoreFunction } from "./core/store.js";
|
|
5
|
+
export { createRouter, type Router, type RouterOptions } from "./modules/router.js";
|
|
6
|
+
export { deepEqual, shallowEqual, strictEqual } from "./utils.js";
|
|
7
|
+
export { cond, createMarkup, html, portal, repeat } from "./core/markup.js";
|
|
8
|
+
export type { Markup, MarkupElement } from "./core/markup.js";
|
|
9
|
+
export { createView } from "./core/nodes/view.js";
|
|
10
|
+
import { Dolla } from "./core/dolla.js";
|
|
4
11
|
declare const dolla: Dolla;
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export type {
|
|
10
|
-
export type {
|
|
11
|
-
export type { Environment } from "./modules/dolla.js";
|
|
12
|
+
export default dolla;
|
|
13
|
+
export declare const t: (selector: string, options?: import("./modules/i18n.js").TOptions) => import("./core/state.js").State<string>;
|
|
14
|
+
export declare function setDevDebug(value: boolean): void;
|
|
15
|
+
export declare function getDevDebug(): boolean;
|
|
16
|
+
export type { Dolla, Environment, Logger, LoggerErrorContext, LoggerOptions, Loggles } from "./core/dolla.js";
|
|
17
|
+
export type { ViewContext, ViewElement, ViewFunction } from "./core/nodes/view.js";
|
|
12
18
|
export type { HTTPRequest, HTTPResponse } from "./modules/http.js";
|
|
19
|
+
export type { InputType, Renderable } from "./types.js";
|
|
20
|
+
export type { CrashViewProps } from "./views/default-crash-view.js";
|
|
13
21
|
import type { IntrinsicElements as Elements } from "./types";
|
|
14
22
|
declare global {
|
|
15
23
|
namespace JSX {
|
|
@@ -18,4 +26,3 @@ declare global {
|
|
|
18
26
|
}
|
|
19
27
|
}
|
|
20
28
|
}
|
|
21
|
-
export default dolla;
|