@manyducks.co/dolla 2.0.0-alpha.6 → 2.0.0-alpha.60

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 (104) hide show
  1. package/README.md +86 -591
  2. package/dist/core/context.d.ts +144 -0
  3. package/dist/core/env.d.ts +3 -0
  4. package/dist/core/index.d.ts +22 -0
  5. package/dist/core/logger.d.ts +42 -0
  6. package/dist/core/markup.d.ts +125 -0
  7. package/dist/core/mount.d.ts +15 -0
  8. package/dist/core/nodes/dom.d.ts +14 -0
  9. package/dist/core/nodes/dynamic.d.ts +29 -0
  10. package/dist/core/nodes/html.d.ts +24 -0
  11. package/dist/core/nodes/portal.d.ts +19 -0
  12. package/dist/core/nodes/repeat.d.ts +25 -0
  13. package/dist/core/nodes/view.d.ts +24 -0
  14. package/dist/core/ref.d.ts +18 -0
  15. package/dist/core/signals.d.ts +43 -0
  16. package/dist/core/symbols.d.ts +2 -0
  17. package/dist/{views → core/views}/default-crash-view.d.ts +6 -2
  18. package/dist/core/views/fragment.d.ts +7 -0
  19. package/dist/fragment-BahD_BJA.js +7 -0
  20. package/dist/fragment-BahD_BJA.js.map +1 -0
  21. package/dist/{modules/http.d.ts → http/index.d.ts} +3 -5
  22. package/dist/http.js +163 -0
  23. package/dist/http.js.map +1 -0
  24. package/dist/i18n/index.d.ts +134 -0
  25. package/dist/i18n.js +318 -0
  26. package/dist/i18n.js.map +1 -0
  27. package/dist/index.js +105 -1385
  28. package/dist/index.js.map +1 -1
  29. package/dist/jsx-dev-runtime.d.ts +3 -2
  30. package/dist/jsx-dev-runtime.js +5 -12
  31. package/dist/jsx-dev-runtime.js.map +1 -1
  32. package/dist/jsx-runtime.d.ts +4 -3
  33. package/dist/jsx-runtime.js +9 -15
  34. package/dist/jsx-runtime.js.map +1 -1
  35. package/dist/logger-MPwl-Xqu.js +524 -0
  36. package/dist/logger-MPwl-Xqu.js.map +1 -0
  37. package/dist/markup-BGlfQYQk.js +996 -0
  38. package/dist/markup-BGlfQYQk.js.map +1 -0
  39. package/dist/router/index.d.ts +2 -0
  40. package/dist/router/router.d.ts +149 -0
  41. package/dist/{routing.d.ts → router/router.utils.d.ts} +17 -3
  42. package/dist/router/router.utils.test.d.ts +1 -0
  43. package/dist/router-BpuJQ6OA.js +516 -0
  44. package/dist/router-BpuJQ6OA.js.map +1 -0
  45. package/dist/router.js +8 -0
  46. package/dist/router.js.map +1 -0
  47. package/dist/typeChecking-CbltMOUt.js +71 -0
  48. package/dist/typeChecking-CbltMOUt.js.map +1 -0
  49. package/dist/typeChecking.d.ts +2 -98
  50. package/dist/typeChecking.test.d.ts +1 -0
  51. package/dist/types.d.ts +98 -25
  52. package/dist/utils.d.ts +20 -3
  53. package/docs/http.md +29 -0
  54. package/docs/i18n.md +43 -0
  55. package/docs/index.md +10 -0
  56. package/docs/markup.md +16 -0
  57. package/docs/mixins.md +32 -0
  58. package/docs/ref.md +93 -0
  59. package/docs/router.md +80 -0
  60. package/docs/setup.md +31 -0
  61. package/docs/signals.md +166 -0
  62. package/docs/state.md +141 -0
  63. package/docs/stores.md +62 -0
  64. package/docs/views.md +208 -0
  65. package/examples/webcomponent/index.html +14 -0
  66. package/examples/webcomponent/main.js +165 -0
  67. package/index.d.ts +2 -2
  68. package/notes/TODO.md +6 -0
  69. package/notes/atomic.md +452 -0
  70. package/notes/context-routes.md +61 -0
  71. package/notes/custom-nodes.md +17 -0
  72. package/notes/effection-idea.md +34 -0
  73. package/notes/elimination.md +33 -0
  74. package/notes/mixins.md +22 -0
  75. package/notes/molecule.md +35 -0
  76. package/notes/observable.md +180 -0
  77. package/notes/readme-scratch.md +45 -7
  78. package/notes/route-middleware.md +42 -0
  79. package/notes/scratch.md +353 -6
  80. package/notes/splitting.md +5 -0
  81. package/notes/stores.md +79 -0
  82. package/package.json +27 -12
  83. package/vite.config.js +5 -11
  84. package/build.js +0 -34
  85. package/dist/index.d.ts +0 -21
  86. package/dist/markup.d.ts +0 -100
  87. package/dist/modules/dolla.d.ts +0 -111
  88. package/dist/modules/language.d.ts +0 -41
  89. package/dist/modules/render.d.ts +0 -17
  90. package/dist/modules/router.d.ts +0 -152
  91. package/dist/nodes/cond.d.ts +0 -26
  92. package/dist/nodes/html.d.ts +0 -31
  93. package/dist/nodes/observer.d.ts +0 -29
  94. package/dist/nodes/outlet.d.ts +0 -22
  95. package/dist/nodes/portal.d.ts +0 -19
  96. package/dist/nodes/repeat.d.ts +0 -34
  97. package/dist/nodes/text.d.ts +0 -19
  98. package/dist/passthrough-CW8Ezjg-.js +0 -1244
  99. package/dist/passthrough-CW8Ezjg-.js.map +0 -1
  100. package/dist/state.d.ts +0 -101
  101. package/dist/view.d.ts +0 -50
  102. package/dist/views/passthrough.d.ts +0 -5
  103. package/tests/state.test.js +0 -135
  104. /package/dist/{routing.test.d.ts → core/signals.test.d.ts} +0 -0
@@ -0,0 +1,452 @@
1
+ # ATOMIC overhaul
2
+
3
+ Overhaul of Dolla as Atomic.
4
+
5
+ Diff:
6
+
7
+ - Change signals to plain functions.
8
+ - Access component context things with $functions in the component body.
9
+ - Split `router` and `localize` into companion packages.
10
+ - No top-level app; just `mount` a view.
11
+
12
+ Goals:
13
+
14
+ - Easy drop-in script tag to get started. Feasible to start with a CDN for prototyping and introduce build step later.
15
+ - Server side rendering support. `html` templates should create intermediate data structure that can be turned into DOM nodes or a string.
16
+
17
+ ## Signals
18
+
19
+ ```js
20
+ import { atom, memo } from "@manyducks.co/atomic";
21
+
22
+ // Atoms are hybrid getter/setter functions. Call without a value to get, call with a value to set.
23
+ const count = atom(0);
24
+
25
+ // Basic computed properties are just functions. Taking advantage of the fact that functions called in functions will still be tracked.
26
+ const doubled = () => count() * 2;
27
+
28
+ // Use memo to make a memoized value for more expensive calculations.
29
+ const quadrupled = memo(() => doubled() * 2);
30
+ ```
31
+
32
+ ## Scopes
33
+
34
+ Provided are certain functions that start with a `$` character. These are scope functions. They only work inside a component scope, which is to say, inside the body of a View or Store function.
35
+
36
+ ViewContext and StoreContext cease to be something the user worries about. Just import and call scope functions. This also provides TypeScript autocomplete for stores and things in plain JS.
37
+
38
+ ```js
39
+ function Example() {
40
+ // Lifecycle
41
+ $mount(() => {
42
+ // ...
43
+ });
44
+ $unmount(() => {
45
+ // ...
46
+ });
47
+
48
+ // Logger
49
+ const debug = $debug();
50
+ const debug = $debug("my-custom-prefix"); // Optionally pass a prefix (replaces ctx.name = "...")
51
+
52
+ // Signal effects
53
+ const count = atom(0);
54
+ $effect(() => {
55
+ debug.log("count has changed: %d", count());
56
+
57
+ return () => {
58
+ // Cleanup function. Runs between effect invocations or on unmount.
59
+ };
60
+ });
61
+
62
+ // Context/Stores
63
+ $provide(SomeStore);
64
+ const some = $use(SomeStore);
65
+
66
+ // Router lib:
67
+ const router = $router();
68
+ router.pattern; // full pattern up to this point in the tree (merged from nested parent routers)
69
+ router.path; // full path up to this point
70
+ router.params; // merged params
71
+ router.query; // parsed query params
72
+ // Router navigation:
73
+ router.go("/somewhere/else");
74
+ router.back();
75
+ router.forward();
76
+
77
+ // .on() returns an outlet on which you can chain more .on() to define subroutes.
78
+ // This goes directly into your template to render those routes.
79
+ const outlet = router
80
+ .on("/example/route/one/*", SomeView)
81
+ .on("/example/route/two/*", OtherView)
82
+ .on("/example/route/three/*", AnotherView);
83
+
84
+ // Localize lib:
85
+ const { t } = $localize();
86
+
87
+ // Special internal function. Returns the actual internal context object.
88
+ // This could be exported for extension purposes.
89
+ const ctx = $$context();
90
+
91
+ // TODO: Need another way to render children. Children should be passed to the view (as Markup).
92
+ // So maybe just passing them into your template would work.
93
+ }
94
+ ```
95
+
96
+ ### Scopes
97
+
98
+ > NOTE: Views and directives are called within a scope.
99
+
100
+ ```js
101
+ // Functions starting with $ can be called within a scope.
102
+ // Scopes will clean up all effects created within them when they are disconnected.
103
+ const scope = createScope(() => {
104
+ $effect(() => {
105
+ // Atoms and memos called within an $effect are automatically tracked.
106
+ console.log(`count is ${count()} (doubled: ${doubled()})`);
107
+ });
108
+
109
+ // Changing tracked values will trigger effects to run again.
110
+ count(1);
111
+
112
+ // $effects are called immediately once, then again each time one or more dependencies change.
113
+ // Effects are settled in queueMicrotask(), effectively batching them.
114
+
115
+ count(2);
116
+ count(3);
117
+ count(4);
118
+ // Multiple synchronous calls in a row like this will only trigger the effect once.
119
+ });
120
+
121
+ // ----- Scope Functions ----- //
122
+
123
+ $effect(() => {
124
+ // Tracks dependencies. This function will run again when any of them change.
125
+ });
126
+
127
+ $connected(() => {
128
+ // Runs when scope is connected.
129
+ // In views and directives this happens in the next microtask after DOM nodes are attached.
130
+ });
131
+
132
+ $disconnected(() => {
133
+ // Runs when scope is disconnected.
134
+ // In views and directives this happens in the next microtask after DOM nodes are disconnected.
135
+ });
136
+
137
+ // ----- Scope API ----- //
138
+
139
+ const scope = createScope(() => {
140
+ /* ... */
141
+ });
142
+
143
+ // Connect starts all $effects and runs $connected callbacks.
144
+ scope.connect();
145
+
146
+ // Disconnect disposes all $effects and runs $disconnected callbacks.
147
+ scope.disconnect();
148
+ ```
149
+
150
+ ## Templates
151
+
152
+ ```js
153
+ // Provide directives and views in a config object.
154
+ const template = html({
155
+ directives: { custom: customDirective },
156
+ views: { SomeView },
157
+ })`
158
+ <div>
159
+ <SomeView *custom=${x} prop=${value} />
160
+ </div>
161
+ `;
162
+
163
+ // Or put the views and directives at the end?
164
+ const template = html`
165
+ <div>
166
+ <p>Counter: ${count}</p>
167
+
168
+ <!-- bind events with @name -->
169
+ <div>
170
+ <button @click=${increment}>+1</button>
171
+ <button @click=${decrement}>-1</button>
172
+ </div>
173
+
174
+ <!-- apply directives with *name -->
175
+ <div *ref=${refAtom} *if=${x} *unless=${x} *show=${x} *hide=${x} *classes=${x} *styles=${x} *custom=${whatever} />
176
+
177
+ <!-- bind properties with .name -->
178
+ <span .textContent=${x} />
179
+
180
+ <!-- two-way bind atoms with :value -->
181
+ <input :value=${valueAtom} />
182
+
183
+ <ul *if=${hasValues}>
184
+ <!-- render iterables from signals with list() -->
185
+ ${list(values, (value, index) => {
186
+ // Render views into HTML templates with view()
187
+ return html`<li><SomeView item=${value} /></li>`.withViews({ SomeView });
188
+ })}
189
+ </ul>
190
+ </div>
191
+ `
192
+ .withDirectives({ custom: customDirective })
193
+ .withViews({ SomeView });
194
+
195
+ // Key
196
+ // @ for event listeners
197
+ // * for directives
198
+ // . for properties
199
+ // :value for two-way value binding
200
+ // no prefix for attributes
201
+ ```
202
+
203
+ ### Event modifiers
204
+
205
+ ```js
206
+ html`<button
207
+ @click.stop.prevent.throttle[250]=${() => {
208
+ // stopPropagation & preventDefault already called
209
+ // Listener will be triggered a maximum of once every 250 milliseconds.
210
+ }}
211
+ >
212
+ Click Me
213
+ </button>`;
214
+ ```
215
+
216
+ You can chain modifiers on event handlers. Inspired by [`Mizu.js`](https://mizu.sh/#event).
217
+
218
+ #### `.prevent`
219
+
220
+ Calls event.preventDefault() when triggered.
221
+
222
+ #### `.stop`
223
+
224
+ Calls event.stopPropagation() when triggered.
225
+
226
+ #### `.once`
227
+
228
+ Register listener with { once: true }. If present the listener is removed after being triggered once.
229
+
230
+ #### `.passive`
231
+
232
+ Register listener with { passive: true }.
233
+
234
+ #### `.capture`
235
+
236
+ Register listener with { capture: true }.
237
+
238
+ #### `.self`
239
+
240
+ Trigger listener only if event.target is the element itself.
241
+
242
+ #### `.attach[element | window | document]`
243
+
244
+ > `@click.attach[document]=${...}`
245
+
246
+ Attach listener to a different target.
247
+
248
+ #### `.throttle[duration≈250ms]`
249
+
250
+ Prevent listener from being called more than once during the specified time frame. Duration value is in milliseconds.
251
+
252
+ #### `.debounce[duration≈250ms]`
253
+
254
+ Delay listener execution until the specified time frame has passed without any activity. Duration value is in milliseconds.
255
+
256
+ ### Lists
257
+
258
+ ```js
259
+ list(values, (value, index) => {
260
+ return html`<li>${view(SomeComponent, value)}</li>`;
261
+ });
262
+ ```
263
+
264
+ ### Custom Directives
265
+
266
+ ```js
267
+ function myDirective(element, value, modifiers) {
268
+ // Directives are called inside a scope.
269
+ $disconnected(() => {
270
+ // Cleanup
271
+ });
272
+ }
273
+ ```
274
+
275
+ ## Full Example
276
+
277
+ ```js
278
+ import { atom, memo, html, connect, $effect } from "@manyducks.co/atomic";
279
+
280
+ // Functions starting with $ can only be called in the body of a component function.
281
+
282
+ // IDEA: CSS components. Ref counted and added to head while used at least once on the page.
283
+ const button = css`
284
+ color: "red";
285
+
286
+ &:hover {
287
+ color: "blue";
288
+ }
289
+ `;
290
+
291
+ function Counter() {
292
+ const debug = logger("Component");
293
+
294
+ const count = atom(0);
295
+
296
+ // Simple computed value; computation runs each time function is called
297
+ const doubled = () => count() * 2;
298
+
299
+ // Memoized; computation only runs when one of its dependencies changes
300
+ const quadrupled = memo((previousValue) => doubled() * 2, { equals: deepEqual });
301
+ // memos pass their previous to their callback
302
+ // memos can have an equality function specified (as can atoms)
303
+
304
+ $effect(() => {
305
+ // Dependencies are tracked when getters are called in a tracked scope.
306
+ // Tracked scopes are the body of a `memo` or `effect` callback.
307
+ debug.log(`Count is: ${count()}`);
308
+
309
+ // untrack
310
+ const value = peek(count);
311
+ const doubled = peek(() => {
312
+ return count() * 2;
313
+ });
314
+ });
315
+
316
+ $connected(() => {
317
+ // Runs when component is connected.
318
+ });
319
+
320
+ $disconnected(() => {
321
+ // Runs when component is disconnected.
322
+ });
323
+
324
+ function increment() {
325
+ // Set new value
326
+ count(count() + 1);
327
+ }
328
+
329
+ function decrement() {
330
+ count(count() - 1);
331
+ }
332
+
333
+ const hasValues = () => values().length > 0;
334
+
335
+ return html`
336
+ <div>
337
+ <p>Counter: ${count}</p>
338
+ <div>
339
+ <button @click=${increment}>+1</button>
340
+ <button @click=${decrement}>-1</button>
341
+ </div>
342
+
343
+ <div *ref=${refAtom} *if=${x} *unless=${x} *show=${x} *hide=${x} *classes=${x} *styles=${x} *custom=${whatever} />
344
+
345
+ <!-- Property binding -->
346
+ <span .textContent=${x} />
347
+
348
+ <!-- Two way binding of atoms -->
349
+ <input :value=${valueAtom} />
350
+
351
+ <ul *if=${hasValues}>
352
+ ${list(values, (value, index) => {
353
+ return html`<li>${view(SomeComponent, value)}</li>`;
354
+ })}
355
+ </ul>
356
+ </div>
357
+ `.withDirectives({ custom: customDirective });
358
+ }
359
+
360
+ // In another file...
361
+
362
+ function refDirective(element, fn) {
363
+ fn(element);
364
+ $disconnected(() => {
365
+ fn(undefined);
366
+ });
367
+ }
368
+
369
+ function ifDirective(element, condition) {
370
+ // directives run in microtask immediately after element is attached to parent, before next paint
371
+
372
+ const placeholder = document.createComment("");
373
+
374
+ // $functions work in directives; they hook into the lifecycle of the element
375
+ $effect(() => {
376
+ if (condition()) {
377
+ // show element
378
+ if (!element.parentNode && placeholder.parentNode) {
379
+ element.insertBefore(placeholder.parentNode);
380
+ placeholder.parentNode.removeChild(placeholder);
381
+ }
382
+ } else {
383
+ // hide element
384
+ if (element.parentNode && !placeholder.parentNode) {
385
+ placeholder.insertBefore(element.parentNode);
386
+ element.parentNode.removeChild(element);
387
+ }
388
+ }
389
+ });
390
+ }
391
+
392
+ function unlessDirective(element, condition) {
393
+ return ifDirective(element, () => !condition());
394
+ }
395
+
396
+ function showDirective(element, condition) {
397
+ // Store the element's current value.
398
+ let value = element.style.display;
399
+
400
+ $effect(() => {
401
+ if (condition()) {
402
+ // Apply the stored value when truthy.
403
+ element.style.display = value;
404
+ } else {
405
+ // Store value and hide when falsy.
406
+ value = element.style.display;
407
+ element.style.display = "none !important";
408
+ }
409
+ });
410
+ }
411
+
412
+ function hideDirective(element, condition) {
413
+ return showDirective(element, () => !condition());
414
+ }
415
+
416
+ function classesDirective(element, classes) {
417
+ // TODO: Applies an object of class names and values, where the values may be signals or plain values.
418
+ // Truthy means "apply this class" while falsy means don't.
419
+ }
420
+
421
+ function stylesDirective(element, styles) {
422
+ // TODO: Same idea as *classes but for styles.
423
+ }
424
+
425
+ connect(Component, document.body);
426
+
427
+ // Easy custom elements? Could be another library.
428
+ element("my-counter", function () {
429
+ // Runs just after connectedCallback. `this` is bound to the custom HTMLElement class.
430
+ const shadow = this.attachShadow({ mode: "closed" });
431
+
432
+ return html`<div></div>`;
433
+ });
434
+
435
+ // function css(strings, values) {
436
+ // return {
437
+ // type: "css",
438
+
439
+ // }
440
+ // }
441
+ ```
442
+
443
+ ```ts
444
+ interface TemplateNode {
445
+ mount(parent: Node, after?: Node): void;
446
+ unmount(skipDOM?: boolean): void;
447
+ }
448
+
449
+ interface TemplateDirective {
450
+ (element: Element, value: unknown): Node | TemplateNode;
451
+ }
452
+ ```
@@ -0,0 +1,61 @@
1
+ # Context routing
2
+
3
+ I had an idea to integrate routing back into views instead of having a separate router. I originally had it work this way but I wasn't good enough to pull it off then.
4
+
5
+ Here's how it might look:
6
+
7
+ ```jsx
8
+ function Example(props, ctx) {
9
+ return <div>
10
+ <header>
11
+ <h1>Some kind of layout.</h1>
12
+ </header>
13
+ <main>
14
+ {this.router(function () {
15
+ this.route("something/*", SomethingView);
16
+ this.redirect("*", "./something/*");
17
+ })}
18
+
19
+ {ctx.router([
20
+ // Route path is relative to parent routes.
21
+ // Nested route definitions are a thing of the past.
22
+ // View could define its own routes.
23
+ { path: "something/*", view: SomethingView }
24
+ ])}
25
+ </main>
26
+ <div>
27
+ }
28
+
29
+ html`
30
+ <${Router}>
31
+ <${Route} path="something/*">
32
+ This child content isn't materialized until the route matches.
33
+ <${SomethingView} />
34
+ <//>
35
+ <//>
36
+ `
37
+ ```
38
+
39
+ This removes the need to import and define the whole app at the top level. You can also add routes as you need them when prototyping.
40
+
41
+ Route matching would be done by forwarding the wildcard portion of a match to child routers. Routers would be stored on the element context.
42
+
43
+ Where would route info be stored then? It would have to be on the context as well.
44
+
45
+ ```js
46
+ // Merged data from all parent segments.
47
+ ctx.route.params;
48
+ ctx.route.query;
49
+ ctx.route.path;
50
+ ctx.route.pattern;
51
+
52
+ ctx.go("/some/path");
53
+ ctx.back();
54
+ ctx.forward();
55
+ ```
56
+
57
+ ## Thoughts
58
+
59
+ - Would eliminate the need for `ctx.outlet()`. Can pass children directly via `children` prop now.
60
+ - Would eliminate the need for `ViewElement` and `setChildView` method because a top level router no longer needs to call it.
61
+ - Couldn't do the current routing strategy of combining all routes into one flat list at the top level.
@@ -0,0 +1,17 @@
1
+ What if people could define custom Markup nodes and use them in JSX. Alternative to writing a view if you need lighter weight or more custom elements.
2
+
3
+ ```js
4
+ class CustomNode implements MarkupNode {
5
+ domNode = document.createElement('div');
6
+
7
+ isMounted = false;
8
+
9
+ mount(parent, before) {
10
+
11
+ }
12
+
13
+ unmount(parentIsUnmounting) {
14
+
15
+ }
16
+ }
17
+ ```
@@ -0,0 +1,34 @@
1
+ # Effection Idea
2
+
3
+ This is probably a different framework, but I've been looking into Effection lately. Effection uses generators to manage async code, guaranteeing that cleanup runs and that you can use synchronous constructs like try/catch as you'd expect. I kind of like it, so I was thinking of adapting dolla views to use generators as well for async mounting and cleanup. It's worth trying just as an experiment and for learning more about generators.
4
+
5
+ Generators are a poorly understood concept to me and I'm guessing most devs, because I never see them suggested as a solution to any problem in mainstream circles.
6
+
7
+ ```js
8
+ const ExampleStore = store(function* () {
9
+ // Yield setup (optional)
10
+ yield* function* () {};
11
+
12
+ //
13
+ yield {};
14
+
15
+ // Yield teardown (optional)
16
+ yield* function* () {};
17
+ });
18
+
19
+ const ExampleView = view(function* () {
20
+ yield* provide(ExampleStore);
21
+
22
+ const example = yield* use(ExampleStore);
23
+
24
+ // Yield setup (optional)
25
+ yield* function* () {};
26
+
27
+ // Yield markup for rendering.
28
+ // When mounting, the view is considered mounted when the view yields markup.
29
+ yield <div>TEST</div>;
30
+
31
+ // Yield teardown (optional)
32
+ yield* function* () {};
33
+ });
34
+ ```
@@ -0,0 +1,33 @@
1
+ # What can we remove?
2
+
3
+ I still want to get this library with all its features down below 15kb. It's currently at 17.8kb. That said, I don't want to strip out things that are actually useful. The mission of this library is to be batteries-included, which implies some extra weight.
4
+
5
+ What can be removed without compromising the basics?
6
+
7
+ ## Events?
8
+
9
+ > 1st ELIMINATED. We're at 16.77kb now.
10
+
11
+ If we have the ability to get contexts and call methods on them, isn't that just a better version of events?
12
+
13
+ ## Logger / Built-in Crash View
14
+
15
+ > REDUCED! Removed simple-color-hash in favor of custom OKLCH hash and we're down to 15.9kb.
16
+
17
+ Logger could be a different package. Crashes could be handled by a crash handler you attach.
18
+
19
+ ```js
20
+ Dolla.onCrash((error) => {
21
+ // Do what you will with this error.
22
+ });
23
+ ```
24
+
25
+ ## HTTP Client?
26
+
27
+ Do we really need this? It's kind of a nice wrapper but the only thing I use the middleware for is to add auth headers for API calls, and it's trivial to write a function around `fetch` that does that. No need for the complexity of middleware.
28
+
29
+ Not really. Fetch is hella basic. I just tried to write my own trivial wrapper around fetch and it took a little too much thought. I don't want to do that for every project. Adding middleware to authenticate feels trivial with `http`.
30
+
31
+ ## Markup?
32
+
33
+ Can JSX and `html` return DOM nodes directly? Not really, because views need to be mounted and unmounted like DOM nodes but they don't have the same API. Although I could define a minimal DOM-compatible API so that DOM nodes could directly work.
@@ -0,0 +1,22 @@
1
+ # Mixins
2
+
3
+ Sometimes you want to attach logic to a DOM node without writing a whole view around it.
4
+
5
+ ```js
6
+ function myMixin(options: any): Mixin {
7
+ return function(element: Element, ctx: MixinContext) {
8
+ ctx.onMount(() => {
9
+
10
+ })
11
+
12
+ ctx.onUnmount(() => {
13
+
14
+ })
15
+ }
16
+
17
+
18
+ // Returns nothing. Use context methods to attach event listeners / behavior / whatever.
19
+ }
20
+
21
+ <h1 mixins={[myMixin({ /* options */ }), /* ... */]}>Whatever</h1>
22
+ ```
@@ -0,0 +1,35 @@
1
+ Like `compose` but it takes an initial value and a function that can set its value asynchronously. Its callback is a tracking context, so it will be re-run when signals called within are updated.
2
+
3
+ ```ts
4
+ interface MoleculeGetter<T> {
5
+ (): T;
6
+ <X>(source: MaybeReactive<X>): X;
7
+ }
8
+
9
+ interface MoleculeSetter<T> {
10
+ (next: T): void;
11
+ }
12
+
13
+ interface MoleculeFunction<T> {
14
+ (get: MoleculeGetter<T>, set: MoleculeSetter<T>): void | (() => void);
15
+ }
16
+
17
+ function molecule<T>(initialValue: T, fn: MoleculeFunction<T>) {}
18
+
19
+ const value = molecule(5, (get, set) => {
20
+ // get() returns the current value stored in this hadron
21
+ // get(reactive) returns the value of that reactive and tracks it (== reactive.get())
22
+ // set(value) updates the value stored in this hadron
23
+ // This function will not be called unless there is at least one observer.
24
+
25
+ let interval = setInterval(() => {
26
+ set(get() + 1);
27
+ }, 1000);
28
+
29
+ // Can return a cleanup function to run between invocations.
30
+ // Also called when the last observer stops observing.
31
+ return () => {
32
+ clearInterval(interval);
33
+ };
34
+ });
35
+ ```