wallace 0.12.2 → 0.13.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/lib/component.js +15 -19
- package/lib/createComponent.js +2 -2
- package/lib/detacher.js +12 -14
- package/lib/extend.js +2 -2
- package/lib/index.js +0 -1
- package/lib/mount.js +2 -2
- package/lib/nestComponent.js +2 -2
- package/lib/offsetter.js +8 -0
- package/lib/part.js +2 -2
- package/lib/refs.js +1 -3
- package/lib/repeaters/keyed.js +44 -15
- package/lib/repeaters/sequential.js +41 -15
- package/lib/router.js +2 -3
- package/lib/stubs.js +1 -3
- package/lib/types.d.ts +11 -13
- package/package.json +3 -3
- package/lib/repeaters/keyedFn.js +0 -81
package/lib/component.js
CHANGED
|
@@ -16,7 +16,7 @@ const ComponentPrototype = {
|
|
|
16
16
|
|
|
17
17
|
/*
|
|
18
18
|
COMPILER_MODS:
|
|
19
|
-
if useFlags is false this is deleted
|
|
19
|
+
if useFlags is false this is deleted, so `_u` can be renamed to `update`.
|
|
20
20
|
*/
|
|
21
21
|
update: function () {
|
|
22
22
|
this._u(0, this._l);
|
|
@@ -100,7 +100,7 @@ const ComponentBase = {
|
|
|
100
100
|
prototype: ComponentPrototype
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
if (wallaceConfig.flags.
|
|
103
|
+
if (wallaceConfig.flags.allowStubs) {
|
|
104
104
|
ComponentBase.stubs = {};
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -110,7 +110,7 @@ if (wallaceConfig.flags.useStubs) {
|
|
|
110
110
|
* @param {function} BaseComponentFunction - A Component definition function to inherit bits from.
|
|
111
111
|
* @returns the ComponentFunction with bits added.
|
|
112
112
|
*/
|
|
113
|
-
export
|
|
113
|
+
export const initConstructor = (ComponentFunction, BaseComponentFunction) => {
|
|
114
114
|
const proto = (ComponentFunction.prototype = Object.create(
|
|
115
115
|
BaseComponentFunction.prototype,
|
|
116
116
|
{
|
|
@@ -120,59 +120,55 @@ export function initConstructor(ComponentFunction, BaseComponentFunction) {
|
|
|
120
120
|
}
|
|
121
121
|
));
|
|
122
122
|
|
|
123
|
-
if (wallaceConfig.flags.
|
|
123
|
+
if (wallaceConfig.flags.allowMethods) {
|
|
124
124
|
Object.defineProperty(ComponentFunction, "methods", {
|
|
125
|
-
set:
|
|
126
|
-
|
|
127
|
-
},
|
|
128
|
-
get: function () {
|
|
129
|
-
return proto;
|
|
130
|
-
}
|
|
125
|
+
set: value => Object.assign(proto, value),
|
|
126
|
+
get: () => proto
|
|
131
127
|
});
|
|
132
128
|
} else {
|
|
133
129
|
if (process.env.NODE_ENV !== "production") {
|
|
134
130
|
Object.defineProperty(ComponentFunction, "name", {
|
|
135
131
|
set: function (value) {
|
|
136
132
|
throw new Error(
|
|
137
|
-
'Flag "
|
|
133
|
+
'Flag "allowMethods" must be set to true in the config for this feature.'
|
|
138
134
|
);
|
|
139
135
|
},
|
|
140
136
|
get: function () {
|
|
141
137
|
throw new Error(
|
|
142
|
-
'Flag "
|
|
138
|
+
'Flag "allowMethods" must be set to true in the config for this feature.'
|
|
143
139
|
);
|
|
144
140
|
}
|
|
145
141
|
});
|
|
146
142
|
}
|
|
147
143
|
}
|
|
148
144
|
|
|
149
|
-
if (wallaceConfig.flags.
|
|
145
|
+
if (wallaceConfig.flags.allowStubs) {
|
|
150
146
|
ComponentFunction.stubs = Object.assign({}, BaseComponentFunction.stubs);
|
|
151
147
|
}
|
|
152
148
|
|
|
153
149
|
return ComponentFunction;
|
|
154
|
-
}
|
|
150
|
+
};
|
|
155
151
|
|
|
156
|
-
export
|
|
152
|
+
export const defineComponent = (html, watches, queries, contructor, inheritFrom) => {
|
|
157
153
|
const ComponentDefinition = initConstructor(contructor, inheritFrom || ComponentBase);
|
|
158
154
|
const proto = ComponentDefinition.prototype;
|
|
159
155
|
throwAway.innerHTML = html;
|
|
160
156
|
proto._w = watches;
|
|
161
157
|
proto._q = queries;
|
|
162
158
|
proto._t = throwAway.content.firstChild;
|
|
163
|
-
if (wallaceConfig.flags.
|
|
159
|
+
if (wallaceConfig.flags.allowBase) {
|
|
164
160
|
proto.base = ComponentPrototype;
|
|
165
161
|
} else {
|
|
166
162
|
if (process.env.NODE_ENV !== "production") {
|
|
167
163
|
Object.defineProperty(proto, "base", {
|
|
168
164
|
set: function (value) {
|
|
169
165
|
throw new Error(
|
|
170
|
-
'Flag "
|
|
166
|
+
'Flag "allowBase" must be set to true in the config for this feature.'
|
|
171
167
|
);
|
|
172
168
|
},
|
|
173
169
|
get: function () {
|
|
174
170
|
throw new Error(
|
|
175
|
-
'Flag "
|
|
171
|
+
'Flag "allowBase" must be set to true in the config for this feature.'
|
|
176
172
|
);
|
|
177
173
|
}
|
|
178
174
|
});
|
|
@@ -180,4 +176,4 @@ export function defineComponent(html, watches, queries, contructor, inheritFrom)
|
|
|
180
176
|
}
|
|
181
177
|
|
|
182
178
|
return ComponentDefinition;
|
|
183
|
-
}
|
|
179
|
+
};
|
package/lib/createComponent.js
CHANGED
package/lib/detacher.js
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
+
import { countOffset } from "./offsetter";
|
|
1
2
|
/**
|
|
2
3
|
* Deals with conditionally detaching elements with the if directive.
|
|
3
4
|
*/
|
|
4
5
|
export function Detacher(i, e, s) {
|
|
5
6
|
this.i = i; // the initial element index.
|
|
6
|
-
this.e = e; // the
|
|
7
|
-
this.s = s; // the
|
|
7
|
+
this.e = e; // the parent element key.
|
|
8
|
+
this.s = s; // the stash key of the map of detached nodes.
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
Detacher.prototype.apply = function (element, shouldBeVisible, elements, stash) {
|
|
11
12
|
let adjustedIndex;
|
|
12
13
|
const index = this.i,
|
|
13
14
|
parent = elements[this.e],
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (shouldBeVisible &&
|
|
17
|
-
adjustedIndex =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}).length;
|
|
22
|
-
parent.insertBefore(detachedElement, parent.childNodes[adjustedIndex]);
|
|
23
|
-
detachedElements[index] = null;
|
|
24
|
-
} else if (!shouldBeVisible && !detachedElement) {
|
|
15
|
+
detachedElementCache = stash[this.s];
|
|
16
|
+
let offset = detachedElementCache.get(index) || 0;
|
|
17
|
+
if (shouldBeVisible && offset === -1) {
|
|
18
|
+
adjustedIndex = countOffset(detachedElementCache, index);
|
|
19
|
+
parent.insertBefore(element, parent.childNodes[adjustedIndex]);
|
|
20
|
+
offset = 0;
|
|
21
|
+
} else if (!shouldBeVisible && offset === 0) {
|
|
25
22
|
parent.removeChild(element);
|
|
26
|
-
|
|
23
|
+
offset = -1;
|
|
27
24
|
}
|
|
25
|
+
detachedElementCache.set(index, offset);
|
|
28
26
|
};
|
package/lib/extend.js
CHANGED
|
@@ -11,7 +11,7 @@ import { initConstructor } from "./component";
|
|
|
11
11
|
*
|
|
12
12
|
* So it should never be called with 2nd arg in real life.
|
|
13
13
|
*/
|
|
14
|
-
export
|
|
14
|
+
export const extendComponent = (base, componentDef) => {
|
|
15
15
|
// This function call will have been replaced if 2nd arg is a valid component func.
|
|
16
16
|
// and therefore we would not receive it.
|
|
17
17
|
if (componentDef)
|
|
@@ -19,4 +19,4 @@ export function extendComponent(base, componentDef) {
|
|
|
19
19
|
return initConstructor(function () {
|
|
20
20
|
base.call(this);
|
|
21
21
|
}, base);
|
|
22
|
-
}
|
|
22
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -7,7 +7,6 @@ export { nestComponent } from "./nestComponent";
|
|
|
7
7
|
export { saveRef } from "./refs";
|
|
8
8
|
export { savePart } from "./part";
|
|
9
9
|
export { KeyedRepeater } from "./repeaters/keyed";
|
|
10
|
-
export { KeyedFnRepeater } from "./repeaters/keyedFn";
|
|
11
10
|
export { SequentialRepeater } from "./repeaters/sequential";
|
|
12
11
|
export { Router, route } from "./router";
|
|
13
12
|
export { getStub } from "./stubs";
|
package/lib/mount.js
CHANGED
|
@@ -7,11 +7,11 @@ import { replaceNode } from "./utils";
|
|
|
7
7
|
* @param {callable} componentDefinition The class of Component to create
|
|
8
8
|
* @param {object} props The props to pass to the component (optional)
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export const mount = (elementOrId, componentDefinition, props, ctrl) => {
|
|
11
11
|
const component = new componentDefinition();
|
|
12
12
|
component.render(props, ctrl);
|
|
13
13
|
const element =
|
|
14
14
|
typeof elementOrId === "string" ? document.getElementById(elementOrId) : elementOrId;
|
|
15
15
|
replaceNode(element, component.el);
|
|
16
16
|
return component;
|
|
17
|
-
}
|
|
17
|
+
};
|
package/lib/nestComponent.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { findElement, replaceNode } from "./utils";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export const nestComponent = (rootElement, path, componentDefinition) => {
|
|
4
4
|
const el = findElement(rootElement, path),
|
|
5
5
|
child = new componentDefinition();
|
|
6
6
|
replaceNode(el, child.el);
|
|
7
7
|
return child;
|
|
8
|
-
}
|
|
8
|
+
};
|
package/lib/offsetter.js
ADDED
package/lib/part.js
CHANGED
|
@@ -11,7 +11,7 @@ Part.prototype.update = function () {
|
|
|
11
11
|
/**
|
|
12
12
|
* Saves a reference to a part of a component so it can be updated independently.
|
|
13
13
|
*/
|
|
14
|
-
export
|
|
14
|
+
export const savePart = (node, component, parts, name, start, end) => {
|
|
15
15
|
parts[name] = new Part(component, start, end);
|
|
16
16
|
return node;
|
|
17
|
-
}
|
|
17
|
+
};
|
package/lib/refs.js
CHANGED
package/lib/repeaters/keyed.js
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
import { countOffset } from "../offsetter";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Repeats nested components, reusing items based on key.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* COMPILER_MODS:
|
|
7
|
+
* if allowRepeaterSiblings is false the last two parameters are removed.
|
|
8
8
|
*/
|
|
9
|
-
export function KeyedRepeater(componentDefinition,
|
|
9
|
+
export function KeyedRepeater(componentDefinition, key, adjustmentTracker, initialIndex) {
|
|
10
10
|
this.def = componentDefinition;
|
|
11
|
-
|
|
11
|
+
if (wallaceConfig.flags.allowRepeaterSiblings) {
|
|
12
|
+
this.at = adjustmentTracker;
|
|
13
|
+
this.ii = initialIndex;
|
|
14
|
+
}
|
|
12
15
|
this.keys = []; // array of keys as last set.
|
|
13
16
|
this.pool = {}; // pool of component instances.
|
|
17
|
+
if (typeof key === "function") {
|
|
18
|
+
this.kf = key;
|
|
19
|
+
} else {
|
|
20
|
+
this.kn = key;
|
|
21
|
+
}
|
|
14
22
|
}
|
|
15
23
|
|
|
16
24
|
/**
|
|
@@ -24,18 +32,24 @@ export function KeyedRepeater(componentDefinition, keyName) {
|
|
|
24
32
|
KeyedRepeater.prototype.patch = function (e, items, ctrl) {
|
|
25
33
|
const pool = this.pool,
|
|
26
34
|
componentDefinition = this.def,
|
|
27
|
-
keyName = this.
|
|
35
|
+
keyName = this.kn,
|
|
36
|
+
keyFn = this.kf,
|
|
28
37
|
childNodes = e.childNodes,
|
|
29
38
|
itemsLength = items.length,
|
|
30
39
|
previousKeys = this.keys,
|
|
31
40
|
previousKeysLength = previousKeys.length,
|
|
32
41
|
newKeys = [],
|
|
33
42
|
previousKeysSet = new Set(previousKeys),
|
|
43
|
+
adjustmentTracker = this.at,
|
|
44
|
+
initialIndex = this.ii,
|
|
34
45
|
frag = document.createDocumentFragment();
|
|
46
|
+
|
|
35
47
|
let item,
|
|
36
48
|
el,
|
|
37
|
-
|
|
49
|
+
itemKey,
|
|
38
50
|
component,
|
|
51
|
+
endAnchor = null,
|
|
52
|
+
adjustment = 0,
|
|
39
53
|
anchor = null,
|
|
40
54
|
fragAnchor = null,
|
|
41
55
|
untouched = true,
|
|
@@ -43,39 +57,54 @@ KeyedRepeater.prototype.patch = function (e, items, ctrl) {
|
|
|
43
57
|
offset = previousKeysLength - itemsLength,
|
|
44
58
|
i = itemsLength - 1;
|
|
45
59
|
|
|
60
|
+
if (wallaceConfig.flags.allowRepeaterSiblings) {
|
|
61
|
+
if (adjustmentTracker) {
|
|
62
|
+
adjustment = countOffset(adjustmentTracker, initialIndex);
|
|
63
|
+
endAnchor = childNodes[previousKeysLength + adjustment] || null;
|
|
64
|
+
anchor = endAnchor;
|
|
65
|
+
untouched = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
46
69
|
// Working backwards saves us having to track moves.
|
|
47
70
|
while (i >= 0) {
|
|
48
71
|
item = items[i];
|
|
49
|
-
|
|
50
|
-
component = pool[
|
|
72
|
+
itemKey = keyName ? item[keyName] : keyFn(item);
|
|
73
|
+
component = pool[itemKey] || (pool[itemKey] = new componentDefinition());
|
|
51
74
|
component.render(item, ctrl);
|
|
52
75
|
el = component.el;
|
|
53
|
-
if (untouched && !previousKeysSet.has(
|
|
76
|
+
if (untouched && !previousKeysSet.has(itemKey)) {
|
|
54
77
|
frag.insertBefore(el, fragAnchor);
|
|
55
78
|
fragAnchor = el;
|
|
56
79
|
append = true;
|
|
57
80
|
offset++;
|
|
58
81
|
} else {
|
|
59
|
-
if (
|
|
82
|
+
if (itemKey !== previousKeys[i + offset]) {
|
|
60
83
|
e.insertBefore(el, anchor);
|
|
61
84
|
untouched = false;
|
|
62
85
|
}
|
|
63
86
|
anchor = el;
|
|
64
87
|
}
|
|
65
|
-
newKeys.push(
|
|
66
|
-
previousKeysSet.delete(
|
|
88
|
+
newKeys.push(itemKey);
|
|
89
|
+
previousKeysSet.delete(itemKey);
|
|
67
90
|
i--;
|
|
68
91
|
}
|
|
69
92
|
|
|
70
93
|
if (append) {
|
|
71
|
-
e.
|
|
94
|
+
e.insertBefore(frag, endAnchor);
|
|
72
95
|
}
|
|
73
96
|
|
|
74
97
|
let toStrip = previousKeysSet.size;
|
|
75
98
|
while (toStrip > 0) {
|
|
76
|
-
e.removeChild(childNodes[
|
|
99
|
+
e.removeChild(childNodes[adjustment]);
|
|
77
100
|
toStrip--;
|
|
78
101
|
}
|
|
79
102
|
|
|
80
103
|
this.keys = newKeys.reverse();
|
|
104
|
+
|
|
105
|
+
if (wallaceConfig.flags.allowRepeaterSiblings) {
|
|
106
|
+
if (adjustmentTracker) {
|
|
107
|
+
adjustmentTracker.set(initialIndex, itemsLength - 1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
81
110
|
};
|
|
@@ -1,32 +1,52 @@
|
|
|
1
|
+
import { countOffset } from "../offsetter";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* Repeats nested components, yielding from
|
|
4
|
+
* Repeats nested components, yielding from the pool sequentially.
|
|
3
5
|
*
|
|
4
|
-
*
|
|
6
|
+
* COMPILER_MODS:
|
|
7
|
+
* if allowRepeaterSiblings is false the last two parameters are removed.
|
|
5
8
|
*/
|
|
6
|
-
export function SequentialRepeater(componentDefinition) {
|
|
9
|
+
export function SequentialRepeater(componentDefinition, adjustmentTracker, initialIndex) {
|
|
7
10
|
this.def = componentDefinition;
|
|
11
|
+
if (wallaceConfig.flags.allowRepeaterSiblings) {
|
|
12
|
+
this.at = adjustmentTracker;
|
|
13
|
+
this.ii = initialIndex;
|
|
14
|
+
}
|
|
8
15
|
this.pool = []; // pool of component instances
|
|
9
|
-
this.
|
|
16
|
+
this.cc = 0; // Child count
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
/**
|
|
13
20
|
* Updates the element's childNodes to match the items.
|
|
14
21
|
* Performance is important.
|
|
15
22
|
*
|
|
16
|
-
* @param {DOMElement}
|
|
23
|
+
* @param {DOMElement} parent - The DOM element to patch.
|
|
17
24
|
* @param {Array} items - Array of items which will be passed as props.
|
|
18
25
|
* @param {any} ctrl - The parent item's controller.
|
|
19
26
|
*/
|
|
20
|
-
SequentialRepeater.prototype.patch = function (
|
|
27
|
+
SequentialRepeater.prototype.patch = function (parent, items, ctrl) {
|
|
21
28
|
const pool = this.pool,
|
|
22
29
|
componentDefinition = this.def,
|
|
23
|
-
childNodes =
|
|
30
|
+
childNodes = parent.childNodes,
|
|
24
31
|
itemsLength = items.length,
|
|
25
|
-
|
|
32
|
+
previousChildCount = this.cc,
|
|
33
|
+
initialIndex = this.ii,
|
|
34
|
+
adjustmentTracker = this.at;
|
|
26
35
|
let i = 0,
|
|
36
|
+
offset = 0,
|
|
27
37
|
component,
|
|
38
|
+
nextElement,
|
|
39
|
+
endOfRange = previousChildCount,
|
|
28
40
|
poolCount = pool.length;
|
|
29
41
|
|
|
42
|
+
if (wallaceConfig.flags.allowRepeaterSiblings) {
|
|
43
|
+
if (adjustmentTracker) {
|
|
44
|
+
// The repeat element has siblings
|
|
45
|
+
offset = countOffset(adjustmentTracker, initialIndex);
|
|
46
|
+
endOfRange += offset;
|
|
47
|
+
nextElement = childNodes[endOfRange] || null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
30
50
|
while (i < itemsLength) {
|
|
31
51
|
if (i < poolCount) {
|
|
32
52
|
component = pool[i];
|
|
@@ -36,15 +56,21 @@ SequentialRepeater.prototype.patch = function (e, items, ctrl) {
|
|
|
36
56
|
poolCount++;
|
|
37
57
|
}
|
|
38
58
|
component.render(items[i], ctrl);
|
|
39
|
-
if (i >=
|
|
40
|
-
|
|
59
|
+
if (i >= previousChildCount) {
|
|
60
|
+
parent.insertBefore(component.el, nextElement);
|
|
41
61
|
}
|
|
42
62
|
i++;
|
|
43
63
|
}
|
|
44
|
-
this.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
64
|
+
this.cc = itemsLength;
|
|
65
|
+
|
|
66
|
+
let removeAtIndex = offset + previousChildCount - 1;
|
|
67
|
+
const stopatIndex = offset + itemsLength - 1;
|
|
68
|
+
for (let i = removeAtIndex; i > stopatIndex; i--) {
|
|
69
|
+
parent.removeChild(childNodes[i]);
|
|
70
|
+
}
|
|
71
|
+
if (wallaceConfig.flags.allowRepeaterSiblings) {
|
|
72
|
+
if (adjustmentTracker) {
|
|
73
|
+
adjustmentTracker.set(initialIndex, itemsLength - 1);
|
|
74
|
+
}
|
|
49
75
|
}
|
|
50
76
|
};
|
package/lib/router.js
CHANGED
|
@@ -17,9 +17,8 @@ const converters = {
|
|
|
17
17
|
date: v => new Date(v)
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
}
|
|
20
|
+
export const route = (path, componentDef, converter, cleanup) =>
|
|
21
|
+
new Route(path, componentDef, converter, cleanup);
|
|
23
22
|
|
|
24
23
|
export const Router = () => <div></div>;
|
|
25
24
|
|
package/lib/stubs.js
CHANGED
package/lib/types.d.ts
CHANGED
|
@@ -204,6 +204,7 @@ const TaskList = (tasks) => (
|
|
|
204
204
|
Notes:
|
|
205
205
|
|
|
206
206
|
- You cannot use nest on the root element.
|
|
207
|
+
- You cannot use `if` on a nested element, only `show` and `hide`.
|
|
207
208
|
|
|
208
209
|
## 4. Repeating
|
|
209
210
|
|
|
@@ -239,8 +240,8 @@ const TaskList = (tasks) => (
|
|
|
239
240
|
|
|
240
241
|
Notes:
|
|
241
242
|
|
|
242
|
-
- You cannot repeat on the root element.
|
|
243
|
-
-
|
|
243
|
+
- You cannot use repeat on the root element.
|
|
244
|
+
- You cannot toggle visibility on the repeat element.
|
|
244
245
|
|
|
245
246
|
## 5. Directives
|
|
246
247
|
|
|
@@ -386,9 +387,7 @@ const TaskList: Uses<iTask[]> = (tasks) => (
|
|
|
386
387
|
<div>
|
|
387
388
|
First task:
|
|
388
389
|
<Task.nest props={tasks[0]} />
|
|
389
|
-
<
|
|
390
|
-
<Task.repeat items={tasks.slice(1)} />
|
|
391
|
-
</div>
|
|
390
|
+
<Task.repeat items={tasks.slice(1)} />
|
|
392
391
|
</div>
|
|
393
392
|
);
|
|
394
393
|
|
|
@@ -526,11 +525,11 @@ watchedObj[0] = 'foo'; // throws error.
|
|
|
526
525
|
You can toggle flags in your babel config to disable certain features for cutting edge
|
|
527
526
|
performance and bundle size:
|
|
528
527
|
|
|
529
|
-
1.
|
|
530
|
-
2.
|
|
531
|
-
3.
|
|
532
|
-
4.
|
|
533
|
-
5.
|
|
528
|
+
1. allowBase - enables use of `base` in components.
|
|
529
|
+
2. allowCtrl - enables use of `ctrl` in components.
|
|
530
|
+
3. allowMethods - adds the `methods` helper to components.
|
|
531
|
+
4. allowParts - enables use of parts.
|
|
532
|
+
5. allowStubs - enables the use of stubs.
|
|
534
533
|
|
|
535
534
|
These flags default to true, unless you specify `flags` in the plugin config, in which
|
|
536
535
|
case they default to false and you need to explicitly enable those you want:
|
|
@@ -543,8 +542,8 @@ module.exports = {
|
|
|
543
542
|
"babel-plugin-wallace",
|
|
544
543
|
{
|
|
545
544
|
flags: {
|
|
546
|
-
|
|
547
|
-
|
|
545
|
+
allowCtrl: true,
|
|
546
|
+
allowStubs: false
|
|
548
547
|
},
|
|
549
548
|
}
|
|
550
549
|
],
|
|
@@ -1078,7 +1077,6 @@ declare namespace JSX {
|
|
|
1078
1077
|
* <MyComponent.repeat items={arrayOfProps} key="id"/>
|
|
1079
1078
|
* <MyComponent.repeat items={arrayOfProps} key={(i) => i.id}/>
|
|
1080
1079
|
* ```
|
|
1081
|
-
* Note that repeated components may not have siblings.
|
|
1082
1080
|
*
|
|
1083
1081
|
* Available Wallace directives:
|
|
1084
1082
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wallace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"author": "Andrew Buchan",
|
|
5
5
|
"description": "An insanely small, fast, intuitive and extendable front-end framework",
|
|
6
6
|
"homepage": "https://wallace.js.org",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"test": "jest --clearCache && jest"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"babel-plugin-wallace": "^0.
|
|
18
|
+
"babel-plugin-wallace": "^0.13.0",
|
|
19
19
|
"browserify": "^17.0.1"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "4ee1dce381dcd46dd057f88c198dd5d6f3d257d9"
|
|
22
22
|
}
|
package/lib/repeaters/keyedFn.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// WARNING: Code here is near duplicated in keyedFn.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Repeats nested components, reusing items based on key.
|
|
5
|
-
*
|
|
6
|
-
* @param {function} componentDefinition - The ComponentDefinition to create.
|
|
7
|
-
* @param {function} keyFn - A function which obtains the key.
|
|
8
|
-
*/
|
|
9
|
-
export function KeyedFnRepeater(componentDefinition, keyFn) {
|
|
10
|
-
this.def = componentDefinition;
|
|
11
|
-
this.keyFn = keyFn;
|
|
12
|
-
this.keys = []; // array of keys as last set.
|
|
13
|
-
this.pool = {}; // pool of component instances.
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Updates the element's childNodes to match the items.
|
|
18
|
-
* Performance is important.
|
|
19
|
-
*
|
|
20
|
-
* @param {DOMElement} e - The DOM element to patch.
|
|
21
|
-
* @param {Array} items - Array of items which will be passed as props.
|
|
22
|
-
* @param {any} ctrl - The parent item's controller.
|
|
23
|
-
*/
|
|
24
|
-
KeyedFnRepeater.prototype.patch = function (e, items, ctrl) {
|
|
25
|
-
const pool = this.pool,
|
|
26
|
-
componentDefinition = this.def,
|
|
27
|
-
keyFn = this.keyFn,
|
|
28
|
-
childNodes = e.childNodes,
|
|
29
|
-
itemsLength = items.length,
|
|
30
|
-
previousKeys = this.keys,
|
|
31
|
-
previousKeysLength = previousKeys.length,
|
|
32
|
-
newKeys = [],
|
|
33
|
-
previousKeysSet = new Set(previousKeys),
|
|
34
|
-
frag = document.createDocumentFragment();
|
|
35
|
-
let item,
|
|
36
|
-
el,
|
|
37
|
-
key,
|
|
38
|
-
component,
|
|
39
|
-
anchor = null,
|
|
40
|
-
fragAnchor = null,
|
|
41
|
-
untouched = true,
|
|
42
|
-
append = false,
|
|
43
|
-
offset = previousKeysLength - itemsLength,
|
|
44
|
-
i = itemsLength - 1;
|
|
45
|
-
|
|
46
|
-
// Working backwards saves us having to track moves.
|
|
47
|
-
while (i >= 0) {
|
|
48
|
-
item = items[i];
|
|
49
|
-
key = keyFn(item);
|
|
50
|
-
component = pool[key] || (pool[key] = new componentDefinition());
|
|
51
|
-
component.render(item, ctrl);
|
|
52
|
-
el = component.el;
|
|
53
|
-
if (untouched && !previousKeysSet.has(key)) {
|
|
54
|
-
frag.insertBefore(el, fragAnchor);
|
|
55
|
-
fragAnchor = el;
|
|
56
|
-
append = true;
|
|
57
|
-
offset++;
|
|
58
|
-
} else {
|
|
59
|
-
if (key !== previousKeys[i + offset]) {
|
|
60
|
-
e.insertBefore(el, anchor);
|
|
61
|
-
untouched = false;
|
|
62
|
-
}
|
|
63
|
-
anchor = el;
|
|
64
|
-
}
|
|
65
|
-
newKeys.push(key);
|
|
66
|
-
previousKeysSet.delete(key);
|
|
67
|
-
i--;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (append) {
|
|
71
|
-
e.appendChild(frag);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let toStrip = previousKeysSet.size;
|
|
75
|
-
while (toStrip > 0) {
|
|
76
|
-
e.removeChild(childNodes[0]);
|
|
77
|
-
toStrip--;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
this.keys = newKeys.reverse();
|
|
81
|
-
};
|