@thi.ng/rdom 0.10.7 → 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 +1 -1
- package/klist.d.ts +26 -10
- package/klist.js +26 -10
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
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
|
|
12
|
-
* re-initialization of list items if they've been
|
|
13
|
-
* positions due to removal/insertion of other items in
|
|
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
|
|
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
|
-
*
|
|
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
|
|
8
|
-
* re-initialization of list items if they've been
|
|
9
|
-
* positions due to removal/insertion of other items in
|
|
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
|
|
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
|
-
*
|
|
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.
|
|
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,18 +35,18 @@
|
|
|
35
35
|
"test": "testament test"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@thi.ng/api": "^8.7.
|
|
39
|
-
"@thi.ng/checks": "^3.3.
|
|
40
|
-
"@thi.ng/errors": "^2.2.
|
|
41
|
-
"@thi.ng/hiccup": "^4.2.
|
|
42
|
-
"@thi.ng/paths": "^5.1.
|
|
43
|
-
"@thi.ng/prefixes": "^2.1.
|
|
44
|
-
"@thi.ng/rstream": "^7.2.
|
|
45
|
-
"@thi.ng/strings": "^3.3.
|
|
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
48
|
"@microsoft/api-extractor": "^7.34.2",
|
|
49
|
-
"@thi.ng/testament": "^0.3.
|
|
49
|
+
"@thi.ng/testament": "^0.3.11",
|
|
50
50
|
"rimraf": "^4.1.2",
|
|
51
51
|
"tools": "^0.0.1",
|
|
52
52
|
"typedoc": "^0.23.24",
|
|
@@ -140,5 +140,5 @@
|
|
|
140
140
|
"status": "beta",
|
|
141
141
|
"year": 2020
|
|
142
142
|
},
|
|
143
|
-
"gitHead": "
|
|
143
|
+
"gitHead": "cafa4ecea90fb681949dc3885a5bd6ddefa38b51\n"
|
|
144
144
|
}
|