@manyducks.co/dolla 2.0.0-alpha.31 → 2.0.0-alpha.33
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 +2 -2
- package/dist/core/context.d.ts +27 -20
- package/dist/core/dolla.d.ts +18 -10
- package/dist/core/markup.d.ts +23 -2
- package/dist/core/nodes/view.d.ts +1 -2
- package/dist/core/store.d.ts +3 -9
- package/dist/index.d.ts +1 -2
- package/dist/index.js +231 -234
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.js +2 -2
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/markup-Dbw-610R.js +1525 -0
- package/dist/markup-Dbw-610R.js.map +1 -0
- package/dist/modules/router.d.ts +2 -2
- package/docs/i18n.md +2 -2
- package/docs/router.md +12 -9
- package/docs/state.md +2 -2
- package/docs/stores.md +18 -18
- package/docs/views.md +56 -70
- package/notes/readme-scratch.md +29 -7
- package/notes/scratch.md +135 -0
- package/notes/stores.md +17 -37
- package/notes/viewstate.md +15 -0
- package/package.json +1 -1
- package/build.js +0 -34
- package/dist/markup-D1i09ddt.js +0 -1563
- package/dist/markup-D1i09ddt.js.map +0 -1
package/README.md
CHANGED
|
@@ -35,9 +35,9 @@ 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
|
```js
|
|
38
|
-
import Dolla, { createState
|
|
38
|
+
import Dolla, { createState } from "@manyducks.co/dolla";
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
function Counter() {
|
|
41
41
|
const [$count, setCount] = createState(0);
|
|
42
42
|
|
|
43
43
|
function increment() {
|
package/dist/core/context.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Emitter } from "@manyducks.co/emitter";
|
|
2
|
-
import type { Store, StoreFactory } from "./store";
|
|
3
2
|
import type { Dolla } from "./dolla";
|
|
3
|
+
import type { Store, StoreFunction } from "./store";
|
|
4
4
|
interface ContextEmitterEvents {
|
|
5
|
-
[eventName: string | symbol]: [ContextEvent
|
|
5
|
+
[eventName: string | symbol]: [ContextEvent, ...args: any[]];
|
|
6
6
|
}
|
|
7
7
|
export interface ElementContext {
|
|
8
8
|
/**
|
|
@@ -20,7 +20,7 @@ export interface ElementContext {
|
|
|
20
20
|
/**
|
|
21
21
|
* Stores attached to this context.
|
|
22
22
|
*/
|
|
23
|
-
stores: Map<
|
|
23
|
+
stores: Map<StoreFunction<any, any>, Store<any, any>>;
|
|
24
24
|
/**
|
|
25
25
|
* A reference to the parent context.
|
|
26
26
|
*/
|
|
@@ -39,7 +39,7 @@ export interface ElementContext {
|
|
|
39
39
|
* Wrapping listeners is necessary because the context API's `.on` method does not pass the event name to "*" listeners while the emitter does.
|
|
40
40
|
* ContextEvent objects already have the event name stored as `event.type`.
|
|
41
41
|
*/
|
|
42
|
-
export type WildcardListenerMap = Map<(event: ContextEvent
|
|
42
|
+
export type WildcardListenerMap = Map<(event: ContextEvent, ...args: any[]) => void, (eventName: string | symbol, event: ContextEvent, ...args: any[]) => void>;
|
|
43
43
|
export interface ComponentContext {
|
|
44
44
|
/**
|
|
45
45
|
* Sets a context variable and returns its value.
|
|
@@ -50,45 +50,52 @@ export interface ComponentContext {
|
|
|
50
50
|
*/
|
|
51
51
|
get<T>(key: string | symbol): T | null;
|
|
52
52
|
/**
|
|
53
|
-
* Adds a listener to be called when `
|
|
53
|
+
* Adds a listener to be called when an event with a matching `type` is emitted.
|
|
54
54
|
*/
|
|
55
|
-
on<T = unknown>(
|
|
55
|
+
on<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
|
|
56
56
|
/**
|
|
57
|
-
* Removes a listener from the list to be called when `
|
|
57
|
+
* Removes a listener from the list to be called when an event with a matching `type` is emitted.
|
|
58
58
|
*/
|
|
59
|
-
off<T = unknown>(
|
|
59
|
+
off<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
|
|
60
60
|
/**
|
|
61
|
-
* Adds a listener to be called when `
|
|
61
|
+
* Adds a listener to be called when an event with a matching `type` is emitted. The listener is immediately removed after being called once.
|
|
62
62
|
*/
|
|
63
|
-
once<T = unknown>(
|
|
63
|
+
once<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
|
|
64
64
|
/**
|
|
65
65
|
* Emits a new event to all listeners.
|
|
66
66
|
*/
|
|
67
|
-
emit<T = unknown>(
|
|
67
|
+
emit<T = unknown>(type: string, ...args: any[]): boolean;
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* A context capable of hosting stores.
|
|
71
71
|
*/
|
|
72
72
|
export interface StorableContext extends ComponentContext {
|
|
73
73
|
/**
|
|
74
|
-
* Attaches a new store to this context.
|
|
74
|
+
* Attaches a new store to this context and returns it.
|
|
75
75
|
*/
|
|
76
|
-
|
|
76
|
+
provide<Value>(store: StoreFunction<{}, Value>): Value;
|
|
77
|
+
/**
|
|
78
|
+
* Attaches a new store to this context and returns it.
|
|
79
|
+
*/
|
|
80
|
+
provide<Value>(store: StoreFunction<undefined, Value>): Value;
|
|
81
|
+
/**
|
|
82
|
+
* Attaches a new store to this context and returns it.
|
|
83
|
+
*/
|
|
84
|
+
provide<Options, Value>(store: StoreFunction<Options, Value>, options: Options): Value;
|
|
77
85
|
/**
|
|
78
86
|
* Gets the closest instance of a store. Throws an error if the store isn't provided higher in the tree.
|
|
79
87
|
*/
|
|
80
|
-
|
|
88
|
+
use<Value>(store: StoreFunction<any, Value>): Value;
|
|
81
89
|
}
|
|
82
90
|
/**
|
|
83
91
|
* An event emitted from and received by a Dolla context. These are separate from DOM events.
|
|
84
92
|
*/
|
|
85
|
-
export declare class ContextEvent
|
|
93
|
+
export declare class ContextEvent {
|
|
86
94
|
#private;
|
|
87
|
-
type: string;
|
|
88
|
-
|
|
89
|
-
get
|
|
90
|
-
|
|
91
|
-
stopPropagation(): void;
|
|
95
|
+
constructor(type: string);
|
|
96
|
+
get type(): string;
|
|
97
|
+
get isStopped(): boolean;
|
|
98
|
+
stop(): void;
|
|
92
99
|
get [Symbol.toStringTag](): string;
|
|
93
100
|
}
|
|
94
101
|
export {};
|
package/dist/core/dolla.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { type Markup, type MarkupElement } from "./markup.js";
|
|
|
8
8
|
import { type ViewElement, type ViewFunction } from "./nodes/view.js";
|
|
9
9
|
import { createRef, isRef } from "./ref.js";
|
|
10
10
|
import { createState, createWatcher, derive, isState, toState, toValue } from "./state.js";
|
|
11
|
-
import {
|
|
11
|
+
import { StoreFunction } from "./store.js";
|
|
12
12
|
export type Environment = "development" | "production";
|
|
13
13
|
/**
|
|
14
14
|
* Log type toggles. Each message category can be turned on or off or enabled only in a specific environment.
|
|
@@ -97,29 +97,37 @@ export declare class Dolla implements StorableContext {
|
|
|
97
97
|
* Returns an object of all context variables stored at the app level.
|
|
98
98
|
*/
|
|
99
99
|
/**
|
|
100
|
-
* Adds a listener to be called when `
|
|
100
|
+
* Adds a listener to be called when an event with a matching `type` is emitted.
|
|
101
101
|
*/
|
|
102
|
-
on<T = unknown>(
|
|
102
|
+
on<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
|
|
103
103
|
/**
|
|
104
|
-
* Removes a listener from the list to be called when `
|
|
104
|
+
* Removes a listener from the list to be called when an event with a matching `type` is emitted.
|
|
105
105
|
*/
|
|
106
|
-
off<T = unknown>(
|
|
106
|
+
off<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
|
|
107
107
|
/**
|
|
108
|
-
* Adds a listener to be called when `
|
|
108
|
+
* Adds a listener to be called when an event with a matching `type` is emitted. The listener is immediately removed after being called once.
|
|
109
109
|
*/
|
|
110
|
-
once<T = unknown>(
|
|
110
|
+
once<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
|
|
111
111
|
/**
|
|
112
112
|
* Emits a new event to all listeners.
|
|
113
113
|
*/
|
|
114
|
-
emit<T = unknown>(
|
|
114
|
+
emit<T = unknown>(type: string, ...args: any[]): boolean;
|
|
115
115
|
/**
|
|
116
116
|
* Attaches a new store to this context.
|
|
117
117
|
*/
|
|
118
|
-
|
|
118
|
+
provide<Value>(store: StoreFunction<{}, Value>): Value;
|
|
119
|
+
/**
|
|
120
|
+
* Attaches a new store to this context.
|
|
121
|
+
*/
|
|
122
|
+
provide<Value>(store: StoreFunction<undefined, Value>): Value;
|
|
123
|
+
/**
|
|
124
|
+
* Attaches a new store to this context.
|
|
125
|
+
*/
|
|
126
|
+
provide<Options, Value>(store: StoreFunction<Options, Value>, options: Options): Value;
|
|
119
127
|
/**
|
|
120
128
|
* Gets the nearest instance of a store. Throws an error if the store isn't provided higher in the tree.
|
|
121
129
|
*/
|
|
122
|
-
|
|
130
|
+
use<Value>(store: StoreFunction<any, Value>): Value;
|
|
123
131
|
mount(selector: string, router: Router): Promise<void>;
|
|
124
132
|
mount(selector: string, view: ViewFunction<any>): Promise<void>;
|
|
125
133
|
mount(element: Element, router: Router): Promise<void>;
|
package/dist/core/markup.d.ts
CHANGED
|
@@ -2,6 +2,27 @@ import type { Renderable } from "../types.js";
|
|
|
2
2
|
import type { ElementContext } from "./context.js";
|
|
3
3
|
import { type ViewContext, type ViewFunction, type ViewResult } from "./nodes/view.js";
|
|
4
4
|
import { type MaybeState, type State } from "./state.js";
|
|
5
|
+
import { IS_MARKUP } from "./symbols.js";
|
|
6
|
+
export declare class _Markup implements Markup {
|
|
7
|
+
[IS_MARKUP]: boolean;
|
|
8
|
+
static text(value: MaybeState<string>): _Markup;
|
|
9
|
+
static from(renderable: Renderable): Markup;
|
|
10
|
+
/**
|
|
11
|
+
* In the case of a view, type will be the View function itself. It can also hold an identifier for special nodes like "$cond", "$repeat", etc.
|
|
12
|
+
* DOM nodes can be created by name, such as HTML elements like "div", "ul" or "span", SVG elements like ""
|
|
13
|
+
*/
|
|
14
|
+
type: string | ViewFunction<any>;
|
|
15
|
+
/**
|
|
16
|
+
* Data that will be passed to a new MarkupElement instance when it is constructed.
|
|
17
|
+
*/
|
|
18
|
+
props: Record<string, any> | undefined;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
children: Markup[];
|
|
23
|
+
constructor(type: string | ViewFunction<any>, props?: Record<string, any>, children?: Renderable[]);
|
|
24
|
+
toElement(context: ElementContext): MarkupElement;
|
|
25
|
+
}
|
|
5
26
|
/**
|
|
6
27
|
* Markup is a set of element metadata that hasn't been constructed into a MarkupElement yet.
|
|
7
28
|
*/
|
|
@@ -68,9 +89,9 @@ export declare function createMarkup<I>(type: ViewFunction<I>, attributes?: I, .
|
|
|
68
89
|
*/
|
|
69
90
|
export declare const html: (strings: TemplateStringsArray, ...values: any[]) => Markup | Markup[];
|
|
70
91
|
/**
|
|
71
|
-
* Displays content conditionally. When `
|
|
92
|
+
* Displays content conditionally. When `condition` holds a truthy value, `thenContent` is displayed; when `condition` holds a falsy value, `elseContent` is displayed.
|
|
72
93
|
*/
|
|
73
|
-
export declare function cond(
|
|
94
|
+
export declare function cond(condition: MaybeState<any>, thenContent?: Renderable, elseContent?: Renderable): Markup;
|
|
74
95
|
/**
|
|
75
96
|
* Calls `renderFn` for each item in `items`. Dynamically adds and removes views as items change.
|
|
76
97
|
* The result of `keyFn` is used to compare items and decide if item was added, removed or updated.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Emitter } from "@manyducks.co/emitter";
|
|
2
|
-
import { type
|
|
2
|
+
import { type ElementContext, type StorableContext, type WildcardListenerMap } from "../context.js";
|
|
3
3
|
import type { Logger } from "../dolla.js";
|
|
4
4
|
import { type Markup, type MarkupElement } from "../markup.js";
|
|
5
5
|
import { type MaybeState, type State, type StateValues, type StopFunction } from "../state.js";
|
|
@@ -60,7 +60,6 @@ export interface ViewContext extends Logger, StorableContext {
|
|
|
60
60
|
*/
|
|
61
61
|
outlet(): Markup;
|
|
62
62
|
}
|
|
63
|
-
export declare function createView<Props extends Record<string, any> = Record<string, unknown>>(fn: ViewFunction<Props>): ViewFunction<Props>;
|
|
64
63
|
type ViewEvents = {
|
|
65
64
|
beforeMount: [];
|
|
66
65
|
mounted: [];
|
package/dist/core/store.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Emitter } from "@manyducks.co/emitter";
|
|
2
|
-
import { type
|
|
2
|
+
import { type ComponentContext, type ElementContext, type WildcardListenerMap } from "./context.js";
|
|
3
3
|
import type { Logger } from "./dolla.js";
|
|
4
4
|
import { type MaybeState, type StateValues, type StopFunction } from "./state.js";
|
|
5
5
|
export type StoreFunction<Options, Value> = (this: StoreContext, options: Options, context: StoreContext) => Value;
|
|
@@ -28,8 +28,7 @@ type StoreEvents = {
|
|
|
28
28
|
unmounted: [];
|
|
29
29
|
};
|
|
30
30
|
export declare class Store<Options, Value> {
|
|
31
|
-
readonly
|
|
32
|
-
private _fn;
|
|
31
|
+
readonly fn: StoreFunction<Options, Value>;
|
|
33
32
|
private _options;
|
|
34
33
|
/**
|
|
35
34
|
* Value is guaranteed to be set after `attach` is called.
|
|
@@ -42,7 +41,7 @@ export declare class Store<Options, Value> {
|
|
|
42
41
|
_logger: Logger;
|
|
43
42
|
_watcher: import("./state.js").StateWatcher;
|
|
44
43
|
get name(): string;
|
|
45
|
-
constructor(
|
|
44
|
+
constructor(fn: StoreFunction<Options, Value>, options: Options);
|
|
46
45
|
/**
|
|
47
46
|
* Attaches this Store to the elementContext.
|
|
48
47
|
* Returns false if there was already an instance attached, and true otherwise.
|
|
@@ -51,12 +50,7 @@ export declare class Store<Options, Value> {
|
|
|
51
50
|
handleMount(): void;
|
|
52
51
|
handleUnmount(): void;
|
|
53
52
|
}
|
|
54
|
-
export declare function isStoreFactory<Options, Value>(value: any): value is StoreFactory<Options, Value>;
|
|
55
53
|
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
54
|
export declare class StoreError extends Error {
|
|
61
55
|
}
|
|
62
56
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
export { createState, derive, isState, toState, toValue } from "./core/state.js";
|
|
2
2
|
export type { MaybeState, Setter, State, StopFunction } from "./core/state.js";
|
|
3
3
|
export { createRef, isRef, type Ref } from "./core/ref.js";
|
|
4
|
-
export {
|
|
4
|
+
export { type StoreFunction, type StoreContext } from "./core/store.js";
|
|
5
5
|
export { createRouter, type Router, type RouterOptions } from "./modules/router.js";
|
|
6
6
|
export { deepEqual, shallowEqual, strictEqual } from "./utils.js";
|
|
7
7
|
export { cond, createMarkup, html, portal, repeat } from "./core/markup.js";
|
|
8
8
|
export type { Markup, MarkupElement } from "./core/markup.js";
|
|
9
|
-
export { createView } from "./core/nodes/view.js";
|
|
10
9
|
import { Dolla } from "./core/dolla.js";
|
|
11
10
|
declare const dolla: Dolla;
|
|
12
11
|
export default dolla;
|