wallace 0.0.6 → 0.0.7
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/lib/component.js +72 -18
- package/lib/index.js +2 -2
- package/lib/initCalls.js +7 -11
- package/package.json +3 -3
package/lib/component.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* The base component.
|
|
3
3
|
*/
|
|
4
4
|
export function Component(parent) {
|
|
5
|
-
this.parent = parent; // The parent component
|
|
5
|
+
this.parent = parent; // The parent component. TODO: is this needed?
|
|
6
6
|
this.props = undefined; // The props passed to the component. May be changed.
|
|
7
|
-
this.el = null; // the element - will be set during build
|
|
8
|
-
this.ref = {}; // user set references to elements or components
|
|
7
|
+
this.el = null; // the element - will be set during build.
|
|
8
|
+
this.ref = {}; // user set references to elements or components.
|
|
9
9
|
// Internal state objects
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
10
|
+
this._e = {}; // The dynamic elements in the DOM.
|
|
11
|
+
this._p = {}; // The previous values for watches to compare against.
|
|
12
|
+
this._s = []; // A stash for misc objects.
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
var proto = Component.prototype;
|
|
@@ -36,29 +36,83 @@ proto.update = function () {
|
|
|
36
36
|
let i = 0,
|
|
37
37
|
watch,
|
|
38
38
|
element,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
parent,
|
|
40
|
+
displayToggle,
|
|
41
|
+
detacher,
|
|
42
|
+
lookupReturn,
|
|
43
|
+
lookupTrue,
|
|
44
|
+
shouldBeVisible,
|
|
45
|
+
visibilityChanged,
|
|
46
|
+
detachedElements,
|
|
47
|
+
detachedElement,
|
|
48
|
+
index,
|
|
49
|
+
adjustedIndex,
|
|
50
|
+
thisElement;
|
|
42
51
|
|
|
43
|
-
const watches = this.
|
|
52
|
+
const watches = this._w;
|
|
44
53
|
const lookup = this._l;
|
|
45
54
|
const props = this.props;
|
|
46
55
|
lookup.reset();
|
|
47
56
|
const il = watches.length;
|
|
57
|
+
/*
|
|
58
|
+
Watches is an array of objects with keys:
|
|
59
|
+
e: the element reference (string)
|
|
60
|
+
c: the callbacks (object)
|
|
61
|
+
?v: visibility toggle (object)
|
|
62
|
+
|
|
63
|
+
The display toggle has keys:
|
|
64
|
+
q: the query key in lookup
|
|
65
|
+
s: the number of watches to skip as their node is underneath
|
|
66
|
+
r: reversed
|
|
67
|
+
?d: detacher
|
|
68
|
+
|
|
69
|
+
The detacher has keys:
|
|
70
|
+
i: the initial element index
|
|
71
|
+
s: the stash key of the detacher (plain object)
|
|
72
|
+
e: the parent element key
|
|
73
|
+
*/
|
|
48
74
|
while (i < il) {
|
|
49
75
|
watch = watches[i];
|
|
50
|
-
element = this._e[watch.
|
|
51
|
-
|
|
76
|
+
element = this._e[watch.e];
|
|
77
|
+
displayToggle = watch.v;
|
|
52
78
|
i++;
|
|
53
79
|
shouldBeVisible = true;
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
80
|
+
if (displayToggle) {
|
|
81
|
+
lookupReturn = lookup.get(this, props, displayToggle.q);
|
|
82
|
+
lookupTrue = !!lookupReturn.n;
|
|
83
|
+
shouldBeVisible = displayToggle.r ? lookupTrue : !lookupTrue;
|
|
84
|
+
visibilityChanged = lookupTrue != !!lookupReturn.o;
|
|
85
|
+
detacher = displayToggle.d;
|
|
86
|
+
if (detacher) {
|
|
87
|
+
index = detacher.i;
|
|
88
|
+
parent = this._e[detacher.e];
|
|
89
|
+
detachedElements = this._s[detacher.s];
|
|
90
|
+
detachedElement = detachedElements[index];
|
|
91
|
+
if (shouldBeVisible && detachedElement) {
|
|
92
|
+
adjustedIndex =
|
|
93
|
+
index -
|
|
94
|
+
Object.keys(detachedElements).filter(function (k) {
|
|
95
|
+
return k < index && detachedElements[k];
|
|
96
|
+
}).length;
|
|
97
|
+
parent.insertBefore(
|
|
98
|
+
detachedElement,
|
|
99
|
+
parent.childNodes[adjustedIndex],
|
|
100
|
+
);
|
|
101
|
+
detachedElements[index] = null;
|
|
102
|
+
} else if (!shouldBeVisible && !detachedElement) {
|
|
103
|
+
thisElement = this._e[watch.e];
|
|
104
|
+
parent.removeChild(thisElement);
|
|
105
|
+
detachedElements[index] = thisElement;
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
element.hidden = !shouldBeVisible;
|
|
109
|
+
}
|
|
110
|
+
if (!shouldBeVisible) {
|
|
111
|
+
i += displayToggle.s;
|
|
112
|
+
}
|
|
59
113
|
}
|
|
60
114
|
if (shouldBeVisible) {
|
|
61
|
-
lookup.applyCallbacks(this, props, element, watch.
|
|
115
|
+
lookup.applyCallbacks(this, props, element, watch.c);
|
|
62
116
|
}
|
|
63
117
|
}
|
|
64
118
|
};
|
package/lib/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
nestComponent,
|
|
11
11
|
defineComponent,
|
|
12
12
|
extendPrototype,
|
|
13
|
-
|
|
13
|
+
stashMisc,
|
|
14
14
|
saveRef,
|
|
15
15
|
} from "./initCalls";
|
|
16
16
|
|
|
@@ -28,7 +28,7 @@ export {
|
|
|
28
28
|
mount,
|
|
29
29
|
nestComponent,
|
|
30
30
|
onEvent,
|
|
31
|
-
|
|
31
|
+
stashMisc,
|
|
32
32
|
saveRef,
|
|
33
33
|
SequentialPool,
|
|
34
34
|
};
|
package/lib/initCalls.js
CHANGED
|
@@ -28,7 +28,7 @@ export const nestComponent = (rootElement, path, cls, parent) => {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Saves a reference to element or nested component.
|
|
31
|
+
* Saves a reference to element or nested component. Returns the element.
|
|
32
32
|
*/
|
|
33
33
|
export const saveRef = (element, component, name) => {
|
|
34
34
|
component.ref[name] = element;
|
|
@@ -36,10 +36,11 @@ export const saveRef = (element, component, name) => {
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* Stash something on the component. Returns the element.
|
|
40
|
+
* The generated code is expected to keep track of the position.
|
|
40
41
|
*/
|
|
41
|
-
export const
|
|
42
|
-
component.
|
|
42
|
+
export const stashMisc = (element, component, object) => {
|
|
43
|
+
component._s.push(object);
|
|
43
44
|
return element;
|
|
44
45
|
};
|
|
45
46
|
|
|
@@ -82,13 +83,8 @@ export function extendComponent(
|
|
|
82
83
|
lookups,
|
|
83
84
|
buildFunction,
|
|
84
85
|
) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
sq: arr[1], // The shield query key
|
|
88
|
-
rv: arr[2], // whether shieldQuery should be flipped
|
|
89
|
-
sc: arr[3], // The number of items to shield
|
|
90
|
-
cb: arr[4], // The callbacks - object
|
|
91
|
-
}));
|
|
86
|
+
//Ensure these do not clash with fields on the component itself.
|
|
87
|
+
prototype._w = watches;
|
|
92
88
|
prototype._l = new Lookup(lookups);
|
|
93
89
|
prototype._b = buildFunction;
|
|
94
90
|
prototype._n = makeEl(html);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wallace",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"author": "Andrew Buchan",
|
|
5
5
|
"description": "The framework that brings you glee.",
|
|
6
6
|
"license": "ISC",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"test": "jest --clearCache && jest"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"babel-plugin-wallace": "^0.0.
|
|
16
|
+
"babel-plugin-wallace": "^0.0.7",
|
|
17
17
|
"browserify": "^17.0.1"
|
|
18
18
|
},
|
|
19
|
-
"gitHead": "
|
|
19
|
+
"gitHead": "625563b34b61857f1180da42d4b1f7bc229440c9"
|
|
20
20
|
}
|