@manyducks.co/dolla 2.0.0-alpha.30 → 2.0.0-alpha.32

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 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, createView } from "@manyducks.co/dolla";
38
+ import Dolla, { createState } from "@manyducks.co/dolla";
39
39
 
40
- const Counter = createView(function (props) {
40
+ function Counter() {
41
41
  const [$count, setCount] = createState(0);
42
42
 
43
43
  function increment() {
@@ -1,6 +1,6 @@
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
5
  [eventName: string | symbol]: [ContextEvent<any>];
6
6
  }
@@ -20,7 +20,7 @@ export interface ElementContext {
20
20
  /**
21
21
  * Stores attached to this context.
22
22
  */
23
- stores: Map<string, Store<any, any>>;
23
+ stores: Map<StoreFunction<any, any>, Store<any, any>>;
24
24
  /**
25
25
  * A reference to the parent context.
26
26
  */
@@ -73,11 +73,19 @@ export interface StorableContext extends ComponentContext {
73
73
  /**
74
74
  * Attaches a new store to this context.
75
75
  */
76
- attachStore(store: Store<any, any>): void;
76
+ attachStore(store: StoreFunction<{}, any>): void;
77
+ /**
78
+ * Attaches a new store to this context.
79
+ */
80
+ attachStore(store: StoreFunction<undefined, any>): void;
81
+ /**
82
+ * Attaches a new store to this context.
83
+ */
84
+ attachStore<Options>(store: StoreFunction<Options, any>, options: Options): void;
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
- useStore<Value>(factory: StoreFactory<any, Value>): Value;
88
+ useStore<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.
@@ -1,6 +1,6 @@
1
1
  import { HTTP } from "../modules/http.js";
2
2
  import { I18n } from "../modules/i18n.js";
3
- import { Router } from "../modules/router.js";
3
+ import { type Router } from "../modules/router.js";
4
4
  import { type CrashViewProps } from "../views/default-crash-view.js";
5
5
  import { Batch } from "./batch.js";
6
6
  import { ContextEvent, type StorableContext } from "./context.js";
@@ -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 { type Store, type StoreFactory } from "./store.js";
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.
@@ -48,7 +48,6 @@ export declare class Dolla implements StorableContext {
48
48
  private readonly stats;
49
49
  readonly http: HTTP;
50
50
  readonly i18n: I18n;
51
- readonly router: Router;
52
51
  constructor();
53
52
  watch: <I extends import("./state.js").MaybeState<any>[]>(states: [...I], fn: (...currentValues: import("./state.js").StateValues<I>) => void) => import("./state.js").StopFunction;
54
53
  createState: typeof createState;
@@ -81,7 +80,7 @@ export declare class Dolla implements StorableContext {
81
80
  /**
82
81
  * Returns the HTMLElement Dolla is mounted to. This will return undefined until Dolla.mount() is called.
83
82
  */
84
- getRootElement(): HTMLElement | undefined;
83
+ getRootElement(): Element | undefined;
85
84
  /**
86
85
  * Returns the top level view Dolla is rendering inside the root element. This will return undefined until Dolla.mount() is called.
87
86
  */
@@ -116,13 +115,23 @@ export declare class Dolla implements StorableContext {
116
115
  /**
117
116
  * Attaches a new store to this context.
118
117
  */
119
- attachStore(store: Store<any, any>): void;
118
+ attachStore(store: StoreFunction<{}, any>): void;
119
+ /**
120
+ * Attaches a new store to this context.
121
+ */
122
+ attachStore(store: StoreFunction<undefined, any>): void;
123
+ /**
124
+ * Attaches a new store to this context.
125
+ */
126
+ attachStore<Options>(store: StoreFunction<Options, any>, options: Options): void;
120
127
  /**
121
128
  * Gets the nearest instance of a store. Throws an error if the store isn't provided higher in the tree.
122
129
  */
123
- useStore<Value>(factory: StoreFactory<any, Value>): Value;
124
- mount(selector: string, view?: ViewFunction<any>): Promise<void>;
125
- mount(element: HTMLElement, view?: ViewFunction<any>): Promise<void>;
130
+ useStore<Value>(store: StoreFunction<any, Value>): Value;
131
+ mount(selector: string, router: Router): Promise<void>;
132
+ mount(selector: string, view: ViewFunction<any>): Promise<void>;
133
+ mount(element: Element, router: Router): Promise<void>;
134
+ mount(element: Element, view: ViewFunction<any>): Promise<void>;
126
135
  unmount(): Promise<void>;
127
136
  /**
128
137
  * Registers a `callback` to run after `Dolla.mount` is called, before the app is mounted. If `callback` returns a Promise,
@@ -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 `predicate` holds a truthy value, `thenContent` is displayed; when `predicate` holds a falsy value, `elseContent` is displayed.
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(predicate: MaybeState<any>, thenContent?: Renderable, elseContent?: Renderable): Markup;
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 WildcardListenerMap, type ElementContext, type StorableContext } from "../context.js";
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: [];
@@ -1,5 +1,5 @@
1
1
  import { Emitter } from "@manyducks.co/emitter";
2
- import { type WildcardListenerMap, type ComponentContext, type ElementContext } from "./context.js";
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 key: string;
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(key: string, fn: StoreFunction<Options, Value>, options: Options);
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 {};
@@ -4,3 +4,4 @@ export declare const IS_MARKUP: unique symbol;
4
4
  export declare const IS_MARKUP_ELEMENT: unique symbol;
5
5
  export declare const IS_STORE: unique symbol;
6
6
  export declare const IS_STORE_FACTORY: unique symbol;
7
+ export declare const IS_ROUTER: unique symbol;
package/dist/index.d.ts CHANGED
@@ -1,11 +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 { createStore, type Store, type StoreFunction, type StoreFactory } from "./core/store.js";
4
+ export { type StoreFunction, type StoreContext } from "./core/store.js";
5
+ export { createRouter, type Router, type RouterOptions } from "./modules/router.js";
5
6
  export { deepEqual, shallowEqual, strictEqual } from "./utils.js";
6
7
  export { cond, createMarkup, html, portal, repeat } from "./core/markup.js";
7
8
  export type { Markup, MarkupElement } from "./core/markup.js";
8
- export { createView } from "./core/nodes/view.js";
9
9
  import { Dolla } from "./core/dolla.js";
10
10
  declare const dolla: Dolla;
11
11
  export default dolla;