@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +15 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fruit-ui/core",
3
- "version": "1.2.9",
3
+ "version": "1.3.0",
4
4
  "description": "A vanilla JS toolkit for reactive UI",
5
5
  "main": "src/index.js",
6
6
  "homepage": "https://asantagata.github.io/fruit-ui/",
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 {object} [memo] - The component's memo, if given.
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 {object} [memo] - The element's memoized props, used to control rerendering.
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: typeof component.memo === 'object' ? deepClone(component.memo) : component.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[k] = template.style[k];
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 (let key in template.style) {
436
- element.style[key] = template.style[key];
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 (functional or otherwise) and it is satisfied.
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 the memo exists and is satisfied.
506
+ * @returns {boolean} whether a memo exists and is satisfied.
506
507
  */
507
508
  function evaluateMemo(component) {
508
- if (component.memo && this.memo) {
509
- // for functional memos: rerender if returns false
510
- if (typeof component.memo === 'function') return !!component.memo.call(this);
511
- const equal = deepEqual(component.memo, this.memo);
512
- this.memo = deepClone(component.memo);
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
  }