diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b19b033..84e26ecf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ - add keyboard shortcut to show widget in project tree - selected widget is not showed on top of the others anymore +- widgets + - expose widgets unique identifiers as with property name "uuid" + ## 1.3.0 - bug fixes diff --git a/resources/docs/docs/widgets/advanced-syntaxes.md b/resources/docs/docs/widgets/advanced-syntaxes.md index 6352d26b..75574649 100644 --- a/resources/docs/docs/widgets/advanced-syntaxes.md +++ b/resources/docs/docs/widgets/advanced-syntaxes.md @@ -16,6 +16,10 @@ The property name (and the dot) can be omitted and defaults to `value` (`@{widge A widget can fetch its own properties or its direct parent's by using the keywords `this` or `parent` instead of `id`. When `this` or `parent` can be used, using the target widget's `id` instead won't work. +#### `uuid` + +Each widget has a unique random identifier that can be retreived with the property name `uuid` (e.g. `@{this.uuid}`, `@{parent.uuid}`). + #### 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. diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index f260505b..77c2aadf 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -357,6 +357,7 @@ class Widget extends EventEmitter { // Cache resolved props this.cachedProps = {} + this.cachedProps.uuid = this.hash for (var k in this.props) { if (k != 'widgets' && k != 'tabs') { @@ -567,15 +568,16 @@ class Widget extends EventEmitter { if (widgets[i] === widgetManager) continue - if (widgets[i].props[k] !== undefined || k === 'value') { + if (widgets[i].props[k] !== undefined || k === 'value' || k === 'uuid') { if (k !== 'value' && originalPropName === k && widgets[i] === originalWidget) { return 'ERR_CIRCULAR_REF' } - var r = k == 'value' ? - widgets[i].getValue(true) : - widgets[i].resolveProp(k, undefined, storeLinks, originalWidget, originalPropName) + var r + if (k === 'value') r = widgets[i].getValue(true) + else if (k === 'uuid') r = widgets[i].hash + else r = widgets[i].resolveProp(k, undefined, storeLinks, originalWidget, originalPropName) if (subk !== undefined && r !== undefined) r = r[subk]