From 073bf9e857d5fd3a6bab95987ee8787f42f06356 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Fri, 14 May 2021 00:32:13 +0200 Subject: [PATCH 1/3] matrix: resolve, cache and compare 'props' against all possible values for $ (needs testing) --- src/client/widgets/common/widget.js | 9 ++++---- src/client/widgets/containers/matrix.js | 28 ++++++++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index 37892089..0ffbd91c 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -509,6 +509,11 @@ class Widget extends EventEmitter { jsScope = context || {}, varnumber = 999 + + if (typeof propValue === 'object' && propValue !== null) { + propValue = JSON.stringify(propValue) + } + if (typeof propValue == 'string') { propValue = balancedReplace('@', '{', '}', propValue, (content)=>{ @@ -772,10 +777,6 @@ class Widget extends EventEmitter { } catch (err) {} } - } else if (propValue != null && typeof propValue == 'object') { - for (let k in propValue) { - propValue[k] = this.resolveProp(propName, propValue[k], storeLinks, originalWidget, originalPropName, context) - } } return propValue diff --git a/src/client/widgets/containers/matrix.js b/src/client/widgets/containers/matrix.js index 839b6eb7..4c59d3c1 100644 --- a/src/client/widgets/containers/matrix.js +++ b/src/client/widgets/containers/matrix.js @@ -1,6 +1,6 @@ var Panel = require('./panel'), parser = require('../../parser'), - {deepCopy} = require('../../utils') + {deepCopy, deepEqual} = require('../../utils') class Matrix extends Panel { @@ -64,7 +64,7 @@ class Matrix extends Panel { for (let i = 0; i < this.getProp('quantity'); i++) { - var props = this.resolveProp('props', undefined, false, false, false, {'$':i}) + var props = deepCopy(this.getProp('props')[i]) var data = this.defaultProps(i) if (typeof props === 'object' && props !== null) { @@ -126,7 +126,7 @@ class Matrix extends Panel { for (let i = this.children.length - 1; i >= 0; i--) { - let data = this.resolveProp('props', undefined, false, false, false, {'$': i}) + let data = deepCopy(this.getProp('props')[i]) if (typeof data !== 'object' || data === null || Array.isArray(data)) { data = {} @@ -134,11 +134,11 @@ class Matrix extends Panel { data = JSON.parse(JSON.stringify(data).replace(/(JS|#|OSC|@|VAR)_\{/g, '$1{')) - if (typeof oldPropValue === 'object' && oldPropValue !== null) { + if (typeof oldPropValue[i] === 'object' && oldPropValue[i] !== null) { // if an overridden default props is removed, set it back to default let overriddenDefaults, widgetDefaults - for (var k in oldPropValue) { + for (var k in oldPropValue[i]) { if (data[k] === undefined) { if (Matrix.overriddenDefaults.indexOf(k) !== -1) { overriddenDefaults = overriddenDefaults || this.defaultProps(i) @@ -166,6 +166,24 @@ class Matrix extends Panel { } + resolveProp(propName, propValue, storeLinks, originalWidget, originalPropName, context) { + + if (propName === 'props') { + + var data = [] + for (var i = 0; i < this.getProp('quantity'); i++) { + data[i] = super.resolveProp(propName, propValue, storeLinks, originalWidget, originalPropName, {$: i}) + } + + return data + + } else { + + return super.resolveProp(propName, propValue, storeLinks, originalWidget, originalPropName, context) + + } + + } } From 74ac95bca53dc9d39cb6e1a287ac0617d9541339 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Fri, 14 May 2021 00:33:57 +0200 Subject: [PATCH 2/3] lint --- src/client/widgets/containers/matrix.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/widgets/containers/matrix.js b/src/client/widgets/containers/matrix.js index 4c59d3c1..169285ae 100644 --- a/src/client/widgets/containers/matrix.js +++ b/src/client/widgets/containers/matrix.js @@ -1,6 +1,6 @@ var Panel = require('./panel'), parser = require('../../parser'), - {deepCopy, deepEqual} = require('../../utils') + {deepCopy} = require('../../utils') class Matrix extends Panel { From ae5ee833b1c96130bccc6e33fb328feb0d4f622f Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Fri, 14 May 2021 10:22:27 +0200 Subject: [PATCH 3/3] widgets: reduce scope of commit 073bf9e857d5fd3a6bab95987ee8787f42f06356 --- src/client/widgets/common/widget.js | 9 ++++----- src/client/widgets/containers/matrix.js | 6 ++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index 0ffbd91c..37892089 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -509,11 +509,6 @@ class Widget extends EventEmitter { jsScope = context || {}, varnumber = 999 - - if (typeof propValue === 'object' && propValue !== null) { - propValue = JSON.stringify(propValue) - } - if (typeof propValue == 'string') { propValue = balancedReplace('@', '{', '}', propValue, (content)=>{ @@ -777,6 +772,10 @@ class Widget extends EventEmitter { } catch (err) {} } + } else if (propValue != null && typeof propValue == 'object') { + for (let k in propValue) { + propValue[k] = this.resolveProp(propName, propValue[k], storeLinks, originalWidget, originalPropName, context) + } } return propValue diff --git a/src/client/widgets/containers/matrix.js b/src/client/widgets/containers/matrix.js index 169285ae..4b6fc4f2 100644 --- a/src/client/widgets/containers/matrix.js +++ b/src/client/widgets/containers/matrix.js @@ -170,6 +170,12 @@ class Matrix extends Panel { if (propName === 'props') { + propValue = propValue !== undefined ? propValue : deepCopy(this.props[propName]) + + if (typeof propValue === 'object' && propValue !== null) { + propValue = JSON.stringify(propValue) + } + var data = [] for (var i = 0; i < this.getProp('quantity'); i++) { data[i] = super.resolveProp(propName, propValue, storeLinks, originalWidget, originalPropName, {$: i})