@manyducks.co/dolla 2.0.0-alpha.46 → 2.0.0-alpha.47
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 -15
- package/dist/core/context.d.ts +2 -2
- package/dist/core/markup.d.ts +25 -24
- package/dist/core/nodes/dynamic.d.ts +2 -2
- package/dist/core/nodes/fragment.d.ts +2 -2
- package/dist/core/nodes/outlet.d.ts +2 -2
- package/dist/core/nodes/{list.d.ts → repeat.d.ts} +6 -6
- package/dist/core/nodes/view.d.ts +3 -3
- package/dist/core/signals-api.d.ts +42 -0
- package/dist/core/signals.d.ts +16 -194
- package/dist/core/store.d.ts +2 -2
- package/dist/fragment-vl5kFl1d.js +8 -0
- package/dist/fragment-vl5kFl1d.js.map +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +443 -398
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/jsx-runtime.js +2 -2
- package/dist/{markup-BJffA2Ls.js → markup-B-2w-v-S.js} +641 -736
- package/dist/markup-B-2w-v-S.js.map +1 -0
- package/dist/router/index.d.ts +22 -8
- package/dist/router/router.utils.d.ts +3 -3
- package/dist/translate/index.d.ts +10 -10
- package/dist/types.d.ts +9 -9
- package/docs/signals.md +82 -65
- package/notes/molecule.md +35 -0
- package/package.json +1 -1
- package/dist/core/ref.d.ts +0 -28
- package/dist/core/views/for.d.ts +0 -9
- package/dist/fragment-CYt92o5I.js +0 -8
- package/dist/fragment-CYt92o5I.js.map +0 -1
- package/dist/markup-BJffA2Ls.js.map +0 -1
- package/dist/router/router.d.ts +0 -0
- /package/dist/core/{signals.test.d.ts → signals-api.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -35,31 +35,51 @@ Dolla's goals include:
|
|
|
35
35
|
A basic view. Note that the view function is called exactly once when the view is first mounted. All changes to DOM nodes thereafter happen as a result of `$state` values changing.
|
|
36
36
|
|
|
37
37
|
```jsx
|
|
38
|
-
import Dolla, {
|
|
38
|
+
import Dolla, { $ } from "@manyducks.co/dolla";
|
|
39
39
|
|
|
40
40
|
function Counter(props, ctx) {
|
|
41
|
-
const count =
|
|
41
|
+
const count = $(0);
|
|
42
42
|
|
|
43
|
+
// An effect will re-run whenever any signal value accessed inside it changes.
|
|
43
44
|
ctx.effect(() => {
|
|
44
|
-
console.log(`Count is: ${count
|
|
45
|
+
console.log(`Count is: ${count()}`);
|
|
45
46
|
});
|
|
46
47
|
|
|
47
48
|
function increment() {
|
|
48
|
-
|
|
49
|
+
// Call signal function with a new value to set it...
|
|
50
|
+
count(count() + 1);
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
function decrement() {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
// ... or pass a function that takes the current value and returns the next.
|
|
55
|
+
count((value) => value - 1);
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
return (
|
|
57
59
|
<div>
|
|
58
|
-
|
|
60
|
+
{/* Signals can be slotted into the DOM to render them */}
|
|
61
|
+
<p>Counter: {count}</p>
|
|
59
62
|
<div>
|
|
60
63
|
<button on:click={increment}>+1</button>
|
|
61
64
|
<button on:click={decrement}>-1</button>
|
|
62
65
|
</div>
|
|
66
|
+
|
|
67
|
+
{/* We can derive a new signal on the fly and conditionally render something based on that condition */}
|
|
68
|
+
{when(
|
|
69
|
+
$(() => count() > 10),
|
|
70
|
+
<span>That's a lot of clicks!</span>,
|
|
71
|
+
)}
|
|
72
|
+
|
|
73
|
+
{/* ALT: Or slot a getter function into the DOM and have it conditionally render an element */}
|
|
74
|
+
{() => {
|
|
75
|
+
// DEV NOTE
|
|
76
|
+
// If we get Dynamic to track its rendered elements and diff them by keys
|
|
77
|
+
// then we may be able to do away with repeat and when and just do things like:
|
|
78
|
+
// <ul>{() => items().map(item => <li>{item}</li>)}</ul>
|
|
79
|
+
if (count() > 10) {
|
|
80
|
+
return <span>That's a lot of clicks!</span>;
|
|
81
|
+
}
|
|
82
|
+
}}
|
|
63
83
|
</div>
|
|
64
84
|
);
|
|
65
85
|
}
|
|
@@ -71,10 +91,10 @@ Dolla.mount(document.body, Counter);
|
|
|
71
91
|
|
|
72
92
|
```js
|
|
73
93
|
function MessageStore(options, ctx) {
|
|
74
|
-
const message =
|
|
94
|
+
const message = $("Hello world!");
|
|
75
95
|
|
|
76
96
|
ctx.effect(() => {
|
|
77
|
-
ctx.log(`Message is now: ${
|
|
97
|
+
ctx.log(`Message is now: ${message()}`);
|
|
78
98
|
// Calling `get()` inside an effect (or compose) function will track that reactive value as a dependency.
|
|
79
99
|
// Effects will re-run when a dependency updates.
|
|
80
100
|
});
|
|
@@ -82,12 +102,8 @@ function MessageStore(options, ctx) {
|
|
|
82
102
|
// Context objects contain methods for controlling the component, logging and attaching lifecycle hooks.
|
|
83
103
|
|
|
84
104
|
return {
|
|
85
|
-
message:
|
|
86
|
-
|
|
87
|
-
// Composed values update when their dependencies update.
|
|
88
|
-
|
|
89
|
-
setMessage: set(message),
|
|
90
|
-
// Creates a setter function to update the original message atom.
|
|
105
|
+
message: $(() => message()),
|
|
106
|
+
setMessage: (value: string) => message(value),
|
|
91
107
|
};
|
|
92
108
|
}
|
|
93
109
|
|
package/dist/core/context.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Dolla } from "./dolla";
|
|
2
2
|
import type { View } from "./nodes/view";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Source } from "./signals-api";
|
|
4
4
|
import type { Store, StoreFunction } from "./store";
|
|
5
5
|
export interface ElementContext {
|
|
6
6
|
/**
|
|
@@ -26,7 +26,7 @@ export interface ElementContext {
|
|
|
26
26
|
/**
|
|
27
27
|
* Current route layer of the nearest view.
|
|
28
28
|
*/
|
|
29
|
-
route?:
|
|
29
|
+
route?: Source<View<{}> | undefined>;
|
|
30
30
|
}
|
|
31
31
|
export interface ComponentContext {
|
|
32
32
|
/**
|
package/dist/core/markup.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Renderable } from "../types.js";
|
|
2
2
|
import type { ElementContext } from "./context.js";
|
|
3
3
|
import { View, type ViewContext, type ViewFunction, type ViewResult } from "./nodes/view.js";
|
|
4
|
-
import {
|
|
4
|
+
import { type MaybeSignal, type Signal } from "./signals-api.js";
|
|
5
5
|
/**
|
|
6
6
|
* Markup is a set of element metadata that hasn't been constructed into a MarkupElement yet.
|
|
7
7
|
*/
|
|
@@ -36,28 +36,37 @@ export interface MarkupElement {
|
|
|
36
36
|
export declare function isMarkup(value: any): value is Markup;
|
|
37
37
|
export declare function isMarkupElement(value: any): value is MarkupElement;
|
|
38
38
|
export declare function toMarkup(renderables: Renderable | Renderable[]): Markup[];
|
|
39
|
+
export declare enum MarkupType {
|
|
40
|
+
Text = "$text",
|
|
41
|
+
Repeat = "$repeat",
|
|
42
|
+
Dynamic = "$dynamic",
|
|
43
|
+
Outlet = "$outlet",
|
|
44
|
+
Fragment = "$fragment",
|
|
45
|
+
Node = "$node",
|
|
46
|
+
Portal = "$portal"
|
|
47
|
+
}
|
|
39
48
|
export interface MarkupAttributes {
|
|
40
|
-
|
|
49
|
+
[MarkupType.Text]: {
|
|
41
50
|
value: any;
|
|
42
51
|
};
|
|
43
|
-
|
|
44
|
-
items:
|
|
52
|
+
[MarkupType.Repeat]: {
|
|
53
|
+
items: Signal<any[]>;
|
|
45
54
|
keyFn: (value: any, index: number) => string | number | symbol;
|
|
46
|
-
renderFn: (item:
|
|
55
|
+
renderFn: (item: Signal<any>, index: Signal<number>, ctx: ViewContext) => ViewResult;
|
|
47
56
|
};
|
|
48
|
-
|
|
49
|
-
source:
|
|
57
|
+
[MarkupType.Dynamic]: {
|
|
58
|
+
source: Signal<Renderable>;
|
|
50
59
|
};
|
|
51
|
-
|
|
52
|
-
view:
|
|
60
|
+
[MarkupType.Outlet]: {
|
|
61
|
+
view: Signal<View<{}> | undefined>;
|
|
53
62
|
};
|
|
54
|
-
|
|
55
|
-
children:
|
|
63
|
+
[MarkupType.Fragment]: {
|
|
64
|
+
children: MaybeSignal<MarkupElement[]>;
|
|
56
65
|
};
|
|
57
|
-
|
|
66
|
+
[MarkupType.Node]: {
|
|
58
67
|
value: Node;
|
|
59
68
|
};
|
|
60
|
-
|
|
69
|
+
[MarkupType.Portal]: {
|
|
61
70
|
content: Renderable;
|
|
62
71
|
parent: Node;
|
|
63
72
|
};
|
|
@@ -65,27 +74,19 @@ export interface MarkupAttributes {
|
|
|
65
74
|
}
|
|
66
75
|
export declare function markup<T extends keyof MarkupAttributes>(type: T, attributes: MarkupAttributes[T], ...children: Renderable[]): Markup;
|
|
67
76
|
export declare function markup<I>(type: ViewFunction<I>, attributes?: I, ...children: any[]): Markup;
|
|
68
|
-
/**
|
|
69
|
-
* Generate markup with HTML in a tagged template literal.
|
|
70
|
-
*/
|
|
71
|
-
/**
|
|
72
|
-
* Displays content conditionally. When `condition` holds a truthy value, `thenContent` is displayed; when `condition` holds a falsy value, `elseContent` is displayed.
|
|
73
|
-
* @deprecated
|
|
74
|
-
*/
|
|
75
|
-
export declare function cond(condition: MaybeReactive<any>, thenContent?: Renderable, elseContent?: Renderable): Markup;
|
|
76
77
|
/**
|
|
77
78
|
* Displays `thenContent` when `condition` is truthy and `elseContent` when falsy.
|
|
78
79
|
*/
|
|
79
|
-
export declare function when(condition:
|
|
80
|
+
export declare function when(condition: MaybeSignal<any>, thenContent?: Renderable, elseContent?: Renderable): Markup;
|
|
80
81
|
/**
|
|
81
82
|
* Inverted `when`. Displays `thenContent` when `condition` is falsy and `elseContent` when truthy.
|
|
82
83
|
*/
|
|
83
|
-
export declare function unless(condition:
|
|
84
|
+
export declare function unless(condition: MaybeSignal<any>, thenContent?: Renderable, elseContent?: Renderable): Markup;
|
|
84
85
|
/**
|
|
85
86
|
* Calls `renderFn` for each item in `items`. Dynamically adds and removes views as items change.
|
|
86
87
|
* The result of `keyFn` is used to compare items and decide if item was added, removed or updated.
|
|
87
88
|
*/
|
|
88
|
-
export declare function
|
|
89
|
+
export declare function repeat<T>(items: MaybeSignal<T[]>, keyFn: (value: T, index: number) => string | number | symbol, renderFn: (item: Signal<T>, index: Signal<number>, ctx: ViewContext) => ViewResult): Markup;
|
|
89
90
|
/**
|
|
90
91
|
* Renders `content` into a `parent` node anywhere in the page, rather than its usual position in the view.
|
|
91
92
|
*/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Renderable } from "../../types.js";
|
|
2
2
|
import type { ElementContext } from "../context.js";
|
|
3
3
|
import { type MarkupElement } from "../markup.js";
|
|
4
|
-
import {
|
|
4
|
+
import { Signal } from "../signals-api.js";
|
|
5
5
|
import { IS_MARKUP_ELEMENT } from "../symbols.js";
|
|
6
6
|
interface DynamicOptions {
|
|
7
|
-
source:
|
|
7
|
+
source: Signal<Renderable>;
|
|
8
8
|
elementContext: ElementContext;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MarkupElement } from "../markup.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type MaybeSignal } from "../signals-api.js";
|
|
3
3
|
import { IS_MARKUP_ELEMENT } from "../symbols.js";
|
|
4
4
|
/**
|
|
5
5
|
* Manages several MarkupElements as one.
|
|
@@ -11,7 +11,7 @@ export declare class Fragment implements MarkupElement {
|
|
|
11
11
|
private source;
|
|
12
12
|
private elements;
|
|
13
13
|
private unsubscribe?;
|
|
14
|
-
constructor(source:
|
|
14
|
+
constructor(source: MaybeSignal<MarkupElement[]>);
|
|
15
15
|
mount(parent: Node, after?: Node | undefined): void;
|
|
16
16
|
unmount(parentIsUnmounting?: boolean): void;
|
|
17
17
|
private cleanup;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MarkupElement } from "../markup.js";
|
|
2
|
-
import {
|
|
2
|
+
import { type Signal } from "../signals-api.js";
|
|
3
3
|
import { IS_MARKUP_ELEMENT } from "../symbols.js";
|
|
4
4
|
import { View } from "./view.js";
|
|
5
5
|
/**
|
|
@@ -12,7 +12,7 @@ export declare class Outlet implements MarkupElement {
|
|
|
12
12
|
private view;
|
|
13
13
|
private mountedView?;
|
|
14
14
|
private unsubscribe?;
|
|
15
|
-
constructor(view:
|
|
15
|
+
constructor(view: Signal<View<{}> | undefined>);
|
|
16
16
|
mount(parent: Node, after?: Node | undefined): void;
|
|
17
17
|
unmount(parentIsUnmounting?: boolean): void;
|
|
18
18
|
private cleanup;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { type ElementContext } from "../context.js";
|
|
2
2
|
import { type MarkupElement } from "../markup.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type Signal } from "../signals-api.js";
|
|
4
4
|
import { IS_MARKUP_ELEMENT } from "../symbols.js";
|
|
5
5
|
import { type ViewContext, type ViewResult } from "./view.js";
|
|
6
|
-
interface
|
|
6
|
+
interface RepeatOptions<T> {
|
|
7
7
|
elementContext: ElementContext;
|
|
8
|
-
items:
|
|
8
|
+
items: Signal<T[]>;
|
|
9
9
|
keyFn: (item: T, index: number) => string | number | symbol;
|
|
10
|
-
renderFn: (item:
|
|
10
|
+
renderFn: (item: Signal<T>, index: Signal<number>, ctx: ViewContext) => ViewResult;
|
|
11
11
|
}
|
|
12
|
-
export declare class
|
|
12
|
+
export declare class Repeat<T> implements MarkupElement {
|
|
13
13
|
[IS_MARKUP_ELEMENT]: boolean;
|
|
14
14
|
domNode: Text;
|
|
15
15
|
private items;
|
|
@@ -19,7 +19,7 @@ export declare class List<T> implements MarkupElement {
|
|
|
19
19
|
private renderFn;
|
|
20
20
|
private keyFn;
|
|
21
21
|
get isMounted(): boolean;
|
|
22
|
-
constructor({ elementContext, items, renderFn, keyFn }:
|
|
22
|
+
constructor({ elementContext, items, renderFn, keyFn }: RepeatOptions<T>);
|
|
23
23
|
mount(parent: Node, after?: Node): void;
|
|
24
24
|
unmount(parentIsUnmounting?: boolean): void;
|
|
25
25
|
private _cleanup;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { ComponentContext, ElementContext, StoreConsumerContext, StoreProviderContext } from "../context.js";
|
|
2
2
|
import type { Logger } from "../dolla.js";
|
|
3
3
|
import { type Markup, type MarkupElement } from "../markup.js";
|
|
4
|
-
import { type
|
|
4
|
+
import { type Signal, type EffectCallback, type UnsubscribeFunction } from "../signals-api.js";
|
|
5
5
|
import { IS_MARKUP_ELEMENT } from "../symbols.js";
|
|
6
6
|
/**
|
|
7
7
|
* Any valid value that a View can return.
|
|
8
8
|
*/
|
|
9
|
-
export type ViewResult = Node |
|
|
9
|
+
export type ViewResult = Node | Signal<any> | Markup | Markup[] | null;
|
|
10
10
|
export type ViewFunction<P> = (this: ViewContext, props: P, context: ViewContext) => ViewResult;
|
|
11
11
|
/**
|
|
12
12
|
* A view that has been constructed into DOM nodes.
|
|
@@ -43,7 +43,7 @@ export interface ViewContext extends Omit<Logger, "setName">, ComponentContext,
|
|
|
43
43
|
* Passes a getter function to `callback` that will track reactive states and return their current values.
|
|
44
44
|
* Callback will be run each time a tracked state gets a new value.
|
|
45
45
|
*/
|
|
46
|
-
effect(callback: EffectCallback
|
|
46
|
+
effect(callback: EffectCallback): UnsubscribeFunction;
|
|
47
47
|
/**
|
|
48
48
|
* Displays this view's subroutes if mounted as a router view.
|
|
49
49
|
*/
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A getter that returns the current value held within the signal.
|
|
3
|
+
* If called inside a trackable scope this signal will be tracked as a dependency.
|
|
4
|
+
*/
|
|
5
|
+
export interface Signal<T> {
|
|
6
|
+
(): T;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Extends Signal with the ability to pass a value or an updater function to change the Signal's value.
|
|
10
|
+
*/
|
|
11
|
+
export interface Source<T> extends Signal<T> {
|
|
12
|
+
(value: T): void;
|
|
13
|
+
(updater: (value: T) => T): void;
|
|
14
|
+
}
|
|
15
|
+
export type MaybeSignal<T> = Signal<T> | T;
|
|
16
|
+
export type EqualityFunction<T> = (current: T, next: T) => boolean;
|
|
17
|
+
export interface SignalOptions<T> {
|
|
18
|
+
/**
|
|
19
|
+
* A function to compare the current and next values. Returning `true` means the value has changed.
|
|
20
|
+
*/
|
|
21
|
+
equals?: EqualityFunction<T>;
|
|
22
|
+
}
|
|
23
|
+
export declare function isSource<T>(value: MaybeSignal<T>): value is Source<T>;
|
|
24
|
+
export declare function peek<T>(value: MaybeSignal<T>): T;
|
|
25
|
+
export declare function get<T>(value: MaybeSignal<T>): T;
|
|
26
|
+
/**
|
|
27
|
+
* Function to be invoked for the effect. Can return an optional cleanup function to be called between invocations.
|
|
28
|
+
*/
|
|
29
|
+
export type EffectCallback = () => void | (() => void);
|
|
30
|
+
export type UnsubscribeFunction = () => void;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a tracked scope that re-runs whenever the values of any tracked reactives changes.
|
|
33
|
+
* Reactives are tracked by accessing their `value` within the body of the function.
|
|
34
|
+
*
|
|
35
|
+
* NOTE: You must call the unsubscribe function to stop watching for changes.
|
|
36
|
+
* If you are using an effect inside a View or Store, use `ctx.effect` instead, which cleans up automatically when the component unmounts.
|
|
37
|
+
*/
|
|
38
|
+
export declare function effect(fn: EffectCallback): UnsubscribeFunction;
|
|
39
|
+
export declare function $<T>(compute: () => MaybeSignal<T>, options?: SignalOptions<T>): Signal<T>;
|
|
40
|
+
export declare function $<T>(value: T, options?: SignalOptions<T>): Source<T>;
|
|
41
|
+
export declare function $<T>(value: undefined, options?: SignalOptions<T>): Source<T | undefined>;
|
|
42
|
+
export declare function $<T>(): Source<T | undefined>;
|
package/dist/core/signals.d.ts
CHANGED
|
@@ -1,200 +1,22 @@
|
|
|
1
|
-
import { type Dependency, type Subscriber } from "alien-signals";
|
|
1
|
+
import { type Dependency, type Subscriber, SubscriberFlags } from "alien-signals";
|
|
2
|
+
import type { EqualityFunction } from "./signals-api";
|
|
2
3
|
export interface Effect extends Subscriber, Dependency {
|
|
3
|
-
fn(): void;
|
|
4
|
-
}
|
|
5
|
-
export interface Computed<T = any> extends Signal<T | undefined>, Subscriber {
|
|
6
|
-
getter: (cachedValue?: T) => T;
|
|
7
|
-
equals: EqualityFunction<T>;
|
|
8
|
-
}
|
|
9
|
-
export interface Signal<T = any> extends Dependency {
|
|
10
|
-
currentValue: T;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* A readable reactive state object.
|
|
14
|
-
*/
|
|
15
|
-
export interface Reactive<T> {
|
|
16
|
-
/**
|
|
17
|
-
* A name provided at the creation of this reactive.
|
|
18
|
-
*/
|
|
19
|
-
readonly name?: string;
|
|
20
4
|
/**
|
|
21
|
-
*
|
|
5
|
+
* Effect function. Can return an optional cleanup callback to be invoked before the next fn() call.
|
|
22
6
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* Returns the current value without tracking this reactive as a dependency when called within `effect` or `compose`.
|
|
26
|
-
*/
|
|
27
|
-
peek(): T;
|
|
28
|
-
/**
|
|
29
|
-
* The current value.
|
|
30
|
-
* @deprecated use `get()` and `set()`
|
|
31
|
-
*/
|
|
32
|
-
readonly value: T;
|
|
7
|
+
fn(): (() => void) | void;
|
|
8
|
+
cleanup?: () => void;
|
|
33
9
|
}
|
|
34
|
-
export
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* A function to compare the current and next values. Returning `true` means the value has changed.
|
|
38
|
-
*/
|
|
39
|
-
export type EqualityFunction<T> = (current: T, next: T) => boolean;
|
|
40
|
-
export interface ReactiveOptions<T> {
|
|
41
|
-
/**
|
|
42
|
-
* A label for debugging purposes.
|
|
43
|
-
*/
|
|
44
|
-
name?: string;
|
|
45
|
-
/**
|
|
46
|
-
* A function to compare the current and next values. Returning `true` means the value has changed.
|
|
47
|
-
*/
|
|
48
|
-
equals?: EqualityFunction<T>;
|
|
10
|
+
export interface Computed<T = any> extends Value<T | undefined>, Subscriber {
|
|
11
|
+
getter: (cachedValue?: T) => T;
|
|
12
|
+
equals: EqualityFunction<T>;
|
|
49
13
|
}
|
|
50
|
-
export
|
|
51
|
-
|
|
52
|
-
get name(): string;
|
|
53
|
-
get [Symbol.toStringTag](): string;
|
|
54
|
-
constructor(value: T, options?: ReactiveOptions<T>);
|
|
55
|
-
/**
|
|
56
|
-
* Returns the latest value. The signal is tracked as a dependency if called within `effect` or `compose`.
|
|
57
|
-
*/
|
|
58
|
-
get(): T;
|
|
59
|
-
/**
|
|
60
|
-
* Returns the latest value. The signal is NOT tracked if called within `effect` or `compose`.
|
|
61
|
-
*/
|
|
62
|
-
peek(): T;
|
|
63
|
-
/**
|
|
64
|
-
* Replaces the current value with `next`.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* const count = atom(0);
|
|
68
|
-
* count.set(2);
|
|
69
|
-
* count.set(count.get() + 1);
|
|
70
|
-
*/
|
|
71
|
-
set(next: T): void;
|
|
72
|
-
/**
|
|
73
|
-
* Passes the current value to `fn` and sets the return value as the next value.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* const count = atom(0);
|
|
77
|
-
* count.update((current) => current + 1);
|
|
78
|
-
* count.update((current) => current * 5);
|
|
79
|
-
*
|
|
80
|
-
* // Also works very well with Immer `produce` for complex objects.
|
|
81
|
-
* const items = atom([{ name: "Alice", age: 26 }, { name: "Bob", age: 33 }]);
|
|
82
|
-
*
|
|
83
|
-
* // Without Immer:
|
|
84
|
-
* items.update((current) => {
|
|
85
|
-
* // Return a new array with Bob's age increased by 1.
|
|
86
|
-
* const newItems = [...current];
|
|
87
|
-
* newItems[1] = {
|
|
88
|
-
* ...newItems[1],
|
|
89
|
-
* age: newItems[1].age + 1
|
|
90
|
-
* };
|
|
91
|
-
* return newItems;
|
|
92
|
-
* });
|
|
93
|
-
*
|
|
94
|
-
* // With Immer:
|
|
95
|
-
* import { produce } from "immer";
|
|
96
|
-
*
|
|
97
|
-
* items.update(produce((draft) => {
|
|
98
|
-
* // Mutate draft to increase Bob's age by 1.
|
|
99
|
-
* // Results in a new object with this patch applied.
|
|
100
|
-
* draft[1].age++;
|
|
101
|
-
* }));
|
|
102
|
-
*/
|
|
103
|
-
update(fn: (current: T) => T): void;
|
|
104
|
-
/**
|
|
105
|
-
* @deprecated use `get()`
|
|
106
|
-
*/
|
|
107
|
-
get value(): T;
|
|
108
|
-
/**
|
|
109
|
-
* @deprecated use `set()`
|
|
110
|
-
*/
|
|
111
|
-
set value(next: T);
|
|
14
|
+
export interface Value<T = any> extends Dependency {
|
|
15
|
+
current: T;
|
|
112
16
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
export declare function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
* Atom values can be read and updated with the `value` property
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* const count = atom<number>();
|
|
123
|
-
* count.set(5);
|
|
124
|
-
* count.get(); // 5
|
|
125
|
-
*/
|
|
126
|
-
export declare function atom<T>(): Atom<T | undefined>;
|
|
127
|
-
/**
|
|
128
|
-
* Creates a simple reactive container that stores a value.
|
|
129
|
-
* Atom values can be read and updated with the `value` property.
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* const count = atom(1);
|
|
133
|
-
* count.set(count.get() + 1);
|
|
134
|
-
* count.get(); // 2
|
|
135
|
-
*/
|
|
136
|
-
export declare function atom<T>(value: T, options?: ReactiveOptions<T>): Atom<T>;
|
|
137
|
-
/**
|
|
138
|
-
* Creates a simple reactive container that stores a value.
|
|
139
|
-
* Atom values can be read and updated with the `value` property.
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* const count = atom(1);
|
|
143
|
-
* count.value++;
|
|
144
|
-
* count.value; // 2
|
|
145
|
-
*/
|
|
146
|
-
export declare function atom<T>(value?: T, options?: ReactiveOptions<T>): Atom<T | undefined>;
|
|
147
|
-
type ComposeCallback<T> = (previousValue?: T) => MaybeReactive<T>;
|
|
148
|
-
/**
|
|
149
|
-
* Creates a reactive container that derives its value from other reactive values that it tracks.
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* const count = atom(1);
|
|
153
|
-
* const doubled = compose(() => count.get() * 2);
|
|
154
|
-
*/
|
|
155
|
-
export declare function compose<T>(fn: ComposeCallback<T>, options?: ReactiveOptions<T>): Reactive<T>;
|
|
156
|
-
/**
|
|
157
|
-
* Takes a new value to set, or a callback that receives the current value and returns a new value to set.
|
|
158
|
-
*/
|
|
159
|
-
type Setter<T> = (next: T | ((current: T) => T)) => void;
|
|
160
|
-
export declare function set<T>(atom: Atom<T>): Setter<T>;
|
|
161
|
-
export declare function set<T>(atom: Atom<T>, next: T | ((current: T) => T)): void;
|
|
162
|
-
/**
|
|
163
|
-
* Returns the current value from a reactive _and track it_ if called in a `compose` or `effect` scope.
|
|
164
|
-
* If a non-reactive value is passed it will just be returned untracked.
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* const count = atom(1);
|
|
168
|
-
* const value = get(count); // 1
|
|
169
|
-
*
|
|
170
|
-
* const value = get(5); // 5
|
|
171
|
-
*/
|
|
172
|
-
export declare function get<T>(value: MaybeReactive<T>): T;
|
|
173
|
-
/**
|
|
174
|
-
* Returns the current value from a reactive (without tracking).
|
|
175
|
-
* If a non-reactive value is passed it will be returned.
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
178
|
-
* ctx.effect(() => {
|
|
179
|
-
* const doubled = get(count) * 2; // `count` will be tracked
|
|
180
|
-
*
|
|
181
|
-
* const doubled = peek(count) * 2; // `count` will NOT be tracked
|
|
182
|
-
* });
|
|
183
|
-
*/
|
|
184
|
-
export declare function peek<T>(value: MaybeReactive<T>): T;
|
|
185
|
-
export declare function untrack(fn: () => void): void;
|
|
186
|
-
/**
|
|
187
|
-
* Registers a callback that will receive a list of dependencies that were tracked within the scope this function was called in.
|
|
188
|
-
*/
|
|
189
|
-
export declare function getTracked(fn: (tracked: Reactive<unknown>[]) => void): void;
|
|
190
|
-
export type EffectCallback = () => void;
|
|
191
|
-
export type EffectOptions = {};
|
|
192
|
-
/**
|
|
193
|
-
* Creates a tracked scope that re-runs whenever the values of any tracked reactives changes.
|
|
194
|
-
* Reactives are tracked by accessing their `value` within the body of the function.
|
|
195
|
-
*
|
|
196
|
-
* NOTE: You must call the unsubscribe function to stop watching for changes.
|
|
197
|
-
* If you are using an effect inside a View or Store, use `ctx.effect` instead, which cleans up automatically when the component unmounts.
|
|
198
|
-
*/
|
|
199
|
-
export declare function effect(fn: EffectCallback, options?: EffectOptions): UnsubscribeFunction;
|
|
200
|
-
export {};
|
|
17
|
+
export declare const link: (dep: Dependency, sub: Subscriber) => import("alien-signals").Link | undefined, propagate: (link: import("alien-signals").Link) => void, updateDirtyFlag: (sub: Subscriber, flags: SubscriberFlags) => boolean, startTracking: (sub: Subscriber) => void, endTracking: (sub: Subscriber) => void, processEffectNotifications: () => void, processComputedUpdate: (computed: Dependency & Subscriber, flags: SubscriberFlags) => void, processPendingInnerEffects: (sub: Subscriber, flags: SubscriberFlags) => void;
|
|
18
|
+
export declare let activeSub: Subscriber | undefined;
|
|
19
|
+
export declare function queueEffect(e: Effect): void;
|
|
20
|
+
export declare function stopEffect(this: Effect): void;
|
|
21
|
+
export declare function pauseTracking(): void;
|
|
22
|
+
export declare function resumeTracking(): void;
|
package/dist/core/store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComponentContext, ElementContext, StoreConsumerContext } from "./context.js";
|
|
2
2
|
import type { Logger } from "./dolla.js";
|
|
3
|
-
import { type EffectCallback, type
|
|
3
|
+
import { type EffectCallback, type UnsubscribeFunction } from "./signals-api.js";
|
|
4
4
|
export type StoreFunction<Options, Value> = (this: StoreContext, options: Options, context: StoreContext) => Value;
|
|
5
5
|
export type StoreFactory<Options, Value> = Options extends undefined ? () => Store<Options, Value> : (options: Options) => Store<Options, Value>;
|
|
6
6
|
export interface StoreContext extends Omit<Logger, "setName">, ComponentContext, StoreConsumerContext {
|
|
@@ -20,7 +20,7 @@ export interface StoreContext extends Omit<Logger, "setName">, ComponentContext,
|
|
|
20
20
|
* Passes a getter function to `callback` that will track reactive states and return their current values.
|
|
21
21
|
* Callback will be run each time a tracked state gets a new value.
|
|
22
22
|
*/
|
|
23
|
-
effect(callback: EffectCallback
|
|
23
|
+
effect(callback: EffectCallback): UnsubscribeFunction;
|
|
24
24
|
}
|
|
25
25
|
export declare class Store<Options, Value> {
|
|
26
26
|
readonly fn: StoreFunction<Options, Value>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fragment-vl5kFl1d.js","sources":["../src/core/views/fragment.ts"],"sourcesContent":["import type { Renderable } from \"../../types.js\";\nimport { markup } from \"../markup.js\";\nimport { type ViewContext } from \"../nodes/view.js\";\n\n/**\n * A utility view that displays its children.\n */\nexport function Fragment(props: { children?: Renderable }, ctx: ViewContext) {\n return markup(\"$dynamic\", { source: () => props.children });\n}\n"],"names":["Fragment","props","ctx","markup"],"mappings":";AAOgB,SAAAA,EAASC,GAAkCC,GAAkB;AAC3E,SAAOC,EAAO,YAAY,EAAE,QAAQ,MAAMF,EAAM,UAAU;AAC5D;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type {
|
|
1
|
+
export { $, effect, get, peek } from "./core/signals-api.js";
|
|
2
|
+
export type { MaybeSignal, Signal, Source } from "./core/signals-api.js";
|
|
3
3
|
export { deepEqual, shallowEqual, strictEqual } from "./utils.js";
|
|
4
|
-
export { ref, type Ref } from "./core/ref.js";
|
|
5
4
|
export { type StoreContext, type StoreFunction } from "./core/store.js";
|
|
6
5
|
export { createRouter, type Router, type RouterOptions } from "./router/index.js";
|
|
7
|
-
export {
|
|
6
|
+
export { markup, portal, repeat, unless, when } from "./core/markup.js";
|
|
8
7
|
export type { Markup, MarkupElement } from "./core/markup.js";
|
|
9
8
|
import { Dolla } from "./core/dolla.js";
|
|
10
9
|
declare const dolla: Dolla;
|
|
11
10
|
export default dolla;
|
|
12
|
-
export declare const t: (selector: string, options?: import("./translate/index.js").TOptions) => import("./core/signals.js").
|
|
11
|
+
export declare const t: (selector: string, options?: import("./translate/index.js").TOptions) => import("./core/signals-api.js").Signal<string>;
|
|
12
|
+
export declare const i18n: import("./translate/index.js").I18n;
|
|
13
13
|
export declare const http: import("./http/index.js").HTTP;
|
|
14
14
|
export declare const createLogger: (name: string, options?: import("./core/dolla.js").LoggerOptions) => import("./core/dolla.js").Logger;
|
|
15
15
|
export type { Dolla, Environment, Logger, LoggerErrorContext, LoggerOptions, Loggles } from "./core/dolla.js";
|