@manyducks.co/dolla 3.0.0 → 3.2.0

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.
@@ -1,4 +1,5 @@
1
1
  import type { Store } from "../types.js";
2
+ import { ViewNode } from "./markup/nodes/view.js";
2
3
  export type LifecycleListener = () => any;
3
4
  type ContextState = {
4
5
  isMounted: boolean;
@@ -13,6 +14,14 @@ export declare function unmountContext(context: Context): void;
13
14
  export declare function onMount(context: Context, fn: LifecycleListener): void;
14
15
  export declare function onCleanup(context: Context, fn: LifecycleListener): void;
15
16
  export declare function onEffect(context: Context, fn: () => void): void;
17
+ /**
18
+ * Returns the parent element of the root we're mounted in.
19
+ */
20
+ export declare function getRootElement(context: Context): Element;
21
+ /**
22
+ * Returns the ViewNode of the nearest view up the context chain.
23
+ */
24
+ export declare function getNearestViewNode<Props = unknown>(context: Context): ViewNode<Props> | undefined;
16
25
  export declare const STORE_ID: unique symbol;
17
26
  export declare function addStore<Props, Returns>(context: Context, store: Store<Props, Returns> & {
18
27
  [STORE_ID]?: symbol;
@@ -1,11 +1,11 @@
1
1
  export { createRoot } from "./root.js";
2
2
  export type { DollaPlugin } from "./root.js";
3
- export { batch, compose, createAtom, createEffect, peek, subscribe, unwrap } from "./signals.js";
3
+ export { batch, compose, createAtom, createEffect, createStream, peek, subscribe, unwrap } from "./signals.js";
4
4
  export type { Getter, Setter } from "./signals.js";
5
- export { addStore, getStore, onCleanup, onEffect, onMount } from "./context.js";
5
+ export { addStore, getNearestViewNode, getRootElement, getStore, onCleanup, onEffect, onMount } from "./context.js";
6
6
  export type { Context } from "./context.js";
7
7
  export { createDebug, getDebug, setLogFilter, setLogLevel } from "./debug.js";
8
- export { forEach, showIf, hideIf, createPortal } from "./markup/helpers.js";
8
+ export { createPortal, forEach, hideIf, showIf } from "./markup/helpers.js";
9
9
  export { html } from "./markup/html.js";
10
10
  export { ViewNode } from "./markup/nodes/view.js";
11
11
  export type { Markup, MarkupNode } from "./markup/types.js";
@@ -1,3 +1,4 @@
1
+ import { Context } from "./index.js";
1
2
  /**
2
3
  * Returns the currently held value. Registers the state as a dependency when called within a tracking context.
3
4
  */
@@ -50,7 +51,7 @@ export declare function createAtom<T>(compute: Getter<T>): AtomAccessors<T>;
50
51
  * const [getCount, setCount] = createAtom(5);
51
52
  */
52
53
  export declare function createAtom<T>(initialValue: T): AtomAccessors<T>;
53
- export declare function compose<T>(getter: (previousValue?: T) => Getter<T> | T): Getter<T>;
54
+ export declare function compose<T>(getter: T | ((previousValue?: T) => Getter<T> | T)): Getter<T>;
54
55
  export declare function createEffect(fn: () => void): () => void;
55
56
  /**
56
57
  * Unwraps a `MaybeGetter<T>` into a plain `T`.
@@ -68,3 +69,34 @@ export declare function peek<T>(value: T | Getter<T>): T;
68
69
  */
69
70
  export declare function batch(callback: () => void): void;
70
71
  export declare function subscribe<T>(target: Getter<T>, fn: (value: T) => any): () => void;
72
+ export interface StreamOptions<T> {
73
+ /**
74
+ * An initial value for non-nullable streams.
75
+ */
76
+ initialValue?: T;
77
+ /**
78
+ * Cancel pending `next` listeners when this context is unmounted.
79
+ */
80
+ context?: Context;
81
+ /**
82
+ * Number of emitted values to keep. Defaults to 0 (latest value only).
83
+ */
84
+ history?: number;
85
+ }
86
+ export interface StreamOptionsWithValue<T> extends StreamOptions<T> {
87
+ initialValue: T;
88
+ }
89
+ export interface Stream<T> {
90
+ readonly latest: T;
91
+ current: Getter<T>;
92
+ next(): Promise<T>;
93
+ map<O>(callback: (value: T, previous?: O) => O): Stream<O>;
94
+ reduce<O>(callback: (reduced: O, value: T) => O, initialValue: O): Stream<O>;
95
+ filter(callback: (value: T, previous?: T) => boolean, defaultValue: T): Stream<T>;
96
+ filter(callback: (value: T, previous?: T) => boolean, defaultValue?: T): Stream<T | undefined>;
97
+ throttle(milliseconds: number): Stream<T>;
98
+ debounce(milliseconds: number): Stream<T>;
99
+ delay(milliseconds: number, initialValue?: T): Stream<T>;
100
+ }
101
+ export declare function createStream<T>(options: StreamOptionsWithValue<T>): [Stream<T>, Setter<T>];
102
+ export declare function createStream<T>(options: StreamOptions<T>): [Stream<T | undefined>, Setter<T | undefined>];