@manyducks.co/dolla 2.0.0-alpha.1 → 2.0.0-alpha.2

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
@@ -3,16 +3,15 @@
3
3
  ![bundle size](https://img.shields.io/bundlephobia/min/@manyducks.co/dolla)
4
4
  ![bundle size](https://img.shields.io/bundlephobia/minzip/@manyducks.co/dolla)
5
5
 
6
- > WARNING: This package is pre-1.0 and therefore may contain serious bugs and releases may introduce breaking changes without notice.
6
+ > WARNING: This package is in active development. It may contain serious bugs and releases may introduce breaking changes without notice.
7
7
 
8
- Dolla is a batteries-included JavaScript frontend framework covering the needs of complex modern single page apps (SPA). Dolla provides:
8
+ Dolla is a batteries-included JavaScript frontend framework covering the needs of moderate-to-complex single page apps:
9
9
 
10
- - Components
10
+ - Reactive DOM updates (Signals)
11
+ - Reusable components (Views)
11
12
  - Routing
12
- - State management
13
- - Declarative templating and DOM updates via signals
14
- - An HTTP client
15
- -
13
+ - HTTP client
14
+ - Localization (translations as JSON files and a `t` function to get strings)
16
15
 
17
16
  Let's first get into some examples.
18
17
 
@@ -58,28 +57,86 @@ import { createSignal, derive } from "@manyducks.co/dolla";
58
57
 
59
58
  const [$count, setCount] = createSignal(0);
60
59
  const $doubled = derive([$count], (count) => count * 2);
60
+
61
+ setCount(1); // $count = 1, $doubled = 2
62
+ setCount(256); // $count = 256, $doubled = 512
63
+ setCount(-37); // $count = -37, $doubled = -74
61
64
  ```
62
65
 
63
- ## A Basic Component
66
+ ## A Basic View
64
67
 
65
- ```tsx
66
- import Dolla from "@manyducks.co/dolla";
68
+ ```js
69
+ import Dolla, { html } from "@manyducks.co/dolla";
67
70
 
68
- function Counter(props, c) {
71
+ function Counter(props, ctx) {
69
72
  const [$count, setCount] = Dolla.createSignal(0);
70
73
 
71
74
  function increment() {
72
75
  setCount((count) => count + 1);
73
76
  }
74
77
 
75
- return (
78
+ return html`
76
79
  <div>
77
- <p>Clicks: {$count}</p>
78
- <button onClick={increment}>Click Me</button>
80
+ <p>Clicks: ${$count}</p>
81
+ <button onclick=${increment}>Click here to increment</button>
79
82
  </div>
80
- );
83
+ `;
84
+ }
85
+
86
+ Dolla.mount(document.body, Counter);
87
+ ```
88
+
89
+ The above example, annotated:
90
+
91
+ ```js
92
+ import Dolla, { html } from "@manyducks.co/dolla";
93
+
94
+ function Counter(props, ctx) {
95
+ const [$count, setCount] = Dolla.createSignal(0);
96
+
97
+ function increment() {
98
+ setCount((count) => count + 1);
99
+ }
100
+
101
+ return html`
102
+ <div>
103
+ <p>Clicks: ${$count}</p>
104
+ <button onclick=${increment}>Click here to increment</button>
105
+ </div>
106
+ `;
107
+ }
108
+
109
+ Dolla.mount(document.body, Counter);
110
+ ```
111
+
112
+ Localized:
113
+
114
+ ```js
115
+ import Dolla, { html, t } from "@manyducks.co/dolla";
116
+
117
+ function Counter(props, ctx) {
118
+ const [$count, setCount] = Dolla.createSignal(0);
119
+
120
+ function increment() {
121
+ setCount((count) => count + 1);
122
+ }
123
+
124
+ return html`
125
+ <div>
126
+ <p>Clicks: ${$count}</p>
127
+ <button onclick=${increment}>${t("buttonLabel")}</button>
128
+ </div>
129
+ `;
81
130
  }
82
131
 
132
+ Dolla.language.setup({
133
+ initialLanguage: "en",
134
+ languages: [
135
+ { name: "en", strings: { buttonLabel: "Click here to increment" } },
136
+ { name: "ja", strings: { buttonLabel: "ここに押して増加する" } },
137
+ ],
138
+ });
139
+
83
140
  Dolla.mount(document.body, Counter);
84
141
  ```
85
142
 
@@ -87,8 +144,6 @@ If you've ever used React before (and chances are you have if you're interested
87
144
 
88
145
  The biggest difference is that the Counter function runs only once when the component is mounted. All updates after that point are a direct result of the `$count` signal being updated.
89
146
 
90
- You'll notice that signals are typically named with a `$` at the beginning to indicate that they contain special values that may change over time.
91
-
92
147
  ## Advanced Componentry
93
148
 
94
149
  Component functions take two arguments; props and a `Context` object. Props are passed from parent components to child components, and `Context` is provided by the app.
@@ -405,6 +460,24 @@ function ExampleView() {
405
460
 
406
461
  A view function takes a `props` object as its first argument. This object contains all properties passed to the view when it's invoked.
407
462
 
463
+ ```js
464
+ import { html } from "@manyducks.co/dolla";
465
+
466
+ function ListView(props, ctx) {
467
+ return html`
468
+ <ul>
469
+ <${ListItemView} label="Squirrel" />
470
+ <${ListItemView} label="Chipmunk" />
471
+ <${ListItemView} label="Groundhog" />
472
+ </ul>
473
+ `;
474
+ }
475
+
476
+ function ListItemView(props, ctx) {
477
+ return html`<li>${props.label}</li>`;
478
+ }
479
+ ```
480
+
408
481
  ```jsx
409
482
  function ListView() {
410
483
  return (
package/dist/index.d.ts CHANGED
@@ -1,38 +1,15 @@
1
- export type { Environment } from "./modules/dolla.js";
2
- export type { HTTPRequest, HTTPResponse } from "./modules/http.js";
3
1
  export { createSettableSignal, createSignal, createSignalSetter, derive, designalify, signalify, toSettableSignal, watch, } from "./signals.js";
4
2
  export type { MaybeSignal, SettableSignal, Signal, StopFunction } from "./signals.js";
5
- export { router };
6
3
  import { Dolla } from "./modules/dolla.js";
7
4
  declare const dolla: Dolla;
8
- export declare const beforeMount: (callback: () => void | Promise<void>) => void;
9
- export declare const onMount: (callback: () => void) => void;
10
- export declare const beforeUnmount: (callback: () => void | Promise<void>) => void;
11
- export declare const onUnmount: (callback: () => void) => void;
12
- export declare const mount: {
13
- (selector: string, view?: import("./view.js").ViewFunction<any> | undefined): Promise<void>;
14
- (element: HTMLElement, view?: import("./view.js").ViewFunction<any> | undefined): Promise<void>;
15
- };
16
- export declare const unmount: () => Promise<void>;
17
- export declare const http: import("./modules/http.js").HTTP;
18
- export declare const render: import("./modules/render.js").Render;
19
- export declare const createLogger: (name: string | import("./signals.js").Signal<string>, options?: import("./modules/dolla.js").LoggerOptions | undefined) => import("./modules/dolla.js").Logger;
20
- export declare const setLogFilter: (filter: string | RegExp) => void;
21
- export declare const setLogges: (options: Partial<import("./modules/dolla.js").Loggles>) => void;
22
5
  export declare const t: (key: string, values?: Record<string, import("./types.js").Stringable | import("./signals.js").Signal<import("./types.js").Stringable>> | undefined) => import("./signals.js").Signal<string>;
23
- import * as router from "./modules/router.js";
24
- export { cond, createMarkup, portal, repeat, createRef, isRef } from "./markup.js";
25
- export type { DOMHandle, Ref } from "./markup.js";
26
- /**
27
- * Generate markup with HTML in a tagged template literal.
28
- */
29
- export declare const html: (strings: TemplateStringsArray, ...values: any[]) => import("./markup.js").Markup | import("./markup.js").Markup[];
30
- export type { ViewFunction } from "./view.js";
31
- export { Fragment } from "./views/fragment.js";
32
- export declare const constructView: <P>(view: import("./view.js").ViewFunction<P>, props: P, children?: import("./markup.js").Markup[]) => import("./markup.js").DOMHandle;
33
- export type { Markup } from "./markup.js";
6
+ export { html, cond, createMarkup, portal, repeat, createRef, isRef } from "./markup.js";
7
+ export type { Markup, MarkupNode, Ref } from "./markup.js";
8
+ export type { ViewFunction, ViewContext, ViewNode } from "./view.js";
9
+ export type { CrashViewProps } from "./views/default-crash-view.js";
34
10
  export type { InputType, Renderable } from "./types.js";
35
- export type { ViewContext } from "./view.js";
11
+ export type { Environment } from "./modules/dolla.js";
12
+ export type { HTTPRequest, HTTPResponse } from "./modules/http.js";
36
13
  import type { IntrinsicElements as Elements } from "./types";
37
14
  declare global {
38
15
  namespace JSX {