Skip to content

Commit b0018e7

Browse files
docs: update readmes, add imports for code snippets
1 parent 98ed1c1 commit b0018e7

30 files changed

+762
-190
lines changed

Diff for: packages/atom/README.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ values. These updates are handled via immutable setters provided by
216216
[@thi.ng/paths](https://github.com/thi-ng/umbrella/tree/develop/packages/paths).
217217

218218
```ts
219+
import { defAtom } from "@thi.ng/atom";
220+
219221
const db = defAtom({ a: { b: 1, c: 2 } });
220222

221223
// type checked access
@@ -277,6 +279,8 @@ e.g. `Atom`, `Cursor` or `History` instances. `Transacted` also implements
277279
`IAtom` itself...
278280

279281
```ts
282+
import { defAtom, defTransacted } from "@thi.ng/atom";
283+
280284
const db = defAtom<any>({ a: 1, b: 2 });
281285
const tx = defTransacted(db);
282286

@@ -285,7 +289,7 @@ tx.begin();
285289

286290
// alternatively use syntax sugar for:
287291
// `defTransacted(db).begin()`
288-
tx = beginTransaction(db);
292+
// tx = beginTransaction(db);
289293

290294
// perform multiple updates
291295
// (none of them are applied to the parent state
@@ -320,6 +324,10 @@ supported and attempting to do so will throw an error. However, nested
320324
transactions can be achieved by wrapping another `Transacted` container.
321325

322326
```ts
327+
import { beginTransaction } from "@thi.ng/atom";
328+
329+
// (db defined earlier...)
330+
323331
const tx1 = beginTransaction(db);
324332
tx1.resetIn(["a"], 10);
325333

@@ -342,6 +350,10 @@ to signal race conditions due to erroneous / out-of-phase state update
342350
logic.
343351

344352
```ts
353+
import { beginTransaction } from "@thi.ng/atom";
354+
355+
// (db defined earlier...)
356+
345357
const tx = beginTransaction(db);
346358
tx.resetIn(["a"], 10);
347359

@@ -370,6 +382,8 @@ I.e. any change to a cursor's value propagates up the hierarchy of
370382
parent states and also triggers any watches attached to the parent.
371383

372384
```ts
385+
import { defAtom, defCursor } from "@thi.ng/atom";
386+
373387
a = defAtom({a: {b: {c: 1}}})
374388
// cursor to `b` value
375389
b = defCursor(a, "a.b")
@@ -390,6 +404,8 @@ rather wide than deep (my personal limit is 3-4 levels) to minimize the
390404
length of the propagation chain and maximize structural sharing.
391405

392406
```ts
407+
import { defAtom, defCursor, defCursorUnsafe } from "@thi.ng/atom";
408+
393409
// main state
394410
main = defAtom({ a: { b: { c: 23 }, d: { e: 42 } }, f: 66 });
395411

@@ -420,6 +436,8 @@ and the ability to (optionally) produce transformed versions of such a
420436
value. The `View` type provides exactly this functionality:
421437

422438
```ts
439+
import { defAtom, defView, defViewUnsafe } from "@thi.ng/atom";
440+
423441
db = defAtom({ a: 1, b: { c: 2 } });
424442

425443
// create a view for a's value
@@ -475,6 +493,8 @@ Related, the actual value change predicate can be customized. If not
475493
given, the default `@thi.ng/equiv` will be used.
476494

477495
```ts
496+
import { defAtom, defView } from "@thi.ng/atom";
497+
478498
let x = 0;
479499
let a = defAtom({ value: 1 })
480500

@@ -632,6 +652,8 @@ watches are notified. By default, the history has length of 100 steps,
632652
though this is configurable via ctor args.
633653

634654
```ts
655+
import { defAtom, defHistory } from "@thi.ng/atom";
656+
635657
// create history w/ max. 100 steps
636658
db = defHistory(defAtom({ a: 1 }), 100)
637659
db.deref()

Diff for: packages/atom/tpl.readme.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ values. These updates are handled via immutable setters provided by
131131
[@thi.ng/paths](https://github.com/thi-ng/umbrella/tree/develop/packages/paths).
132132

133133
```ts
134+
import { defAtom } from "@thi.ng/atom";
135+
134136
const db = defAtom({ a: { b: 1, c: 2 } });
135137

136138
// type checked access
@@ -192,6 +194,8 @@ e.g. `Atom`, `Cursor` or `History` instances. `Transacted` also implements
192194
`IAtom` itself...
193195

194196
```ts
197+
import { defAtom, defTransacted } from "@thi.ng/atom";
198+
195199
const db = defAtom<any>({ a: 1, b: 2 });
196200
const tx = defTransacted(db);
197201

@@ -200,7 +204,7 @@ tx.begin();
200204

201205
// alternatively use syntax sugar for:
202206
// `defTransacted(db).begin()`
203-
tx = beginTransaction(db);
207+
// tx = beginTransaction(db);
204208

205209
// perform multiple updates
206210
// (none of them are applied to the parent state
@@ -235,6 +239,10 @@ supported and attempting to do so will throw an error. However, nested
235239
transactions can be achieved by wrapping another `Transacted` container.
236240

237241
```ts
242+
import { beginTransaction } from "@thi.ng/atom";
243+
244+
// (db defined earlier...)
245+
238246
const tx1 = beginTransaction(db);
239247
tx1.resetIn(["a"], 10);
240248

@@ -257,6 +265,10 @@ to signal race conditions due to erroneous / out-of-phase state update
257265
logic.
258266

259267
```ts
268+
import { beginTransaction } from "@thi.ng/atom";
269+
270+
// (db defined earlier...)
271+
260272
const tx = beginTransaction(db);
261273
tx.resetIn(["a"], 10);
262274

@@ -285,6 +297,8 @@ I.e. any change to a cursor's value propagates up the hierarchy of
285297
parent states and also triggers any watches attached to the parent.
286298

287299
```ts
300+
import { defAtom, defCursor } from "@thi.ng/atom";
301+
288302
a = defAtom({a: {b: {c: 1}}})
289303
// cursor to `b` value
290304
b = defCursor(a, "a.b")
@@ -305,6 +319,8 @@ rather wide than deep (my personal limit is 3-4 levels) to minimize the
305319
length of the propagation chain and maximize structural sharing.
306320

307321
```ts
322+
import { defAtom, defCursor, defCursorUnsafe } from "@thi.ng/atom";
323+
308324
// main state
309325
main = defAtom({ a: { b: { c: 23 }, d: { e: 42 } }, f: 66 });
310326

@@ -335,6 +351,8 @@ and the ability to (optionally) produce transformed versions of such a
335351
value. The `View` type provides exactly this functionality:
336352

337353
```ts
354+
import { defAtom, defView, defViewUnsafe } from "@thi.ng/atom";
355+
338356
db = defAtom({ a: 1, b: { c: 2 } });
339357

340358
// create a view for a's value
@@ -390,6 +408,8 @@ Related, the actual value change predicate can be customized. If not
390408
given, the default `@thi.ng/equiv` will be used.
391409

392410
```ts
411+
import { defAtom, defView } from "@thi.ng/atom";
412+
393413
let x = 0;
394414
let a = defAtom({ value: 1 })
395415

@@ -547,6 +567,8 @@ watches are notified. By default, the history has length of 100 steps,
547567
though this is configurable via ctor args.
548568

549569
```ts
570+
import { defAtom, defHistory } from "@thi.ng/atom";
571+
550572
// create history w/ max. 100 steps
551573
db = defHistory(defAtom({ a: 1 }), 100)
552574
db.deref()

Diff for: packages/defmulti/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ causes issues to people, parents could be implemented as sorted list
144144
impact... please open an issue if you run into problems!
145145

146146
```ts
147+
import { defmulti } from "@thi.ng/defmulti";
148+
147149
const foo = defmulti((x) => x);
148150
foo.isa(23, "odd");
149151
foo.isa(42, "even");
@@ -174,6 +176,8 @@ foo.callable(1) // false
174176
Same example, but with relationships provided as argument to `defmulti`:
175177

176178
```ts
179+
import { defmulti } from "@thi.ng/defmulti";
180+
177181
const foo = defmulti((x) => x, {
178182
23: "odd",
179183
42: "even",
@@ -204,6 +208,8 @@ The remaining implementations are associated with their related
204208
multi-method and the given `type` dispatch value.
205209

206210
```ts
211+
import { defmulti, implementations } from "@thi.ng/defmulti";
212+
207213
foo = defmulti((x) => x.id);
208214
bar = defmulti((x) => x.id);
209215
bax = defmulti((x) => x.id);
@@ -257,6 +263,8 @@ throws an `IllegalArityError` when invoked.
257263
however you can specify the return type for the generated function.
258264

259265
```ts
266+
import { defmultiN } from "@thi.ng/defmulti";
267+
260268
const foo = defmultiN<string>({
261269
0: () => "zero",
262270
1: (x) => `one: ${x}`,
@@ -306,6 +314,8 @@ for a variation of this example.
306314
#### Dynamic dispatch: Simple S-expression interpreter
307315

308316
```ts
317+
import { defmulti, DEFAULT } from "@thi.ng/defmulti";
318+
309319
const exec = defmulti((x) => Array.isArray(x) ? x[0] : typeof x);
310320
exec.add("+", ([_, ...args]) => args.reduce((acc, n) => acc + exec(n), 0));
311321
exec.add("*", ([_, ...args]) => args.reduce((acc, n) => acc * exec(n), 1));
@@ -320,6 +330,8 @@ exec(["+", ["*", 10, ["+", 1, 2, 3]], 6]);
320330
#### True multiple arg dispatch
321331

322332
```ts
333+
import { defmulti, DEFAULT } from "@thi.ng/defmulti";
334+
323335
// interest rate calculator based on account type & balance thresholds
324336
const apr = defmulti(
325337
({type, balance}) =>
@@ -354,6 +366,7 @@ graph](https://github.com/thi-ng/umbrella/tree/develop/packages/dgraph), which
354366
then can also be visualized.
355367

356368
```ts
369+
import { defmulti } from "@thi.ng/defmulti";
357370
import { defDGraph } from "@thi.ng/dgraph";
358371
import { toDot } from "@thi.ng/dgraph-dot";
359372

Diff for: packages/defmulti/tpl.readme.md

+13
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ causes issues to people, parents could be implemented as sorted list
8787
impact... please open an issue if you run into problems!
8888

8989
```ts
90+
import { defmulti } from "@thi.ng/defmulti";
91+
9092
const foo = defmulti((x) => x);
9193
foo.isa(23, "odd");
9294
foo.isa(42, "even");
@@ -117,6 +119,8 @@ foo.callable(1) // false
117119
Same example, but with relationships provided as argument to `defmulti`:
118120

119121
```ts
122+
import { defmulti } from "@thi.ng/defmulti";
123+
120124
const foo = defmulti((x) => x, {
121125
23: "odd",
122126
42: "even",
@@ -147,6 +151,8 @@ The remaining implementations are associated with their related
147151
multi-method and the given `type` dispatch value.
148152

149153
```ts
154+
import { defmulti, implementations } from "@thi.ng/defmulti";
155+
150156
foo = defmulti((x) => x.id);
151157
bar = defmulti((x) => x.id);
152158
bax = defmulti((x) => x.id);
@@ -200,6 +206,8 @@ throws an `IllegalArityError` when invoked.
200206
however you can specify the return type for the generated function.
201207

202208
```ts
209+
import { defmultiN } from "@thi.ng/defmulti";
210+
203211
const foo = defmultiN<string>({
204212
0: () => "zero",
205213
1: (x) => `one: ${x}`,
@@ -250,6 +258,8 @@ for a variation of this example.
250258
#### Dynamic dispatch: Simple S-expression interpreter
251259

252260
```ts
261+
import { defmulti, DEFAULT } from "@thi.ng/defmulti";
262+
253263
const exec = defmulti((x) => Array.isArray(x) ? x[0] : typeof x);
254264
exec.add("+", ([_, ...args]) => args.reduce((acc, n) => acc + exec(n), 0));
255265
exec.add("*", ([_, ...args]) => args.reduce((acc, n) => acc * exec(n), 1));
@@ -264,6 +274,8 @@ exec(["+", ["*", 10, ["+", 1, 2, 3]], 6]);
264274
#### True multiple arg dispatch
265275

266276
```ts
277+
import { defmulti, DEFAULT } from "@thi.ng/defmulti";
278+
267279
// interest rate calculator based on account type & balance thresholds
268280
const apr = defmulti(
269281
({type, balance}) =>
@@ -298,6 +310,7 @@ graph](https://github.com/thi-ng/umbrella/tree/develop/packages/dgraph), which
298310
then can also be visualized.
299311

300312
```ts
313+
import { defmulti } from "@thi.ng/defmulti";
301314
import { defDGraph } from "@thi.ng/dgraph";
302315
import { toDot } from "@thi.ng/dgraph-dot";
303316

Diff for: packages/hdom-canvas/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ set to `false` to skip unnecessary diffing and force redraws.
209209
To disable the automatic background clearing of the canvas, set the `__clear` attribute to `false`.
210210

211211
```ts
212+
import { canvas } from "@thi.ng/hdom-components";
213+
212214
[canvas, { width: 100, height: 100, __clear: false }, ...]
213215
```
214216

@@ -220,6 +222,8 @@ context accordingly before any shapes are processed. For fullscreen
220222
canvases simply set the `width` & `height` attribs to:
221223

222224
```ts
225+
import { canvas } from "@thi.ng/hdom-components";
226+
223227
[canvas,
224228
{
225229
width: window.innerWidth,

Diff for: packages/hdom-canvas/tpl.readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ set to `false` to skip unnecessary diffing and force redraws.
129129
To disable the automatic background clearing of the canvas, set the `__clear` attribute to `false`.
130130

131131
```ts
132+
import { canvas } from "@thi.ng/hdom-components";
133+
132134
[canvas, { width: 100, height: 100, __clear: false }, ...]
133135
```
134136

@@ -140,6 +142,8 @@ context accordingly before any shapes are processed. For fullscreen
140142
canvases simply set the `width` & `height` attribs to:
141143

142144
```ts
145+
import { canvas } from "@thi.ng/hdom-components";
146+
143147
[canvas,
144148
{
145149
width: window.innerWidth,

0 commit comments

Comments
 (0)