props inheritance: default @{widgetId} to @{widgetId._value}

This commit is contained in:
jean-emmanuel 2018-02-05 15:45:13 +01:00
parent b14263d5c3
commit 058dfd4676
4 changed files with 41 additions and 6 deletions

View file

@ -1,15 +1,17 @@
# Changelog
## 0.23.2
## 0.24.0
- bug fixes
- regression preventing dropdown to display no option selected
- crossfaders display issue on iOS
- restored compatibility options for server-client communications
- prevent client to load multiple sessions simultaneously
- prevent client to load multiple sessions simultaneously
- widgets
- switch: wrap non-array `values` property in an array
- dropdown: wrap non-array `values` property in an array; allow setting value by its key/index; add `sendKey` option;
- property inheritance: added shorthand default to `_value` when no property is specified (`@{widgetId}`); some properties can now be dynamically changed without recreating the widget entirely
- property maths: added support for math expressions everywhere via `#{}`
- input: add glass effect when `editable` is `false`
## 0.23.1

View file

@ -22,6 +22,8 @@ If the retreived property is an object (`[] / {}`), a subset can be defined by a
The special property name `_value`<i class="md-icon">flash_on</i> refers to a widget's value, as opposed to its `value` property.
When omitted, the property name defaults to `_value` : `@{widgetId}` => `@{widgetId._value}`
## Dynamic properties
Some properties, when changed, trigger a complete widget recreation that ends any ongoing user interaction. Also, updating these properties continuously (e.g. when linked to a slider's dynamic value) can be very cpu expensive.

View file

@ -0,0 +1,19 @@
# Property maths
The following syntax allow writing mathematical formulas in widgets' properties:
```
#{ FORMULA }
```
Where FORMULA is a valid [MathJS](http://mathjs.org/docs/expressions/syntax.html) expression:
- [syntax documentation](http://mathjs.org/docs/expressions/syntax.html)
- [available functions](http://mathjs.org/docs/reference/functions.html)
- [available constants](http://mathjs.org/docs/reference/constants.html)
- property inheritance calls (`@{...}`) are always resolved before formulas
- arrays / matrices indexes are **zero-based** (ie `['a','b'][0]` returns `'a'`)
Additionnal functions:
- `unpack`: remove an array's brackets (`unpack([1,2])` returns `'1, 2'`)

View file

@ -208,15 +208,27 @@ module.exports = class _widgets_base extends EventEmitter {
if (typeof propValue == 'string') {
propValue = propValue.replace(/@\{([^\}]+)\}/g, (m)=>{
let id = m.substr(2, m.length - 3).split('.'),
k = id.pop(),
subk = undefined
k, subk
if (id.length > 1) {
subk = k
k = id.pop()
subk = undefined
if (id.length > 1) {
subk = k
k = id.pop()
}
id = id.join('.')
} else {
id = id[0]
k = '_value'
}
id = id.join('.')
var widgets = id == 'parent' && this.parent ?
[this.parent] : id == 'this' ? [this] :