@thi.ng/rdom 0.10.6 → 0.10.9

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-01-10T15:20:19Z
3
+ - **Last updated**: 2023-02-10T14:03:10Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/README.md CHANGED
@@ -22,6 +22,8 @@ This project is part of the
22
22
  - [Dependencies](#dependencies)
23
23
  - [Usage examples](#usage-examples)
24
24
  - [API](#api)
25
+ - [Basic usage](#basic-usage)
26
+ - [Lists](#lists)
25
27
  - [Authors](#authors)
26
28
  - [License](#license)
27
29
 
@@ -218,6 +220,8 @@ Currently, documentation only exists in the form of small examples and
218
220
  various doc strings (incomplete). I'm working to alleviate this
219
221
  situation ASAP... In that respect, PRs are welcome as well!
220
222
 
223
+ ### Basic usage
224
+
221
225
  ```ts
222
226
  import { $compile } from "@thi.ng/rdom";
223
227
  import { reactive } from "@thi.ng/rstream";
@@ -242,7 +246,7 @@ $compile([
242
246
  "div",
243
247
  {},
244
248
  // transformed color as title (aka derived view)
245
- ["h1", {}, bg.transform(map((col) => `Hello, ${col}!`))],
249
+ ["h1", {}, bg.map((col) => `Hello, ${col}!`)],
246
250
  [
247
251
  // tag with Emmet-style ID & classes
248
252
  "button#foo.w4.pa3.bn",
@@ -257,6 +261,51 @@ $compile([
257
261
  ]).mount(document.body);
258
262
  ```
259
263
 
264
+ ### Lists
265
+
266
+ See [`$list`](https://docs.thi.ng/umbrella/rdom/functions/_list.html) and
267
+ [`$klist`](https://docs.thi.ng/umbrella/rdom/functions/_klist.html) docs for
268
+ further information...
269
+
270
+ ```ts
271
+ import { $klist } from "@thi.ng/rdom";
272
+ import { reactive } from "@thi.ng/rstream";
273
+
274
+ const items = reactive([
275
+ { id: "a", val: 1 },
276
+ { id: "b", val: 2 },
277
+ { id: "c", val: 3 },
278
+ ]);
279
+
280
+ $klist(
281
+ // reactive data source (any rstream subscribable)
282
+ items,
283
+ // outer list element & attribs
284
+ "ul",
285
+ { class: "list red" },
286
+ // list item component constructor
287
+ (x) => ["li", {}, x.id, ` (${x.val})`],
288
+ // key function (includes)
289
+ (x) => `${x.id}-${x.val}`
290
+ ).mount(document.body);
291
+
292
+ // update list:
293
+ // - item a will be removed
294
+ // - item b is unchanged
295
+ // - item d will be newly inserted
296
+ // - item c will be updated (due to new value)
297
+ setTimeout(
298
+ () => {
299
+ items.next([
300
+ { id: "b", val: 2 },
301
+ { id: "d", val: 4 },
302
+ { id: "c", val: 30 },
303
+ ]);
304
+ },
305
+ 1000
306
+ );
307
+ ```
308
+
260
309
  ## Authors
261
310
 
262
311
  - [Karsten Schmidt](https://thi.ng)
package/klist.d.ts CHANGED
@@ -8,32 +8,48 @@ interface KListItem {
8
8
  }
9
9
  /**
10
10
  * Similar to {@link $list}, however additionally uses keying to establish list
11
- * item identities and uses them in a more complex diffing algorithm to avoid
12
- * re-initialization of list items if they've been re-ordered or changed
13
- * positions due to removal/insertion of other items in the list.
11
+ * item identities and uses these keys (and *only* these!) in a more complex
12
+ * diffing algorithm to avoid re-initialization of list items if they've been
13
+ * re-ordered or changed positions due to removal/insertion of other items in
14
+ * the list.
14
15
  *
15
16
  * @remarks
16
17
  * The given `keyFn` is used to obtain a *unique* key value for each list item
17
- * obtained from the reactive arrays obtained from `src`.
18
+ * obtained from the reactive arrays obtained from `src`. Like a hash, the key
19
+ * value MUST represent an item's *current* value such that if the value
20
+ * changes, so does the key.
18
21
  *
19
22
  * @example
20
23
  * ```ts
21
- * const items = reactive([{id: "a"}, {id: "b"}, {id: "c"}]);
24
+ * const items = reactive([{id: "a", val: 1}, {id: "b", val: 2}, {id: "c", val: 3}]);
22
25
  *
23
26
  * $klist(
24
- * // data source (rstream subsribable)
27
+ * // data source (any rstream subscribable)
25
28
  * items,
26
29
  * // outer list element & attribs
27
30
  * "ul",
28
31
  * { class: "list red" },
29
32
  * // list item component constructor
30
- * (x) => ["li", {}, x.id],
33
+ * (x) => ["li", {}, x.id, ` (${x.val})`],
31
34
  * // key function
32
- * (x) => x.id
35
+ * (x) => `${x.id}-${x.val}`
33
36
  * ).mount(document.body);
34
37
  *
35
- * // update list
36
- * items.next([{id: "b"}, {id: "d"}, {id: "c"}]);
38
+ * // update list:
39
+ * // - item a will be removed
40
+ * // - item b is unchanged
41
+ * // - item d will be newly inserted
42
+ * // - item c will be updated (due to new value)
43
+ * setTimeout(
44
+ * () => {
45
+ * items.next([
46
+ * { id: "b", val: 2 },
47
+ * { id: "d", val: 4 },
48
+ * { id: "c", val: 30 },
49
+ * ]);
50
+ * },
51
+ * 1000
52
+ * );
37
53
  * ```
38
54
  *
39
55
  * @param src -
package/klist.js CHANGED
@@ -4,32 +4,48 @@ import { $moveTo } from "./dom.js";
4
4
  import { $sub } from "./sub.js";
5
5
  /**
6
6
  * Similar to {@link $list}, however additionally uses keying to establish list
7
- * item identities and uses them in a more complex diffing algorithm to avoid
8
- * re-initialization of list items if they've been re-ordered or changed
9
- * positions due to removal/insertion of other items in the list.
7
+ * item identities and uses these keys (and *only* these!) in a more complex
8
+ * diffing algorithm to avoid re-initialization of list items if they've been
9
+ * re-ordered or changed positions due to removal/insertion of other items in
10
+ * the list.
10
11
  *
11
12
  * @remarks
12
13
  * The given `keyFn` is used to obtain a *unique* key value for each list item
13
- * obtained from the reactive arrays obtained from `src`.
14
+ * obtained from the reactive arrays obtained from `src`. Like a hash, the key
15
+ * value MUST represent an item's *current* value such that if the value
16
+ * changes, so does the key.
14
17
  *
15
18
  * @example
16
19
  * ```ts
17
- * const items = reactive([{id: "a"}, {id: "b"}, {id: "c"}]);
20
+ * const items = reactive([{id: "a", val: 1}, {id: "b", val: 2}, {id: "c", val: 3}]);
18
21
  *
19
22
  * $klist(
20
- * // data source (rstream subsribable)
23
+ * // data source (any rstream subscribable)
21
24
  * items,
22
25
  * // outer list element & attribs
23
26
  * "ul",
24
27
  * { class: "list red" },
25
28
  * // list item component constructor
26
- * (x) => ["li", {}, x.id],
29
+ * (x) => ["li", {}, x.id, ` (${x.val})`],
27
30
  * // key function
28
- * (x) => x.id
31
+ * (x) => `${x.id}-${x.val}`
29
32
  * ).mount(document.body);
30
33
  *
31
- * // update list
32
- * items.next([{id: "b"}, {id: "d"}, {id: "c"}]);
34
+ * // update list:
35
+ * // - item a will be removed
36
+ * // - item b is unchanged
37
+ * // - item d will be newly inserted
38
+ * // - item c will be updated (due to new value)
39
+ * setTimeout(
40
+ * () => {
41
+ * items.next([
42
+ * { id: "b", val: 2 },
43
+ * { id: "d", val: 4 },
44
+ * { id: "c", val: 30 },
45
+ * ]);
46
+ * },
47
+ * 1000
48
+ * );
33
49
  * ```
34
50
  *
35
51
  * @param src -
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rdom",
3
- "version": "0.10.6",
3
+ "version": "0.10.9",
4
4
  "description": "Lightweight, reactive, VDOM-less UI/DOM components with async lifecycle and @thi.ng/hiccup compatible",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -35,22 +35,22 @@
35
35
  "test": "testament test"
36
36
  },
37
37
  "dependencies": {
38
- "@thi.ng/api": "^8.6.3",
39
- "@thi.ng/checks": "^3.3.7",
40
- "@thi.ng/errors": "^2.2.8",
41
- "@thi.ng/hiccup": "^4.2.29",
42
- "@thi.ng/paths": "^5.1.28",
43
- "@thi.ng/prefixes": "^2.1.17",
44
- "@thi.ng/rstream": "^7.2.35",
45
- "@thi.ng/strings": "^3.3.23"
38
+ "@thi.ng/api": "^8.7.2",
39
+ "@thi.ng/checks": "^3.3.9",
40
+ "@thi.ng/errors": "^2.2.11",
41
+ "@thi.ng/hiccup": "^4.2.32",
42
+ "@thi.ng/paths": "^5.1.31",
43
+ "@thi.ng/prefixes": "^2.1.19",
44
+ "@thi.ng/rstream": "^7.2.38",
45
+ "@thi.ng/strings": "^3.3.26"
46
46
  },
47
47
  "devDependencies": {
48
- "@microsoft/api-extractor": "^7.33.7",
49
- "@thi.ng/testament": "^0.3.9",
50
- "rimraf": "^3.0.2",
48
+ "@microsoft/api-extractor": "^7.34.2",
49
+ "@thi.ng/testament": "^0.3.11",
50
+ "rimraf": "^4.1.2",
51
51
  "tools": "^0.0.1",
52
- "typedoc": "^0.23.22",
53
- "typescript": "^4.9.4"
52
+ "typedoc": "^0.23.24",
53
+ "typescript": "^4.9.5"
54
54
  },
55
55
  "keywords": [
56
56
  "async",
@@ -140,5 +140,5 @@
140
140
  "status": "beta",
141
141
  "year": 2020
142
142
  },
143
- "gitHead": "3f0b3e2a7c82aefc7e46fb4338369836b5e1b8cf\n"
143
+ "gitHead": "cafa4ecea90fb681949dc3885a5bd6ddefa38b51\n"
144
144
  }