@manyducks.co/dolla 2.0.0-alpha.34 → 2.0.0-alpha.35

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.
Files changed (45) hide show
  1. package/README.md +12 -14
  2. package/dist/core/{batch.d.ts → _batch.d.ts} +4 -0
  3. package/dist/core/context.d.ts +20 -17
  4. package/dist/core/dolla.d.ts +7 -48
  5. package/dist/core/markup.d.ts +9 -31
  6. package/dist/core/nodes/{observer.d.ts → dynamic.d.ts} +8 -10
  7. package/dist/core/nodes/html.d.ts +5 -7
  8. package/dist/core/nodes/{repeat.d.ts → list.d.ts} +12 -14
  9. package/dist/core/nodes/outlet.d.ts +4 -4
  10. package/dist/core/nodes/view.d.ts +22 -18
  11. package/dist/core/ref.d.ts +16 -0
  12. package/dist/core/signals.d.ts +128 -0
  13. package/dist/core/store.d.ts +9 -7
  14. package/dist/core/symbols.d.ts +0 -2
  15. package/dist/{views → core/views}/default-crash-view.d.ts +1 -1
  16. package/dist/{views → core/views}/passthrough.d.ts +2 -2
  17. package/dist/{modules/http.d.ts → http/index.d.ts} +1 -2
  18. package/dist/index.d.ts +8 -11
  19. package/dist/index.js +709 -846
  20. package/dist/index.js.map +1 -1
  21. package/dist/jsx-dev-runtime.d.ts +1 -1
  22. package/dist/jsx-dev-runtime.js +2 -2
  23. package/dist/jsx-dev-runtime.js.map +1 -1
  24. package/dist/jsx-runtime.d.ts +1 -1
  25. package/dist/jsx-runtime.js +2 -2
  26. package/dist/jsx-runtime.js.map +1 -1
  27. package/dist/markup-BWJWLvDF.js +1634 -0
  28. package/dist/markup-BWJWLvDF.js.map +1 -0
  29. package/dist/{modules/router.d.ts → router/index.d.ts} +5 -5
  30. package/dist/router/router.utils.test.d.ts +1 -0
  31. package/dist/{modules/i18n.d.ts → translate/index.d.ts} +20 -16
  32. package/dist/types.d.ts +9 -9
  33. package/docs/signals.md +149 -0
  34. package/docs/views.md +1 -1
  35. package/notes/atomic.md +146 -0
  36. package/package.json +11 -7
  37. package/vite.config.js +3 -0
  38. package/dist/core/state.d.ts +0 -126
  39. package/dist/core/stats.d.ts +0 -31
  40. package/dist/markup-B3FV_fq9.js +0 -1525
  41. package/dist/markup-B3FV_fq9.js.map +0 -1
  42. package/notes/viewstate.md +0 -15
  43. package/tests/state.test.js +0 -135
  44. /package/dist/{modules/router.utils.test.d.ts → core/signals.test.d.ts} +0 -0
  45. /package/dist/{modules → router}/router.utils.d.ts +0 -0
@@ -0,0 +1,128 @@
1
+ import { type Dependency, type Subscriber } from "alien-signals";
2
+ 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
+ * The current value.
18
+ */
19
+ readonly value: T;
20
+ }
21
+ export type MaybeReactive<T> = Reactive<T> | T;
22
+ export type UnsubscribeFunction = () => void;
23
+ /**
24
+ * A function to compare the current and next values. Returning `true` means the value has changed.
25
+ */
26
+ export type EqualityFunction<T> = (current: T, next: T) => boolean;
27
+ export interface ReactiveOptions<T> {
28
+ /**
29
+ * A label for debugging purposes.
30
+ */
31
+ name?: string;
32
+ /**
33
+ * A function to compare the current and next values. Returning `true` means the value has changed.
34
+ */
35
+ equals?: EqualityFunction<T>;
36
+ }
37
+ export declare class Atom<T> implements Reactive<T> {
38
+ #private;
39
+ /**
40
+ * A label for debugging purposes.
41
+ */
42
+ name?: string;
43
+ constructor(signal: Signal<T>, options?: ReactiveOptions<T>);
44
+ get value(): T;
45
+ set value(next: T);
46
+ }
47
+ /**
48
+ * Determines if a value is reactive.
49
+ */
50
+ export declare function isReactive<T>(value: any): value is Reactive<T>;
51
+ /**
52
+ * Creates a simple reactive container that stores a value.
53
+ * Atom values can be read and updated with the `value` property
54
+ *
55
+ * @example
56
+ * const count = atom(1);
57
+ * count.value++;
58
+ * count.value; // 2
59
+ */
60
+ export declare function atom<T>(): Atom<T | undefined>;
61
+ /**
62
+ * Creates a simple reactive container that stores a value.
63
+ * Atom values can be read and updated with the `value` property.
64
+ *
65
+ * @example
66
+ * const count = atom(1);
67
+ * count.value++;
68
+ * count.value; // 2
69
+ */
70
+ export declare function atom<T>(value: T, options?: ReactiveOptions<T>): Atom<T>;
71
+ /**
72
+ * Creates a simple reactive container that stores a value.
73
+ * Atom values can be read and updated with the `value` property.
74
+ *
75
+ * @example
76
+ * const count = atom(1);
77
+ * count.value++;
78
+ * count.value; // 2
79
+ */
80
+ export declare function atom<T>(value?: T, options?: ReactiveOptions<T>): Atom<T | undefined>;
81
+ type ComposeCallback<T> = (previousValue?: T) => MaybeReactive<T>;
82
+ /**
83
+ * Creates a reactive container that derives its value from other reactive values that it tracks.
84
+ *
85
+ * @example
86
+ * const count = atom(1);
87
+ * const doubled = compose(() => get(count) * 2);
88
+ */
89
+ export declare function compose<T>(fn: ComposeCallback<T>, options?: ReactiveOptions<T>): Reactive<T>;
90
+ /**
91
+ * Takes a new value to set, or a callback that receives the current value and returns a new value to set.
92
+ */
93
+ type Setter<T> = (next: T | ((current: T) => T)) => void;
94
+ export declare function set<T>(atom: Atom<T>): Setter<T>;
95
+ export declare function set<T>(atom: Atom<T>, next: T | ((current: T) => T)): void;
96
+ /**
97
+ * Returns the current value from a reactive _and track it_ if called in a `compose` or `effect` scope.
98
+ * If a non-reactive value is passed it will just be returned untracked.
99
+ *
100
+ * @example
101
+ * const count = atom(1);
102
+ * const value = get(count); // 1
103
+ *
104
+ * const value = get(5); // 5
105
+ */
106
+ export declare function get<T>(value: MaybeReactive<T>): T;
107
+ /**
108
+ * Returns the current value from a reactive (without tracking).
109
+ * If a non-reactive value is passed it will be returned.
110
+ *
111
+ * @example
112
+ * ctx.effect(() => {
113
+ * const doubled = get(count) * 2; // `count` will be tracked
114
+ *
115
+ * const doubled = peek(count) * 2; // `count` will NOT be tracked
116
+ * });
117
+ */
118
+ export declare function peek<T>(value: MaybeReactive<T>): T;
119
+ export type EffectCallback = () => void;
120
+ /**
121
+ * Creates a tracked scope that re-runs whenever the values of any tracked reactives changes.
122
+ * Reactives are tracked by accessing their `value` within the body of the function.
123
+ *
124
+ * NOTE: You must call the unsubscribe function to stop watching for changes.
125
+ * If you are using an effect inside a View or Store, use `ctx.effect` instead, which cleans up automatically when the component unmounts.
126
+ */
127
+ export declare function effect(fn: EffectCallback): UnsubscribeFunction;
128
+ export {};
@@ -1,10 +1,10 @@
1
1
  import { Emitter } from "@manyducks.co/emitter";
2
- import { type ComponentContext, type ElementContext, type WildcardListenerMap } from "./context.js";
2
+ import { GenericEvents, StoreConsumerContext, type ComponentContext, type ElementContext, type WildcardListenerMap } from "./context.js";
3
3
  import type { Logger } from "./dolla.js";
4
- import { type MaybeState, type StateValues, type StopFunction } from "./state.js";
4
+ import { EffectCallback, UnsubscribeFunction } from "./signals.js";
5
5
  export type StoreFunction<Options, Value> = (this: StoreContext, options: Options, context: StoreContext) => Value;
6
6
  export type StoreFactory<Options, Value> = Options extends undefined ? () => Store<Options, Value> : (options: Options) => Store<Options, Value>;
7
- export interface StoreContext extends Logger, ComponentContext {
7
+ export interface StoreContext<Events extends GenericEvents = GenericEvents> extends Omit<Logger, "setName">, ComponentContext<Events>, StoreConsumerContext {
8
8
  /**
9
9
  * True while this store is attached to a context that is currently mounted in the view tree.
10
10
  */
@@ -18,10 +18,10 @@ export interface StoreContext extends Logger, ComponentContext {
18
18
  */
19
19
  onUnmount(callback: () => void): void;
20
20
  /**
21
- * Watch a set of states. The callback is called when any of the states receive a new value.
22
- * Watchers will be automatically stopped when this store is unmounted.
21
+ * Passes a getter function to `callback` that will track reactive states and return their current values.
22
+ * Callback will be run each time a tracked state gets a new value.
23
23
  */
24
- watch<T extends MaybeState<any>[]>(states: [...T], callback: (...values: StateValues<T>) => void): StopFunction;
24
+ effect(callback: EffectCallback): UnsubscribeFunction;
25
25
  }
26
26
  type StoreEvents = {
27
27
  mounted: [];
@@ -39,7 +39,9 @@ export declare class Store<Options, Value> {
39
39
  _emitter: Emitter<StoreEvents>;
40
40
  _wildcardListeners: WildcardListenerMap;
41
41
  _logger: Logger;
42
- _watcher: import("./state.js").StateWatcher;
42
+ _unsubscribes: UnsubscribeFunction[];
43
+ _name: string;
44
+ _id: string;
43
45
  get name(): string;
44
46
  constructor(fn: StoreFunction<Options, Value>, options: Options);
45
47
  /**
@@ -1,7 +1,5 @@
1
- export declare const IS_STATE: unique symbol;
2
1
  export declare const IS_REF: unique symbol;
3
2
  export declare const IS_MARKUP: unique symbol;
4
3
  export declare const IS_MARKUP_ELEMENT: unique symbol;
5
4
  export declare const IS_STORE: unique symbol;
6
- export declare const IS_STORE_FACTORY: unique symbol;
7
5
  export declare const IS_ROUTER: unique symbol;
@@ -15,4 +15,4 @@ export type CrashViewProps = {
15
15
  */
16
16
  uid?: string;
17
17
  };
18
- export declare function DefaultCrashView(props: CrashViewProps): import("../core/markup.js").Markup | import("../core/markup.js").Markup[];
18
+ export declare function DefaultCrashView(props: CrashViewProps): import("../markup.js").Markup | import("../markup.js").Markup[];
@@ -1,5 +1,5 @@
1
- import { type ViewContext } from "../core/nodes/view.js";
1
+ import { type ViewContext } from "../nodes/view.js";
2
2
  /**
3
3
  * A utility view that simply displays its children.
4
4
  */
5
- export declare function Passthrough(_: {}, ctx: ViewContext): import("../index.js").Markup;
5
+ export declare function Passthrough(_: {}, ctx: ViewContext): import("../markup.js").Markup;
@@ -1,11 +1,10 @@
1
- import type { Dolla } from "../core/dolla.js";
2
1
  /**
3
2
  * A simple HTTP client with middleware support. Middleware applies to all requests made through this store,
4
3
  * so it's the perfect way to handle things like auth headers and permission checks for API calls.
5
4
  */
6
5
  export declare class HTTP {
7
6
  #private;
8
- constructor(dolla: Dolla);
7
+ constructor();
9
8
  /**
10
9
  * Adds a new middleware that will apply to subsequent requests.
11
10
  * Returns a function to remove this middleware.
package/dist/index.d.ts CHANGED
@@ -1,22 +1,19 @@
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 { type StoreFunction, type StoreContext } from "./core/store.js";
5
- export { createRouter, type Router, type RouterOptions } from "./modules/router.js";
1
+ export { atom, compose, effect, get, set, peek } from "./core/signals.js";
2
+ export type { Reactive, MaybeReactive, Atom } from "./core/signals.js";
6
3
  export { deepEqual, shallowEqual, strictEqual } from "./utils.js";
7
- export { cond, createMarkup, html, portal, repeat } from "./core/markup.js";
4
+ export { ref, type Ref } from "./core/ref.js";
5
+ export { type StoreFunction, type StoreContext } from "./core/store.js";
6
+ export { createRouter, type Router, type RouterOptions } from "./router/index.js";
7
+ export { cond, createMarkup, html, portal, list } from "./core/markup.js";
8
8
  export type { Markup, MarkupElement } from "./core/markup.js";
9
9
  import { Dolla } from "./core/dolla.js";
10
10
  declare const dolla: Dolla;
11
11
  export default dolla;
12
- export declare const t: (selector: string, options?: import("./modules/i18n.js").TOptions) => import("./core/state.js").State<string>;
13
- export declare function setDevDebug(value: boolean): void;
14
- export declare function getDevDebug(): boolean;
12
+ export declare const t: (selector: string, options?: import("./translate/index.js").TOptions) => import("./core/signals.js").Reactive<string>;
15
13
  export type { Dolla, Environment, Logger, LoggerErrorContext, LoggerOptions, Loggles } from "./core/dolla.js";
16
14
  export type { ViewContext, ViewElement, ViewFunction } from "./core/nodes/view.js";
17
- export type { HTTPRequest, HTTPResponse } from "./modules/http.js";
18
15
  export type { InputType, Renderable } from "./types.js";
19
- export type { CrashViewProps } from "./views/default-crash-view.js";
16
+ export type { CrashViewProps } from "./core/views/default-crash-view.js";
20
17
  import type { IntrinsicElements as Elements } from "./types";
21
18
  declare global {
22
19
  namespace JSX {