@fruit-ui/core 1.2.9 → 1.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/package.json +1 -1
- package/src/index.js +15 -13
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
* @property {object} state - The component's state.
|
|
50
50
|
* @property {object} setState - Functions to set the component's state with automatic reactivity.
|
|
51
51
|
* @property {Object.<string, Binding>} bindings - The component's bindings.
|
|
52
|
-
* @property {
|
|
52
|
+
* @property {*} [memo] - The component's last memo value, if given.
|
|
53
53
|
*/
|
|
54
54
|
|
|
55
55
|
/**
|
|
@@ -66,7 +66,8 @@
|
|
|
66
66
|
* @property {() => Object.<string, any>} [state] - The initializer for local state.
|
|
67
67
|
* @property {string} [key] - The element's key, used to distinguish re-ordered siblings and preserve state.
|
|
68
68
|
* @property {string} [binding] - The element's binding.
|
|
69
|
-
* @property {
|
|
69
|
+
* @property {() => any} [memo] - The element's memo, used to control rerendering.
|
|
70
|
+
* @property {() => boolean} [customMemo] - The element's custom memo, used to control rerendering.
|
|
70
71
|
*/
|
|
71
72
|
|
|
72
73
|
/**
|
|
@@ -119,7 +120,7 @@ function createThis(component) {
|
|
|
119
120
|
state: {},
|
|
120
121
|
setState: {},
|
|
121
122
|
bindings: {},
|
|
122
|
-
memo:
|
|
123
|
+
memo: 'memo' in component ? deepClone(component.memo()) : false
|
|
123
124
|
};
|
|
124
125
|
}
|
|
125
126
|
|
|
@@ -181,7 +182,7 @@ function createElementFromTemplate(template, onMounts, producer = null) {
|
|
|
181
182
|
}
|
|
182
183
|
if (template.style) {
|
|
183
184
|
for (const k in template.style) {
|
|
184
|
-
element.style
|
|
185
|
+
element.style.setProperty(k, template.style[k]);
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
188
|
if (template.on) {
|
|
@@ -432,8 +433,8 @@ function rerenderElementFromTemplate(element, template, onMounts) {
|
|
|
432
433
|
}
|
|
433
434
|
}
|
|
434
435
|
if (template.style) {
|
|
435
|
-
for (
|
|
436
|
-
element.style
|
|
436
|
+
for (const k in template.style) {
|
|
437
|
+
element.style.setProperty(k, template.style[k]);
|
|
437
438
|
}
|
|
438
439
|
}
|
|
439
440
|
if (template.dataset) {
|
|
@@ -499,17 +500,18 @@ function deepClone(value) {
|
|
|
499
500
|
}
|
|
500
501
|
|
|
501
502
|
/**
|
|
502
|
-
* Returns true iff a component has a memo
|
|
503
|
+
* Returns true iff a component has a memo or customMemo and it is satisfied.
|
|
503
504
|
* @param {This} this - the This.
|
|
504
505
|
* @param {Component} component - the Component.
|
|
505
|
-
* @returns {boolean} whether
|
|
506
|
+
* @returns {boolean} whether a memo exists and is satisfied.
|
|
506
507
|
*/
|
|
507
508
|
function evaluateMemo(component) {
|
|
508
|
-
if (component.
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
const
|
|
512
|
-
|
|
509
|
+
if (component.customMemo) {
|
|
510
|
+
return !component.customMemo();
|
|
511
|
+
} else if (component.memo) {
|
|
512
|
+
const componentMemoValue = component.memo();
|
|
513
|
+
const equal = deepEqual(componentMemoValue, this.memo);
|
|
514
|
+
this.memo = deepClone(componentMemoValue);
|
|
513
515
|
return equal;
|
|
514
516
|
} else return false;
|
|
515
517
|
}
|