@manyducks.co/dolla 2.0.0-alpha.24 → 2.0.0-alpha.26
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/core/dolla.d.ts +3 -4
- package/dist/core/markup.d.ts +1 -6
- package/dist/core/nodes/observer.d.ts +7 -11
- package/dist/core/nodes/outlet.d.ts +6 -5
- package/dist/core/nodes/repeat.d.ts +1 -2
- package/dist/core/nodes/view.d.ts +1 -0
- package/dist/core/state.d.ts +44 -35
- package/dist/index.d.ts +4 -4
- package/dist/index.js +94 -97
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/jsx-runtime.js +2 -2
- package/dist/{passthrough-BeKX_qRr.js → passthrough-CACEgFx5.js} +394 -546
- package/dist/passthrough-CACEgFx5.js.map +1 -0
- package/dist/types.d.ts +2 -2
- package/docs/states.md +3 -50
- package/notes/scratch.md +112 -11
- package/package.json +1 -1
- package/dist/core/nodes/cond.d.ts +0 -28
- package/dist/passthrough-BeKX_qRr.js.map +0 -1
package/dist/core/dolla.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type CrashViewProps } from "../views/default-crash-view.js";
|
|
|
2
2
|
import { Batch } from "./batch.js";
|
|
3
3
|
import { type Markup, type MarkupElement } from "./markup.js";
|
|
4
4
|
import { type ViewElement, type ViewFunction } from "./nodes/view.js";
|
|
5
|
-
import { createRef,
|
|
5
|
+
import { createRef, createState, createWatcher, derive, isRef, isState, toState, toValue } from "./state.js";
|
|
6
6
|
import { HTTP } from "../modules/http.js";
|
|
7
7
|
import { I18n } from "../modules/i18n.js";
|
|
8
8
|
import { Router } from "../modules/router.js";
|
|
@@ -52,10 +52,9 @@ export declare class Dolla {
|
|
|
52
52
|
constructor();
|
|
53
53
|
watch: <I extends import("./state.js").MaybeState<any>[]>(states: [...I], fn: (...currentValues: import("./state.js").StateValues<I>) => void) => import("./state.js").StopFunction;
|
|
54
54
|
createState: typeof createState;
|
|
55
|
-
createSettableState: typeof createSettableState;
|
|
56
|
-
toSettableState: typeof toSettableState;
|
|
57
55
|
toState: typeof toState;
|
|
58
|
-
|
|
56
|
+
toValue: typeof toValue;
|
|
57
|
+
isState: typeof isState;
|
|
59
58
|
derive: typeof derive;
|
|
60
59
|
createWatcher: typeof createWatcher;
|
|
61
60
|
createRef: typeof createRef;
|
package/dist/core/markup.d.ts
CHANGED
|
@@ -57,18 +57,13 @@ export interface MarkupAttributes {
|
|
|
57
57
|
$text: {
|
|
58
58
|
value: MaybeState<Stringable>;
|
|
59
59
|
};
|
|
60
|
-
$cond: {
|
|
61
|
-
$predicate: State<any>;
|
|
62
|
-
thenContent?: Renderable;
|
|
63
|
-
elseContent?: Renderable;
|
|
64
|
-
};
|
|
65
60
|
$repeat: {
|
|
66
61
|
$items: State<any[]>;
|
|
67
62
|
keyFn: (value: any, index: number) => string | number | symbol;
|
|
68
63
|
renderFn: ($item: State<any>, $index: State<number>, c: ViewContext) => ViewResult;
|
|
69
64
|
};
|
|
70
65
|
$observer: {
|
|
71
|
-
|
|
66
|
+
sources: MaybeState<any>[];
|
|
72
67
|
renderFn: (...items: any) => Renderable;
|
|
73
68
|
};
|
|
74
69
|
$outlet: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Renderable } from "../../types.js";
|
|
2
2
|
import { type ElementContext, type MarkupElement } from "../markup.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type MaybeState } from "../state.js";
|
|
4
4
|
import { TYPE_MARKUP_ELEMENT } from "../symbols.js";
|
|
5
5
|
interface ObserverOptions {
|
|
6
6
|
elementContext: ElementContext;
|
|
7
|
-
|
|
7
|
+
sources: MaybeState<any>[];
|
|
8
8
|
renderFn: (...values: any) => Renderable;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
@@ -13,21 +13,17 @@ interface ObserverOptions {
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class Observer implements MarkupElement {
|
|
15
15
|
[TYPE_MARKUP_ELEMENT]: boolean;
|
|
16
|
-
node:
|
|
17
|
-
|
|
18
|
-
connectedViews: MarkupElement[];
|
|
16
|
+
node: Text;
|
|
17
|
+
children: MarkupElement[];
|
|
19
18
|
renderFn: (...values: any) => Renderable;
|
|
20
19
|
elementContext: ElementContext;
|
|
21
|
-
observerControls: {
|
|
22
|
-
start: () => void;
|
|
23
|
-
stop: () => void;
|
|
24
|
-
};
|
|
25
20
|
watcher: import("../state.js").StateWatcher;
|
|
21
|
+
sources: MaybeState<any>[];
|
|
26
22
|
get isMounted(): boolean;
|
|
27
|
-
constructor({
|
|
23
|
+
constructor({ sources, renderFn, elementContext }: ObserverOptions);
|
|
28
24
|
mount(parent: Node, after?: Node): void;
|
|
29
25
|
unmount(parentIsUnmounting?: boolean): void;
|
|
30
26
|
cleanup(parentIsUnmounting: boolean): void;
|
|
31
|
-
update(
|
|
27
|
+
update(children: Renderable[]): void;
|
|
32
28
|
}
|
|
33
29
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MarkupElement } from "../markup.js";
|
|
2
|
-
import { MaybeState, type StopFunction } from "../state.js";
|
|
2
|
+
import { type MaybeState, type StopFunction } from "../state.js";
|
|
3
3
|
import { TYPE_MARKUP_ELEMENT } from "../symbols.js";
|
|
4
4
|
/**
|
|
5
5
|
* Manages several MarkupElements as one.
|
|
@@ -8,11 +8,12 @@ export declare class Outlet implements MarkupElement {
|
|
|
8
8
|
[TYPE_MARKUP_ELEMENT]: boolean;
|
|
9
9
|
node: Text;
|
|
10
10
|
isMounted: boolean;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
source: MaybeState<MarkupElement[]>;
|
|
12
|
+
elements: MarkupElement[];
|
|
13
13
|
stopCallback?: StopFunction;
|
|
14
|
-
constructor(
|
|
14
|
+
constructor(source: MaybeState<MarkupElement[]>);
|
|
15
15
|
mount(parent: Node, after?: Node | undefined): void;
|
|
16
16
|
unmount(parentIsUnmounting?: boolean): void;
|
|
17
|
-
|
|
17
|
+
cleanup(parentIsUnmounting: boolean): void;
|
|
18
|
+
update(newElements: MarkupElement[]): void;
|
|
18
19
|
}
|
|
@@ -18,8 +18,7 @@ type ConnectedItem<T> = {
|
|
|
18
18
|
};
|
|
19
19
|
export declare class Repeat<T> implements MarkupElement {
|
|
20
20
|
[TYPE_MARKUP_ELEMENT]: boolean;
|
|
21
|
-
node:
|
|
22
|
-
endNode: Node;
|
|
21
|
+
node: Text;
|
|
23
22
|
$items: State<T[]>;
|
|
24
23
|
stopCallback?: StopFunction;
|
|
25
24
|
connectedItems: ConnectedItem<T>[];
|
|
@@ -71,6 +71,7 @@ export declare class View<P> implements ViewElement {
|
|
|
71
71
|
_view: ViewFunction<P>;
|
|
72
72
|
_props: P;
|
|
73
73
|
_element?: MarkupElement;
|
|
74
|
+
_childMarkup: Markup[];
|
|
74
75
|
_$children: State<MarkupElement[]>;
|
|
75
76
|
_setChildren: import("../state.js").Setter<MarkupElement[], MarkupElement[]>;
|
|
76
77
|
_watcher: import("../state.js").StateWatcher;
|
package/dist/core/state.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { strictEqual } from "../utils";
|
|
2
|
-
import {
|
|
2
|
+
import { TYPE_STATE } from "./symbols";
|
|
3
3
|
/**
|
|
4
4
|
* Stops the observer that created it when called.
|
|
5
5
|
*/
|
|
@@ -62,16 +62,25 @@ export interface SettableState<I, O = I> extends State<I> {
|
|
|
62
62
|
*/
|
|
63
63
|
set(callback: (current: I) => O): void;
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
export interface Ref<T> {
|
|
69
|
+
/**
|
|
70
|
+
* Get: returns the current value stored in the ref (or undefined).
|
|
71
|
+
*/
|
|
72
|
+
(): T | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Set: stores a new `value` in the ref.
|
|
75
|
+
*/
|
|
76
|
+
<T>(value: T | undefined): void;
|
|
67
77
|
}
|
|
68
78
|
export declare function isState<T>(value: any): value is State<T>;
|
|
69
|
-
export declare function isSettableState<T>(value: any): value is SettableState<T>;
|
|
70
79
|
export declare function isRef<T extends Node>(value: any): value is Ref<T>;
|
|
71
80
|
/**
|
|
72
81
|
* Retrieves a plain value from a variable that may be a state.
|
|
73
82
|
*/
|
|
74
|
-
export declare function
|
|
83
|
+
export declare function toValue<T>(source: MaybeState<T>): T;
|
|
75
84
|
/**
|
|
76
85
|
* Ensures a variable that may be a state or plain value is a state.
|
|
77
86
|
*/
|
|
@@ -95,44 +104,44 @@ export declare class Signal<T> implements State<T> {
|
|
|
95
104
|
/**
|
|
96
105
|
* Creates a state and setter.
|
|
97
106
|
*/
|
|
98
|
-
export declare function createState<T>(
|
|
107
|
+
export declare function createState<T>(value: T, options?: CreateStateOptions<T>): [State<T>, Setter<T>];
|
|
99
108
|
/**
|
|
100
109
|
* Creates a state and setter.
|
|
101
110
|
*/
|
|
102
|
-
export declare function createState<T>(
|
|
103
|
-
export declare class SettableSignal<T> implements State<T>, SettableState<T> {
|
|
104
|
-
[TYPE_STATE]: boolean;
|
|
105
|
-
[TYPE_SETTABLE_STATE]: boolean;
|
|
106
|
-
__value: ValueHolder<T>;
|
|
107
|
-
constructor(value: ValueHolder<T>);
|
|
108
|
-
get(): T;
|
|
109
|
-
set(action: T | ((value: T) => T)): void;
|
|
110
|
-
watch(callback: (value: T) => void, options?: WatchOptions<T>): () => void;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Creates a SettableState.
|
|
114
|
-
*/
|
|
115
|
-
export declare function createSettableState<T>(initialValue: T, options?: CreateStateOptions<T>): SettableState<T>;
|
|
116
|
-
/**
|
|
117
|
-
* Creates a SettableState.
|
|
118
|
-
*/
|
|
119
|
-
export declare function createSettableState<T>(initialValue?: T, options?: CreateStateOptions<T | undefined>): SettableState<T | undefined>;
|
|
120
|
-
/**
|
|
121
|
-
* Join a state and its setter into a single SettableState object.
|
|
122
|
-
*/
|
|
123
|
-
export declare function toSettableState<I, O = I>($state: State<I>, setter: Setter<I, O>): SettableState<I, O>;
|
|
124
|
-
/**
|
|
125
|
-
* Creates a Setter with custom logic provided by `callback`.
|
|
126
|
-
*/
|
|
127
|
-
export declare function createSetter<I, O = I>($state: State<I>, callback: (next: O, current: I) => void): Setter<I, O>;
|
|
111
|
+
export declare function createState<T>(value?: T, options?: CreateStateOptions<T | undefined>): [State<T | undefined>, Setter<T | undefined>];
|
|
128
112
|
export interface DeriveOptions {
|
|
129
113
|
equals?: (next: unknown, current: unknown) => boolean;
|
|
130
114
|
}
|
|
131
|
-
export declare function derive<Inputs extends MaybeState<any>[], T>(states: [...Inputs], fn: (...currentValues: StateValues<Inputs>) => T | State<T>, options?: DeriveOptions): State<T>;
|
|
132
115
|
/**
|
|
133
|
-
*
|
|
116
|
+
* Derives a new `State` from one or more existing states.
|
|
117
|
+
*
|
|
118
|
+
* @param sources - Array of source states to track.
|
|
119
|
+
* @param fn - A function called to recompute the value when any tracked source states receive a new value.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* // With one source...
|
|
123
|
+
* const [$count, setCount] = createState(5);
|
|
124
|
+
* const $doubled = derive([$count], count => count * 2);
|
|
125
|
+
* // ... or many:
|
|
126
|
+
* const [$greeting, setGreeting] = createState("Hello");
|
|
127
|
+
* const [$name, setName] = createState("World");
|
|
128
|
+
* const $hello = derive([$greeting, name], (greeting, name) => `${greeting}, ${name}!`);
|
|
129
|
+
*/
|
|
130
|
+
export declare function derive<Sources extends MaybeState<any>[], T>(sources: [...Sources], fn: (...values: StateValues<Sources>) => T | State<T>, options?: DeriveOptions): State<T>;
|
|
131
|
+
/**
|
|
132
|
+
* A Ref is a function that returns the last argument it was called with.
|
|
133
|
+
* Calling it with no arguments will simply return the latest value.
|
|
134
|
+
* Calling it with an argument will store that value and immediately return it.
|
|
135
|
+
*
|
|
136
|
+
* @param value - An (optional) initial value to store.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* const ref = createRef(5);
|
|
140
|
+
* ref(); // 5
|
|
141
|
+
* ref(500);
|
|
142
|
+
* ref(); // 500
|
|
134
143
|
*/
|
|
135
|
-
export declare function createRef<T
|
|
144
|
+
export declare function createRef<T>(value?: T): Ref<T>;
|
|
136
145
|
export interface StateWatcher {
|
|
137
146
|
/**
|
|
138
147
|
* Watch one or more states, calling the provided `fn` each time one of their values changes.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { createRef,
|
|
2
|
-
export type { MaybeState, Ref,
|
|
3
|
-
export {
|
|
1
|
+
export { createRef, createState, derive, isRef, isState, toState, toValue } from "./core/state.js";
|
|
2
|
+
export type { MaybeState, Ref, Setter, State, StopFunction } from "./core/state.js";
|
|
3
|
+
export { deepEqual, shallowEqual, strictEqual } from "./utils.js";
|
|
4
4
|
export { cond, createMarkup, html, portal, repeat } from "./core/markup.js";
|
|
5
5
|
export type { Markup, MarkupElement } from "./core/markup.js";
|
|
6
6
|
import { Dolla } from "./core/dolla.js";
|
|
@@ -10,9 +10,9 @@ export declare const t: (selector: string, options?: import("./modules/i18n.js")
|
|
|
10
10
|
export declare function setDevDebug(value: boolean): void;
|
|
11
11
|
export declare function getDevDebug(): boolean;
|
|
12
12
|
export type { Dolla, Environment, Logger, LoggerErrorContext, LoggerOptions, Loggles } from "./core/dolla.js";
|
|
13
|
+
export type { ViewContext, ViewElement, ViewFunction } from "./core/nodes/view.js";
|
|
13
14
|
export type { HTTPRequest, HTTPResponse } from "./modules/http.js";
|
|
14
15
|
export type { InputType, Renderable } from "./types.js";
|
|
15
|
-
export type { ViewContext, ViewFunction, ViewElement as ViewNode } from "./core/nodes/view.js";
|
|
16
16
|
export type { CrashViewProps } from "./views/default-crash-view.js";
|
|
17
17
|
import type { IntrinsicElements as Elements } from "./types";
|
|
18
18
|
declare global {
|