solarite 0.2.3 → 0.3.0
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/dist/Solarite-debug.js +1708 -1211
- package/dist/Solarite.js +1642 -1047
- package/dist/Solarite.min.js +2 -2
- package/package.json +1 -1
- package/readme.md +1 -3
- package/src/solarite/ExprPath.js +479 -196
- package/src/solarite/Globals.js +77 -51
- package/src/solarite/HtmlParser.js +91 -0
- package/src/solarite/NodeGroup.js +288 -195
- package/src/solarite/Shell.js +117 -91
- package/src/solarite/Solarite.js +7 -3
- package/src/solarite/Template.js +23 -18
- package/src/solarite/Util.js +117 -179
- package/src/solarite/createSolarite.js +16 -138
- package/src/solarite/getArg.js +31 -16
- package/src/solarite/{r.js → h.js} +56 -18
- package/src/solarite/hash.js +12 -9
- package/src/solarite/watch.js +546 -0
- package/src/util/Errors.js +1 -0
- package/src/util/MultiValueMap.js +73 -13
- package/src/util/Util.js +15 -2
- package/src/util/delve.js +5 -4
- package/src/solarite/watch3.js +0 -98
- package/src/util/WeakArray.js +0 -33
package/src/solarite/watch3.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Trying to be able to automatically watch primitive values.
|
|
3
|
-
* TODO:
|
|
4
|
-
* 1. Have get() return Proxies for nested updates.
|
|
5
|
-
* 2. Override .map() for loops to capture changes.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// Example:
|
|
10
|
-
/*
|
|
11
|
-
class WatchExample extends Solarite {
|
|
12
|
-
|
|
13
|
-
constructor(items = []) {
|
|
14
|
-
super();
|
|
15
|
-
|
|
16
|
-
this.items = items;
|
|
17
|
-
watch(this, 'items');
|
|
18
|
-
|
|
19
|
-
this.name = 'George';
|
|
20
|
-
watch(this, 'name');
|
|
21
|
-
|
|
22
|
-
this.render();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
render() {
|
|
26
|
-
r(this)`
|
|
27
|
-
<watch-example>
|
|
28
|
-
${() => this.name + '!'}
|
|
29
|
-
|
|
30
|
-
${this.items.map(item => r`
|
|
31
|
-
<div>${item.name}</div>
|
|
32
|
-
`)}
|
|
33
|
-
${this.items.length}
|
|
34
|
-
</watch-example>`;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
customElements.define('watch-example', WatchExample);
|
|
38
|
-
|
|
39
|
-
let a = new WatchExample();
|
|
40
|
-
|
|
41
|
-
// Items is a Proxy.
|
|
42
|
-
// Calling push() will trigger the map'd ExprPaths to add another at the end.
|
|
43
|
-
// And the .length expression to update.
|
|
44
|
-
// Because accessing .items returns a proxy.
|
|
45
|
-
a.items.push({name: 'Fred'});
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
import Globals from "./Globals.js";
|
|
50
|
-
import delve from "../util/delve.js";
|
|
51
|
-
//import NodeGroupManager from "./NodeGroupManager.js";
|
|
52
|
-
|
|
53
|
-
let unusedArg = Symbol('unusedArg');
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
*
|
|
57
|
-
* @param root {Object}
|
|
58
|
-
* @param path {string}
|
|
59
|
-
* @param value {string|Symbol} */
|
|
60
|
-
export default function watch3(root, path, value=unusedArg) {
|
|
61
|
-
|
|
62
|
-
/** @type {ExprPath} The ExprPath that's using this variable.*/
|
|
63
|
-
let exprPath;
|
|
64
|
-
|
|
65
|
-
/** @type {function} Function evaluated by the ExprPath. */
|
|
66
|
-
let exprFunction;
|
|
67
|
-
|
|
68
|
-
if (value !== unusedArg)
|
|
69
|
-
root[path] = value;
|
|
70
|
-
|
|
71
|
-
// Store internal value used by get/set.
|
|
72
|
-
else
|
|
73
|
-
value = root[path];
|
|
74
|
-
|
|
75
|
-
Object.defineProperty(root, path, {
|
|
76
|
-
get() {
|
|
77
|
-
// Track which ExprPath is using this variable.
|
|
78
|
-
if (Globals.currentExprPath)
|
|
79
|
-
[exprPath, exprFunction] = Globals.currentExprPath;
|
|
80
|
-
|
|
81
|
-
// TODO: Return Proxy for non-primitive value, to track path changed.
|
|
82
|
-
return value;
|
|
83
|
-
},
|
|
84
|
-
set(val) {
|
|
85
|
-
value = val;
|
|
86
|
-
|
|
87
|
-
if (exprFunction) {
|
|
88
|
-
|
|
89
|
-
// TODO: Will fail for attribute w/ a value having multiple ExprPaths.
|
|
90
|
-
// TODO: This won't update a component's expressions.
|
|
91
|
-
exprPath.apply(exprFunction);
|
|
92
|
-
|
|
93
|
-
exprPath.freeNodeGroups(); // TODO: This could be skipped if applyExprs() never marked them as in-use.
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
package/src/util/WeakArray.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export default class WeakArray {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.items = [];
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
push(...items) {
|
|
7
|
-
for (let item of items) {
|
|
8
|
-
if (typeof item === 'object' && item)
|
|
9
|
-
this.items.push(new WeakRef(item));
|
|
10
|
-
else
|
|
11
|
-
throw new TypeError("Only objects can be added to a WeakArray");
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get(index) {
|
|
16
|
-
const ref = this.items[index];
|
|
17
|
-
if (ref)
|
|
18
|
-
return ref.deref();
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
cleanup() {
|
|
23
|
-
this.items = this.items.filter(ref => ref.deref() !== undefined);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
*[Symbol.iterator]() {
|
|
27
|
-
for (const ref of this.items) {
|
|
28
|
-
const value = ref.deref();
|
|
29
|
-
if (value !== undefined)
|
|
30
|
-
yield value;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|