@manyducks.co/dolla 2.0.0-alpha.23 → 2.0.0-alpha.24

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.
package/README.md CHANGED
@@ -20,8 +20,8 @@ Let's first get into some examples.
20
20
 
21
21
  ### Basic State API
22
22
 
23
- ```jsx
24
- import { createState, toState, valueOf, derive, createWatcher } from "@manyducks.co/dolla";
23
+ ```js
24
+ import { createState, derive } from "@manyducks.co/dolla";
25
25
 
26
26
  const [$count, setCount] = createState(72);
27
27
 
@@ -35,26 +35,24 @@ $count.get(); // 300
35
35
  // You can also pass a function that takes the current value and returns a new one
36
36
  setCount((current) => current + 1);
37
37
  $count.get(); // 301
38
+ ```
38
39
 
39
- // Derive a new state from one or more other states. Whenever $count changes, $doubled will follow.
40
+ Now that you have a state you can derive more states from that one. Derived states automatically stay in sync with the values of their dependencies.
41
+
42
+ ```js
43
+ // Pass and array of one or more states followed by a function that computes a new value.
40
44
  const $doubled = derive([$count], (count) => count * 2);
41
- const $sum = derive([$count, $doubled], (count, doubled) => count + doubled);
42
45
 
43
- // Returns the value of a state. If the value is not a state it is returned as is.
44
- const count = valueOf($count);
45
- const bool = valueOf(true);
46
+ $doubled.get(); // 602
46
47
 
47
- // Creates a state from a value. If the value is already a state it is returned as is.
48
- const $bool = toState(true);
49
- const $anotherCount = toState($count);
48
+ setCount(500);
50
49
 
51
- const watcher = createWatcher();
50
+ $doubled.get(); // 1000
51
+ ```
52
+
53
+ ### In Views
52
54
 
53
- // Watch for changes to the value
54
- const stop = watcher.watch([$count], (value) => [
55
- // This function is called immediately with the current value, then again each time the value changes.
56
- ]);
57
- stop(); // Stop watching for changes
55
+ ```jsx
58
56
 
59
57
  ```
60
58
 
@@ -105,12 +103,12 @@ $doubled(); // 100
105
103
  $value(); // 50
106
104
  ```
107
105
 
108
- ## Views [id="section-views"]
106
+ <h2 id="section-views">Views</h2>
109
107
 
110
108
  A basic view:
111
109
 
112
110
  ```js
113
- import Dolla, { createState, html } from "@manyducks.co/dolla";
111
+ import Dolla, { createState } from "@manyducks.co/dolla";
114
112
 
115
113
  function Counter(props, ctx) {
116
114
  const [$count, setCount] = createState(0);
@@ -119,12 +117,24 @@ function Counter(props, ctx) {
119
117
  setCount((count) => count + 1);
120
118
  }
121
119
 
122
- return html`
120
+ function decrement() {
121
+ setCount((count) => count - 1);
122
+ }
123
+
124
+ function reset() {
125
+ setCount(0);
126
+ }
127
+
128
+ return (
123
129
  <div>
124
- <p>Clicks: ${$count}</p>
125
- <button onclick=${increment}>+1</button>
130
+ <p>Clicks: {$count}</p>
131
+ <div>
132
+ <button onClick={decrement}>-1</button>
133
+ <button onClick={reset}>0</button>
134
+ <button onClick={increment}>-1</button>
135
+ </div>
126
136
  </div>
127
- `;
137
+ );
128
138
  }
129
139
 
130
140
  Dolla.mount(document.body, Counter);
@@ -15,6 +15,7 @@ export declare class HTML implements MarkupElement {
15
15
  stopCallbacks: StopFunction[];
16
16
  elementContext: ElementContext;
17
17
  uniqueId: string;
18
+ _batchWrite: (callback: () => void, key?: string) => void;
18
19
  ref?: Ref<any>;
19
20
  canClickAway: boolean;
20
21
  get isMounted(): boolean;
@@ -22,6 +23,7 @@ export declare class HTML implements MarkupElement {
22
23
  mount(parent: Node, after?: Node): void;
23
24
  unmount(parentIsUnmounting?: boolean): void;
24
25
  getUpdateKey(type: string, value: string | number): string;
26
+ _mutate(callback: () => any, updateKey?: string): void;
25
27
  attachProp<T>(value: State<T> | T, callback: (value: T) => void, updateKey: string): void;
26
28
  applyProps(element: HTMLElement | SVGElement, props: Record<string, unknown>): void;
27
29
  applyStyles(element: HTMLElement | SVGElement, styles: unknown, stopCallbacks: StopFunction[]): () => void;
package/dist/index.js CHANGED
@@ -13,8 +13,8 @@ var Y = (o, e, t, r) => ({
13
13
  return a(o, e, r);
14
14
  }
15
15
  });
16
- import { h as Ie, c as it, i as ke, a as Ve, d as F, b as k, e as ot, f as te, t as We, g as Qe, j as lt, s as _e, k as Ge, P as Je, l as Be, m as ze, n as ct, o as ht, p as ut, v as ft, q as dt, r as mt, u as He, w as gt, x as be, y as $e, V as pt, z as wt, A as yt } from "./passthrough-C9975ULD.js";
17
- import { B as Ht, D as Kt, E as Qt, C as Jt } from "./passthrough-C9975ULD.js";
16
+ import { h as Ie, c as it, i as ke, a as Ve, d as F, b as k, e as ot, f as te, t as We, g as Qe, j as lt, s as _e, k as Ge, P as Je, l as Be, m as ze, n as ct, o as ht, p as ut, v as ft, q as dt, r as mt, u as He, w as gt, x as be, y as $e, V as pt, z as wt, A as yt } from "./passthrough-BeKX_qRr.js";
17
+ import { B as Ht, D as Kt, E as Qt, C as Jt } from "./passthrough-BeKX_qRr.js";
18
18
  function bt(o) {
19
19
  return Ie`
20
20
  <div
@@ -754,12 +754,12 @@ class Nt {
754
754
  };
755
755
  window.addEventListener("popstate", t), a(this, G).push(() => window.removeEventListener("popstate", t));
756
756
  const r = e.getRootElement();
757
- return a(this, G).push(
757
+ a(this, G).push(
758
758
  Tt(r, (n) => {
759
759
  let s = n.getAttribute("href");
760
760
  a(this, x).info("intercepted click on <a> tag", n), /^https?:\/\/|^\//.test(s) || (s = H([window.location.pathname, s])), d(this, w, je).call(this, s);
761
761
  })
762
- ), a(this, x).info("will intercept clicks on <a> tags within root element", r), d(this, w, Z).call(this);
762
+ ), a(this, x).info("will intercept clicks on <a> tags within root element", r), await d(this, w, Z).call(this);
763
763
  }), e.onUnmount(() => {
764
764
  for (const t of a(this, G))
765
765
  t();
@@ -829,6 +829,7 @@ W = new WeakMap(), x = new WeakMap(), xe = new WeakMap(), D = new WeakMap(), X =
829
829
  a(this, he).call(this, n), n.pattern !== i && d(this, w, st).call(this, n);
830
830
  } else
831
831
  t.crash(new Ct(`Failed to match route '${r.pathname}'`));
832
+ return { match: n, journey: s };
832
833
  }, Ce = async function(e, t = []) {
833
834
  const r = et(a(this, X), e.pathname);
834
835
  if (!r)