math props: always stringify to keep object intact and add unpack() function for formatting arrays
This commit is contained in:
parent
1166922f8e
commit
b14263d5c3
2 changed files with 8 additions and 3 deletions
|
|
@ -205,7 +205,7 @@ module.exports = class _widgets_base extends EventEmitter {
|
|||
originalPropName = originalPropName || propName,
|
||||
obj
|
||||
|
||||
if (typeof propValue == 'string' && propValue.indexOf('@{') != -1) {
|
||||
if (typeof propValue == 'string') {
|
||||
propValue = propValue.replace(/@\{([^\}]+)\}/g, (m)=>{
|
||||
let id = m.substr(2, m.length - 3).split('.'),
|
||||
k = id.pop(),
|
||||
|
|
@ -279,8 +279,10 @@ module.exports = class _widgets_base extends EventEmitter {
|
|||
|
||||
try {
|
||||
propValue = propValue.replace(/#\{([^\}]+)\}/g, (m)=>{
|
||||
let expression = m.substr(2, m.length - 3).trim()
|
||||
return math.eval(expression)
|
||||
let expression = m.substr(2, m.length - 3).trim(),
|
||||
r = math.eval(expression)
|
||||
|
||||
return typeof r != 'string' ? JSON.stringify(r) : r
|
||||
})
|
||||
} catch (err) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
var math = require('mathjs/dist/math.min.js').create({
|
||||
matrix: 'Array'
|
||||
})
|
||||
math.import({
|
||||
unpack: function(a) { return Array.isArray(a) ? a.toString() : a }
|
||||
})
|
||||
|
||||
// set math's parser array index base to zero
|
||||
math.expression.mathWithTransform = Object.assign({}, math)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue