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

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 (70) hide show
  1. package/README.md +31 -951
  2. package/dist/core/batch.d.ts +17 -0
  3. package/dist/core/context.d.ts +94 -0
  4. package/dist/{modules → core}/dolla.d.ts +68 -19
  5. package/dist/core/markup.d.ts +91 -0
  6. package/dist/core/nodes/dom.d.ts +13 -0
  7. package/dist/core/nodes/html.d.ts +39 -0
  8. package/dist/core/nodes/observer.d.ts +30 -0
  9. package/dist/core/nodes/outlet.d.ts +19 -0
  10. package/dist/core/nodes/portal.d.ts +22 -0
  11. package/dist/core/nodes/repeat.d.ts +36 -0
  12. package/dist/core/nodes/view.d.ts +92 -0
  13. package/dist/core/ref.d.ts +29 -0
  14. package/dist/core/state.d.ts +126 -0
  15. package/dist/core/stats.d.ts +31 -0
  16. package/dist/core/store.d.ts +62 -0
  17. package/dist/core/symbols.d.ts +6 -0
  18. package/dist/index.d.ts +17 -11
  19. package/dist/index.js +991 -1010
  20. package/dist/index.js.map +1 -1
  21. package/dist/jsx-dev-runtime.d.ts +2 -2
  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 +3 -3
  25. package/dist/jsx-runtime.js +2 -2
  26. package/dist/jsx-runtime.js.map +1 -1
  27. package/dist/modules/http.d.ts +5 -5
  28. package/dist/modules/i18n.d.ts +129 -0
  29. package/dist/modules/router.d.ts +27 -48
  30. package/dist/passthrough-d2lcM0cd.js +1563 -0
  31. package/dist/passthrough-d2lcM0cd.js.map +1 -0
  32. package/dist/typeChecking.d.ts +2 -2
  33. package/dist/types.d.ts +12 -13
  34. package/dist/utils.d.ts +14 -2
  35. package/dist/views/default-crash-view.d.ts +1 -1
  36. package/dist/views/passthrough.d.ts +2 -2
  37. package/docs/http.md +29 -0
  38. package/docs/i18n.md +38 -0
  39. package/docs/index.md +10 -0
  40. package/docs/router.md +77 -0
  41. package/docs/setup.md +31 -0
  42. package/docs/state.md +141 -0
  43. package/docs/stores.md +62 -0
  44. package/docs/views.md +308 -0
  45. package/index.d.ts +2 -2
  46. package/notes/TODO.md +6 -0
  47. package/notes/context-vars.md +21 -0
  48. package/notes/readme-scratch.md +222 -0
  49. package/notes/route-middleware.md +42 -0
  50. package/notes/scratch.md +195 -7
  51. package/notes/stores.md +73 -0
  52. package/package.json +12 -14
  53. package/tests/{signals.test.js → state.test.js} +6 -6
  54. package/vite.config.js +0 -10
  55. package/dist/markup.d.ts +0 -100
  56. package/dist/modules/language.d.ts +0 -41
  57. package/dist/modules/render.d.ts +0 -17
  58. package/dist/nodes/cond.d.ts +0 -26
  59. package/dist/nodes/html.d.ts +0 -26
  60. package/dist/nodes/observer.d.ts +0 -29
  61. package/dist/nodes/outlet.d.ts +0 -22
  62. package/dist/nodes/portal.d.ts +0 -19
  63. package/dist/nodes/repeat.d.ts +0 -34
  64. package/dist/nodes/text.d.ts +0 -19
  65. package/dist/passthrough-DrtCifRF.js +0 -1228
  66. package/dist/passthrough-DrtCifRF.js.map +0 -1
  67. package/dist/signals.d.ts +0 -101
  68. package/dist/view.d.ts +0 -50
  69. /package/dist/{routing.d.ts → modules/router.utils.d.ts} +0 -0
  70. /package/dist/{routing.test.d.ts → modules/router.utils.test.d.ts} +0 -0
@@ -0,0 +1,222 @@
1
+ # README
2
+
3
+ > This note will eventually become the new README. Here I'm laying out my ideal framework API.
4
+
5
+ A basic component.
6
+
7
+ ```jsx
8
+ import Dolla, { createState, derive } from "@manyducks.co/dolla";
9
+
10
+ function ExampleView(props, ctx) {
11
+ const [$count, setCount] = createState(5);
12
+ const $doubled = derive([$count], (n) => n * 2);
13
+
14
+ ctx.watch([$count], (count) => {
15
+ ctx.log("value of count is now %n", count);
16
+ });
17
+
18
+ return <p>{$count}</p>;
19
+ }
20
+
21
+ Dolla.mount(document.body, ExampleView);
22
+ ```
23
+
24
+ <details open>
25
+ <summary>
26
+ <h2>Signals API</h2>
27
+ </summary>
28
+
29
+ The signals API. Dolla's signals use explicit tracking, meaning any function where signal values are tracked take an array of the signals you want to track. This way you know exactly what depends on what at a glance without any kind of hidden tracking logic behind the scenes. You are free to `.get()` the value of a signal without worrying about untracking it first.
30
+
31
+ ```jsx
32
+ import { createState } from "@manyducks.co/dolla";
33
+
34
+ const [$count, setCount] = createState(256);
35
+
36
+ $count.get(); // 256; returns the current value
37
+
38
+ const stop = $count.watch((value) => {
39
+ // Runs once immediately, then again whenever the value changes.
40
+ });
41
+
42
+ setCount(512); // Update the value of $count. The new value is set and all watchers run synchronously.
43
+
44
+ stop(); // Stop watching for changes.
45
+ ```
46
+
47
+ That is the basic signal API. Signals are all about composability. Here are some more advanced ways of working with them:
48
+
49
+ ```jsx
50
+ import { createState, toState, valueOf, derive } from "@manyducks.co/dolla";
51
+
52
+ const [$count, setCount] = createState(72);
53
+
54
+ // Returns the value of the signal passed in. If the value is not a signal it is returned as is.
55
+ const count = valueOf($count);
56
+ const bool = valueOf(true);
57
+
58
+ // Creates a signal containing the value passed in. If the value is already a signal it is returned as is.
59
+ const $bool = toState(true);
60
+ const $anotherCount = toState($count);
61
+
62
+ // Derive a new signal from the value of another. Whenever $count changes, $doubled will follow.
63
+ const $doubled = derive([$count], (count) => count * 2);
64
+
65
+ // Derive a new signal from the values of several others. When any value in the list changes, $sum will be recomputed.
66
+ const $sum = derive([$count, $doubled], (count, doubled) => count + doubled);
67
+ ```
68
+
69
+ The API if we call it State instead of Signal to distance from the Signal object in standardization process.
70
+
71
+ ```jsx
72
+ import { createState, toState, valueOf, derive } from "@manyducks.co/dolla";
73
+
74
+ const [$count, setCount] = createState(72);
75
+
76
+ // Returns the value of the signal passed in. If the value is not a signal it is returned as is.
77
+ const count = valueOf($count);
78
+ const bool = valueOf(true);
79
+
80
+ // Creates a signal containing the value passed in. If the value is already a signal it is returned as is.
81
+ const $bool = toState(true);
82
+ const $anotherCount = toState($count);
83
+
84
+ // Derive a new signal from the value of another. Whenever $count changes, $doubled will follow.
85
+ const $doubled = derive([$count], (count) => count * 2);
86
+
87
+ // Derive a new signal from the values of several others. When any value in the list changes, $sum will be recomputed.
88
+ const $sum = derive([$count, $doubled], (count, doubled) => count + doubled);
89
+ ```
90
+
91
+ States also come in a settable variety, with the setter included on the same object. Sometimes you want to pass around a two-way binding and this is what SettableState is for.
92
+
93
+ ```jsx
94
+ import { createSettableState, fromSettable, toSettable } from "@manyducks.co/dolla";
95
+
96
+ // Settable states have their setter included.
97
+ const $$value = createSettableState("Test");
98
+ $$value.set("New Value");
99
+
100
+ // They can also be split into a State and Setter
101
+ const [$value, setValue] = fromSettableState($$value);
102
+
103
+ // And a State and Setter can be combined into a SettableState.
104
+ const $$otherValue = toSettableState($value, setValue);
105
+
106
+ // Or discard the setter and make it read-only using the good old toState function:
107
+ const $value = toState($$value);
108
+ ```
109
+
110
+ Alternative API
111
+
112
+ ```jsx
113
+ import { State } from "@manyducks.co/dolla";
114
+
115
+ const [$count, setCount] = State(72);
116
+
117
+ const count = State.unwrap($count);
118
+ const bool = State.unwrap(true);
119
+
120
+ const $bool = State.wrap(true);
121
+ const $sameCount = State.wrap($count);
122
+
123
+ const $doubled = State.from([$count], (count) => count * 2);
124
+
125
+ const $sum = State.from([$count, $doubled], (count, doubled) => count + doubled);
126
+ ```
127
+
128
+ Yet another
129
+
130
+ ```jsx
131
+ import Dolla from "@manyducks.co/dolla";
132
+
133
+ const [$count, setCount] = Dolla.state(72);
134
+
135
+ const count = Dolla.get($count);
136
+ const bool = Dolla.get(true);
137
+
138
+ const $bool = Dolla.toState(true);
139
+ const $sameCount = Dolla.toState($count);
140
+
141
+ const $doubled = Dolla.computed([$count], (count) => count * 2);
142
+ const $sum = Dolla.computed([$count, $doubled], (count, doubled) => count + doubled);
143
+
144
+ // or
145
+
146
+ import { state, computed, get, toState } from "@manyducks.co/dolla";
147
+
148
+ const [$count, setCount] = state(72);
149
+
150
+ const count = get($count);
151
+ const bool = get(true);
152
+
153
+ const $bool = toState(true);
154
+ const $sameCount = toState($count);
155
+
156
+ const $doubled = computed([$count], (count) => count * 2);
157
+ const $sum = computed([$count, $doubled], (count, doubled) => count + doubled);
158
+ ```
159
+
160
+ Settable signals:
161
+
162
+ ```jsx
163
+ import { createSettableState, createSetter, toSettableSignal, fromSettableSignal } from "@manyducks.co/dolla";
164
+
165
+ // Create a SettableSignal, which is basically a signal and its setter combined into a single object.
166
+ const $$settable = createSettableState("Example");
167
+
168
+ // The basic API is identical...
169
+ $$settable.get();
170
+ const stop = $$settable.watch((value) => {
171
+ // ...
172
+ });
173
+ stop();
174
+
175
+ // ... except for the addition of a setter.
176
+ $$settable.set("Set me directly");
177
+
178
+ // When you already have a signal and a setter, they can be combined into one.
179
+ const $$count = toSettableSignal($count, setCount);
180
+
181
+ // This updates the original $signal value.
182
+ $$count.set(386);
183
+
184
+ // TODO: You can also split a SettableSignal into a signal and its setter.
185
+ const [$readable, setReadable] = fromSettableSignal($$settable);
186
+
187
+ // Create a custom setter. Calling this will cap the value to 100.
188
+ const setCountBounded = createSetter($count, (next, current) => {
189
+ return Math.min(100, next);
190
+ });
191
+
192
+ setCountBounded((current) => {
193
+ return current + 1;
194
+ });
195
+
196
+ // Or make a proxy $$doubled -- but would you actually want to proxy things like this?
197
+ const [$count, setCount] = createState(5);
198
+ const $doubled = derive([$count], (count) => count * 2);
199
+ const $$doubled = toSettableSignal(
200
+ $doubled,
201
+ createSetter($doubled, (next, current) => {
202
+ setCount(next * 2);
203
+ }),
204
+ );
205
+ ```
206
+
207
+ I'm not really sure we need all of this. On the chopping block:
208
+
209
+ - The entire concept of settable signals
210
+ - `createSettableState`
211
+ - `toSettableSignal`
212
+ - `fromSettableSignal`
213
+ - `createSetter`
214
+
215
+ This makes the entire API just four functions:
216
+
217
+ - `createState`
218
+ - `derive`
219
+ - `toState`
220
+ - `valueOf`
221
+
222
+ </details>
@@ -0,0 +1,42 @@
1
+ # Router Middleware
2
+
3
+ Allow handling route guards, preloading, etc with per-route middleware. When a route is matched, all middleware from higher layers are run again.
4
+
5
+ ```js
6
+ Dolla.router.setup({
7
+ middleware: [/* does it make sense to have global middleware? */]
8
+ routes: [
9
+ { path: "/login", middleware: [auth] },
10
+ { path: "/", middleware: [auth], routes: [{ path: "/example", view: ExampleView }] }
11
+ ]
12
+ });
13
+
14
+ async function auth(ctx) {
15
+ // This check can be implemented however it needs to be for the app.
16
+ const authed = await isAuthorized();
17
+
18
+ if (ctx.path === "/login") {
19
+ if (authed) {
20
+ ctx.redirect("/");
21
+ }
22
+ } else {
23
+ if (!authed) {
24
+ ctx.redirect("/login");
25
+ }
26
+ }
27
+ // If no redirect has happened and nothing has been returned then we're clear to proceed.
28
+ }
29
+
30
+ // A middleware can also return Markup to stay on the URL but show something different.
31
+ async function randomVisitor(ctx) {
32
+ if (Math.random() > 0.99) {
33
+ return <LuckyVisitorView />
34
+ }
35
+ }
36
+
37
+ // Or preload async data and set a context variable before navigating.
38
+ async function preload(ctx) {
39
+ const data = await fetchData();
40
+ ctx.set("data", data);
41
+ }
42
+ ```
package/notes/scratch.md CHANGED
@@ -1,5 +1,193 @@
1
1
  # Scratch Note
2
2
 
3
+ ---
4
+
5
+ Bring the $ back and the name full circle.
6
+
7
+ ```js
8
+ import { $, $$ } from "@manyducks.co/dolla";
9
+
10
+ // Shorthand dolla sign
11
+
12
+ // An initial value (with optional options object) creates a state.
13
+ const [$count, setCount] = $(0);
14
+ // = createState(0)
15
+
16
+ // An array and a function derives a state.
17
+ const $doubled = $.map([$count], (count) => count * 2);
18
+ // = derive([$count], (count) => count * 2);
19
+
20
+ // A state returns the same state.
21
+ const $sameCount = $.from($count);
22
+ const $wrapped = $.from({ message: "This is a state with no setter." });
23
+ // = toState($count)
24
+
25
+ // Get value from a state. Values that are not states are returned directly.
26
+ const count = $.get($count);
27
+ ```
28
+
29
+ What about other operators like RxJS?
30
+
31
+ ```js
32
+ // These would be functionally equivalent.
33
+ const $doubled = $count.pipe($.map((count) => count * 2));
34
+ const $doubled = $.map([$count], (count) => count * 2);
35
+
36
+ // Chainable. Get doubled value, but only update if it's between 10 and 100.
37
+ const $boundedDouble = $count.pipe(
38
+ // Transforms the value
39
+ $.map((count) => count * 2),
40
+
41
+ // Receives the value when it changes without affecting the output.
42
+ // Only receives values while this state is actively being watched.
43
+ $.tap((count) => console.log(`doubled value is ${count}`))
44
+
45
+ // Value only changes if it's within the range.
46
+ $.filter((count) => count >= 10 && count <= 100),
47
+ );
48
+
49
+ // Could have a top level pipe operator
50
+ const $boundedDouble = $.pipe(
51
+ [$count],
52
+ $.map((count) => count * 2),
53
+ $.tap((count) => console.log(`doubled value is ${count}`))
54
+ $.filter((count) => count >= 10 && count <= 100),
55
+ );
56
+
57
+ // Could also be chainable
58
+ const $boundedDouble = $count
59
+ .map((count) => count * 2)
60
+ .tap((count) => console.log(`doubled value is ${count}`))
61
+ .filter((count) => count >= 10 && count <= 100);
62
+
63
+ // I kind of like this more than the current derive. It's cleaner.
64
+ $count.map(c => c * 2);
65
+ $count.merge([$other], (c, o) => c * o);
66
+
67
+ // Another way to merge multiple.
68
+ $.merge([$count, $other], (c, o) => c * o);
69
+
70
+ // What if you want to add something in the middle?
71
+
72
+ const $example = $count
73
+ .map((count) => count * 2)
74
+ .tap((count) => console.log(`doubled value is ${count}`))
75
+ .merge([$other1, $other2], (count, other1, other2) => /* ... */)
76
+ .filter((value) => value >= 10 && value <= 100);
77
+
78
+ // Is this a good pattern?
79
+ $count
80
+ .merge([$other], (count, other) => count * other)
81
+ .merge([$another], (merged, another) => merged * another);
82
+ // I think it gets a little weird to follow.
83
+
84
+ // equivalent to
85
+ derive(
86
+ [
87
+ derive([$count, $other], (count, other) => count * other),
88
+ $another
89
+ ],
90
+ (merged, another) => merged * another)
91
+ // Is this a pattern? Yeah, I guess I do that. Just never in line like that.
92
+
93
+ // Do we want to handle errors?
94
+ // I feel like errors usually happen in watchers though.
95
+ $boundedDouble.watch((value) => {
96
+ // Received a value.
97
+ }, (error) => {
98
+ // Something threw an error.
99
+ });
100
+ // Or like this.
101
+ $boundedDouble.watch({
102
+ change: (value) => {
103
+ // Received a value.
104
+ // This code is most likely to throw an error.
105
+ // Should errors here be passed to the error callback?
106
+ // What is the point if you can just try/catch?
107
+
108
+ // Although if you don't then Dolla could use this to catch
109
+ // and trace errors better than it does now.
110
+ },
111
+ error: (error) => {
112
+ // Something threw an error.
113
+ }
114
+ });
115
+
116
+ // Filter derives a new state where the value only updates if the function returns truthy.
117
+ const $evens = $count.pipe($.filter((count) => count % 1 === 0));
118
+ // This is equivalent to
119
+ const $events = $.map([$count], (count) => count, { equals: (a, b) => a % 1 === 0 });
120
+
121
+ function filter(...args) {
122
+ if (isArray(args[0]) && isFunction(args[1])) {
123
+ // Standalone signature. Returns a new derived state.
124
+ } else if (args.length === 1 && isFunction(args[1])) {
125
+ // Curried signature. Returns a function that takes an array of states
126
+ // and returns one with args[1] as the equality check.
127
+ }
128
+ }
129
+ ```
130
+
131
+ And you can write your own operators that implement these two signatures.
132
+
133
+ ```js
134
+ // Here's one I might want to include.
135
+ // Use this to prevent ever getting a null value.
136
+ compare((next, previous) => next ?? previous ?? "default");
137
+
138
+ function compare(...args) {}
139
+ ```
140
+
141
+ ---
142
+
143
+ I've been looking into other libraries that don't make you track your dependencies specifically. I think this is weird and unhinged to be honest. Calling functions with side effects that magically re-run things when the value changes is a truly weird and unexpected lifecycle. At least if you're explicitly tracking dependencies you know exactly what depends on what at a glance. Getting the computer to figure it out for you doesn't seem smart.
144
+
145
+ ```js
146
+ import { $ } from "@manyducks.co/dolla";
147
+
148
+ const [count, setCount] = $(0);
149
+
150
+ const doubled = $.computed(() => count() * 2);
151
+
152
+ $.effect(() => {
153
+ console.log(doubled());
154
+ });
155
+
156
+ $.batch(() => {
157
+ // Set multiple things but defer updates to after this function returns.
158
+ });
159
+
160
+ // Helpers on $; can plug into template as is.
161
+ $.if(
162
+ $.computed(() => count() > 5),
163
+ <span>Greater than 5!</span>,
164
+ <span>Not greater than 5...</span>,
165
+ );
166
+
167
+ const switched = $.switch(count, [[1, "one"], [2, "two"], [3, "three"]], "more...");
168
+
169
+ $.repeat()
170
+
171
+ // TODO: How feasible is this?
172
+ <Repeat each={}>
173
+ {(item, index) => {
174
+
175
+ }}
176
+ </Repeat>
177
+
178
+ <Show when={condition}>
179
+ Condition is true.
180
+ </Show>
181
+
182
+ // Get
183
+ count();
184
+
185
+ // Set
186
+ count(52);
187
+ ```
188
+
189
+ ---
190
+
3
191
  What if Dolla was just a global object that you don't instantiate. I have never personally run into a use case for having more than one app on a page at once. In all my projects, the page and the app are synonymous.
4
192
 
5
193
  Doing this would make it possible to access things inside the Dolla app from _outside_ code such as Quill blots. Effectively all code that has access to your Dolla import is _inside_ the app.
@@ -11,8 +199,8 @@ Doing this would make it possible to access things inside the Dolla app from _ou
11
199
  import Dolla from "@manyducks.co/dolla";
12
200
 
13
201
  // Languages: add translation, set language and get localized string as a signal
14
- Dolla.language.setup({
15
- initialLanguage: Dolla.language.detect({ fallback: "ja" }), // Detect user's language and fall back to passed value
202
+ Dolla.i18n.setup({
203
+ initialLanguage: Dolla.i18n.detect({ fallback: "ja" }), // Detect user's language and fall back to passed value
16
204
  languages: [
17
205
  { name: "ja", path: "/static/locales/ja.json" },
18
206
  {
@@ -26,8 +214,8 @@ Dolla.language.setup({
26
214
  ]
27
215
  });
28
216
 
29
- Dolla.language.$current
30
- Dolla.language.t$()
217
+ Dolla.i18n.$locale
218
+ Dolla.i18n.t$()
31
219
 
32
220
  // A single setup call to keep things contained (must happen before mount)
33
221
  Dolla.router.setup({
@@ -75,10 +263,10 @@ debug.log("HELLO");
75
263
  debug.warn("THIS IS A SCOPED LOGGER");
76
264
 
77
265
  // Efficiently and safely read and mutate the DOM using Dolla's render batching
78
- Dolla.render.read(() => {
266
+ Dolla.batch.read(() => {
79
267
  // Reference DOM nodes
80
268
  });
81
- Dolla.render.update(() => {
269
+ Dolla.batch.write(() => {
82
270
  // Mutate the DOM as part of Dolla's next batch
83
271
  }, "some-key");
84
272
 
@@ -93,7 +281,7 @@ function SomeView (props: SomeViewProps, ctx: Dolla.ViewContext) {
93
281
  const debug = Dolla.createLogger("SomeView");
94
282
 
95
283
  // returns a signal and a setter function
96
- const [$someValue, setSomeValue] = Dolla.createSignal(4);
284
+ const [$someValue, setSomeValue] = Dolla.createState(4);
97
285
 
98
286
  // Router is now a part of the Dolla object
99
287
  Dolla.router.$path;
@@ -0,0 +1,73 @@
1
+ # Stores
2
+
3
+ Ideas for updating the API.
4
+
5
+ ```js
6
+ import { createStore, attachStore, useStore, createView } from "@manyducks.co/dolla";
7
+
8
+ const Counter = createStore(function (initialCount: number) {
9
+ const [$value, setValue] = createState(initialCount);
10
+
11
+ this.on("counter:increment", (e) => {
12
+ e.stopPropagation(); // Stop this event from bubbling up to counters at higher levels (if any).
13
+ setValue((current) => current + 1);
14
+ });
15
+
16
+ this.on("counter:decrement", (e) => {
17
+ e.stopPropagation();
18
+ setValue((current) => current - 1);
19
+ });
20
+
21
+ // Events can be emitted from this context in a store.
22
+ this.emit("otherEvent");
23
+
24
+ this.onMount(() => {
25
+ // Setup
26
+ // This is called based on the context the store is attached to.
27
+ // If Dolla, it's called when the app is mounted. If ViewContext, it's called when the view is mounted.
28
+ });
29
+ this.onUnmount(() => {
30
+ // Cleanup
31
+ });
32
+
33
+ // Context variables will be accessible on the same context (e.g. the view this is attached to and below)
34
+ this.get("context variable");
35
+ this.set("context variable", "context variable value");
36
+
37
+ // Stores don't have to return anything, but if they do it becomes accessible by using `useStore(ctx, Store)`.
38
+ return $value;
39
+ });
40
+
41
+ // Attach it to the app.
42
+ Dolla.attachStore(Counter(0));
43
+
44
+ const ExampleView = createView(function () {
45
+ // useStore lets you access the return value
46
+ // but the events will still be received and handled regardless
47
+ const $count = this.useStore(Counter);
48
+
49
+ // Convenience helper to attach and use in one step?
50
+ const $count = this.attachAndUseStore(Counter(0));
51
+
52
+ return html`
53
+ <button onclick=${() => this.emit("counter:decrement")}>-1</button>
54
+ <span>${$count}</span>
55
+ <button onclick=${() => this.emit("counter:increment")}>+1</button>
56
+ `;
57
+ });
58
+
59
+ // ViewContext is also still passed as a second argument if you'd rather use arrow functions to define views.
60
+ const ExampleView = createView((props, self) => {
61
+ // useStore lets you access the return value
62
+ // but the events will still be received and handled regardless
63
+ const $count = self.useStore(Counter);
64
+
65
+ return html`
66
+ <button onclick=${() => self.emit("counter:decrement")}>-1</button>
67
+ <span>${$count}</span>
68
+ <button onclick=${() => self.emit("counter:increment")}>+1</button>
69
+ `;
70
+ });
71
+ ```
72
+
73
+ This means `createStore` returns a function that is called to create a Store instance. The instance is
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@manyducks.co/dolla",
3
- "version": "2.0.0-alpha.3",
3
+ "version": "2.0.0-alpha.30",
4
4
  "description": "Front-end components, routing and state management.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "type": "module",
8
8
  "sideEffects": false,
9
- "repository": "https://github.com/manyducksco/dolla",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/manyducksco/dolla.git"
12
+ },
10
13
  "scripts": {
11
14
  "test": "npm run build && node --test",
12
15
  "build:esbuild": "tsc && node build.js",
@@ -36,20 +39,15 @@
36
39
  "types": "./jsx-dev-runtime.d.ts"
37
40
  }
38
41
  },
39
- "dependencies": {
40
- "fetch-ponyfill": "^7.1.0",
41
- "history": "^5.3.0",
42
- "nanoid": "^5.0.4",
43
- "simple-color-hash": "^1.0.2",
44
- "vite": "^6.0.7"
45
- },
46
42
  "devDependencies": {
47
- "@types/node": "^18.17.6",
43
+ "@manyducks.co/emitter": "^1.1.2",
44
+ "@types/node": "^22.12.0",
48
45
  "csstype": "^3.1.3",
49
- "esbuild": "^0.24.2",
46
+ "fast-deep-equal": "^3.1.3",
50
47
  "htm": "^3.1.1",
51
- "prettier": "^3.2.4",
52
- "typescript": "^5.3.3",
53
- "zod": "^3.22.4"
48
+ "prettier": "^3.4.2",
49
+ "simple-color-hash": "^1.0.2",
50
+ "typescript": "^5.7.3",
51
+ "vite": "^6.0.11"
54
52
  }
55
53
  }
@@ -1,10 +1,10 @@
1
1
  import test from "node:test";
2
2
  import assert from "node:assert";
3
3
 
4
- import { signal, derive } from "../lib/index.js";
4
+ import { createState, derive } from "../dist/index.js";
5
5
 
6
6
  test("signal", (t) => {
7
- const [$count, setCount] = signal(5);
7
+ const [$count, setCount] = createState(5);
8
8
 
9
9
  const defaultWatcher = t.mock.fn();
10
10
  const stopDefault = $count.watch(defaultWatcher);
@@ -42,8 +42,8 @@ test("signal", (t) => {
42
42
  });
43
43
 
44
44
  test("derive", (t) => {
45
- const [$one, setOne] = signal(5);
46
- const [$two, setTwo] = signal(20);
45
+ const [$one, setOne] = createState(5);
46
+ const [$two, setTwo] = createState(20);
47
47
 
48
48
  const deriveSum = t.mock.fn((one, two) => one + two);
49
49
  const deriveProduct = t.mock.fn((one, two) => one * two);
@@ -101,9 +101,9 @@ test("derive", (t) => {
101
101
  });
102
102
 
103
103
  test("derive nested signals", (t) => {
104
- const [$value, setValue] = signal(5);
104
+ const [$value, setValue] = createState(5);
105
105
 
106
- const [$object, setObject] = signal({
106
+ const [$object, setObject] = createState({
107
107
  href: derive([$value], (value) => `/projects/${value}/test`),
108
108
  });
109
109
 
package/vite.config.js CHANGED
@@ -3,8 +3,6 @@ import { defineConfig } from "vite";
3
3
 
4
4
  export default defineConfig({
5
5
  build: {
6
- // minify: "terser",
7
- // minify: false,
8
6
  sourcemap: true,
9
7
 
10
8
  lib: {
@@ -16,13 +14,5 @@ export default defineConfig({
16
14
  name: "Dolla",
17
15
  formats: ["es"],
18
16
  },
19
- // rollupOptions: {
20
- // external: ["vue"],
21
- // output: {
22
- // globals: {
23
- // vue: "Vue",
24
- // },
25
- // },
26
- // },
27
17
  },
28
18
  });