@manyducks.co/dolla 2.0.0-alpha.24 → 2.0.0-alpha.25

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.
@@ -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, createSettableState, createState, createWatcher, derive, isRef, toSettableState, toState, valueOf } from "./state.js";
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
- valueOf: typeof valueOf;
56
+ toValue: typeof toValue;
57
+ isState: typeof isState;
59
58
  derive: typeof derive;
60
59
  createWatcher: typeof createWatcher;
61
60
  createRef: typeof createRef;
@@ -15,19 +15,16 @@ export declare class Observer implements MarkupElement {
15
15
  [TYPE_MARKUP_ELEMENT]: boolean;
16
16
  node: Node;
17
17
  endNode: Node;
18
- connectedViews: MarkupElement[];
18
+ children: MarkupElement[];
19
19
  renderFn: (...values: any) => Renderable;
20
20
  elementContext: ElementContext;
21
- observerControls: {
22
- start: () => void;
23
- stop: () => void;
24
- };
25
21
  watcher: import("../state.js").StateWatcher;
22
+ sources: State<any>[];
26
23
  get isMounted(): boolean;
27
24
  constructor({ states, renderFn, elementContext }: ObserverOptions);
28
25
  mount(parent: Node, after?: Node): void;
29
26
  unmount(parentIsUnmounting?: boolean): void;
30
27
  cleanup(parentIsUnmounting: boolean): void;
31
- update(...children: Renderable[]): void;
28
+ update(children: Renderable[]): void;
32
29
  }
33
30
  export {};
@@ -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
- elements: MaybeState<MarkupElement[]>;
12
- children: MarkupElement[];
11
+ source: MaybeState<MarkupElement[]>;
12
+ elements: MarkupElement[];
13
13
  stopCallback?: StopFunction;
14
- constructor(elements: MaybeState<MarkupElement[]>);
14
+ constructor(source: MaybeState<MarkupElement[]>);
15
15
  mount(parent: Node, after?: Node | undefined): void;
16
16
  unmount(parentIsUnmounting?: boolean): void;
17
- update(newChildren: MarkupElement[]): void;
17
+ cleanup(parentIsUnmounting: boolean): void;
18
+ update(newElements: MarkupElement[]): void;
18
19
  }
@@ -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;
@@ -1,5 +1,5 @@
1
1
  import { strictEqual } from "../utils";
2
- import { TYPE_SETTABLE_STATE, TYPE_STATE } from "./symbols";
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
- export interface Ref<T extends Node> extends State<T | undefined> {
66
- node: T | undefined;
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 valueOf<T>(value: MaybeState<T>): T;
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>(initialValue: T, options?: CreateStateOptions<T>): [State<T>, Setter<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>(initialValue?: T, options?: CreateStateOptions<T | undefined>): [State<T | undefined>, Setter<T | undefined>];
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
- * A special kind of State exclusively for storing references to DOM nodes.
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 extends Node>(): Ref<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, createSettableState, createSetter, createState, derive, isRef, toSettableState, toState, valueOf, } from "./core/state.js";
2
- export type { MaybeState, Ref, SettableState, State, StopFunction } from "./core/state.js";
3
- export { strictEqual, shallowEqual, deepEqual } from "./utils.js";
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 {