@manyducks.co/dolla 2.0.0-alpha.26 → 2.0.0-alpha.28

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.
@@ -0,0 +1,31 @@
1
+ import { Emitter } from "@manyducks.co/emitter";
2
+ import type { Dolla } from "./dolla";
3
+ interface StatsStore {
4
+ emitter: Emitter<StatsStoreEvents>;
5
+ stats: {
6
+ watcherCount: number;
7
+ viewCount: number;
8
+ };
9
+ }
10
+ type StatsStoreEvents = {
11
+ /**
12
+ * Emitted when any stats are updated in the store.
13
+ */
14
+ statsChanged: [];
15
+ _incrementWatcherCount: [amount: number];
16
+ _incrementViewCount: [amount: number];
17
+ };
18
+ /**
19
+ * Tracks runtime statistics.
20
+ */
21
+ export declare class Stats {
22
+ #private;
23
+ constructor(dolla: Dolla);
24
+ }
25
+ export declare function _createStore(): StatsStore;
26
+ export declare function _getStore(): StatsStore;
27
+ export declare function _onWatcherAdded(): void;
28
+ export declare function _onWatcherRemoved(): void;
29
+ export declare function _onViewMounted(): void;
30
+ export declare function _onViewUnmounted(): void;
31
+ export {};
@@ -0,0 +1,44 @@
1
+ import { Emitter } from "@manyducks.co/emitter";
2
+ import { type ComponentContext, type ElementContext } from "./context.js";
3
+ import type { Logger } from "./dolla.js";
4
+ export type StoreFunction<Options, Value> = (this: StoreContext, options: Options, context: StoreContext) => Value;
5
+ export type StoreFactory<Options, Value> = Options extends undefined ? () => Store<Options, Value> : (options: Options) => Store<Options, Value>;
6
+ export interface StoreContext extends Logger, ComponentContext {
7
+ /**
8
+ * Registers a callback to run just after this store is mounted.
9
+ */
10
+ onMount(callback: () => void): void;
11
+ /**
12
+ * Registers a callback to run just after this store is unmounted.
13
+ */
14
+ onUnmount(callback: () => void): void;
15
+ }
16
+ type StoreEvents = {
17
+ mounted: [];
18
+ unmounted: [];
19
+ };
20
+ export declare class Store<Options, Value> {
21
+ readonly key: string;
22
+ private _fn;
23
+ private _options;
24
+ /**
25
+ * Value is guaranteed to be set after `attach` is called.
26
+ */
27
+ value: Value;
28
+ _elementContext: ElementContext;
29
+ _emitter: Emitter<StoreEvents>;
30
+ _logger: Logger;
31
+ constructor(key: string, fn: StoreFunction<Options, Value>, options: Options);
32
+ attach(elementContext: ElementContext): void;
33
+ handleMount(): void;
34
+ handleUnmount(): void;
35
+ }
36
+ export declare function isStoreFactory<Options, Value>(value: any): value is StoreFactory<Options, Value>;
37
+ export declare function isStore<Options, Value>(value: any): value is Store<Options, Value>;
38
+ /**
39
+ * Defines a new store.
40
+ */
41
+ export declare function createStore<Options = undefined, Value = unknown>(fn: StoreFunction<Options, Value>): StoreFactory<Options, Value>;
42
+ export declare class StoreError extends Error {
43
+ }
44
+ export {};
@@ -1,5 +1,6 @@
1
- export declare const TYPE_STATE: unique symbol;
2
- export declare const TYPE_SETTABLE_STATE: unique symbol;
3
- export declare const TYPE_REF: unique symbol;
4
- export declare const TYPE_MARKUP: unique symbol;
5
- export declare const TYPE_MARKUP_ELEMENT: unique symbol;
1
+ export declare const IS_STATE: unique symbol;
2
+ export declare const IS_REF: unique symbol;
3
+ export declare const IS_MARKUP: unique symbol;
4
+ export declare const IS_MARKUP_ELEMENT: unique symbol;
5
+ export declare const IS_STORE: unique symbol;
6
+ export declare const IS_STORE_FACTORY: unique symbol;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,11 @@
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";
1
+ export { createState, derive, isState, toState, toValue } from "./core/state.js";
2
+ export type { MaybeState, Setter, State, StopFunction } from "./core/state.js";
3
+ export { createRef, isRef, type Ref } from "./core/ref.js";
4
+ export { createStore, type Store, type StoreFunction, type StoreFactory } from "./core/store.js";
3
5
  export { deepEqual, shallowEqual, strictEqual } from "./utils.js";
4
6
  export { cond, createMarkup, html, portal, repeat } from "./core/markup.js";
5
7
  export type { Markup, MarkupElement } from "./core/markup.js";
8
+ export { createView } from "./core/nodes/view.js";
6
9
  import { Dolla } from "./core/dolla.js";
7
10
  declare const dolla: Dolla;
8
11
  export default dolla;