Skip to content

Commit 1c4e0a0

Browse files
committed
live-elements-core: BaseElement, updated property data visibility and exposed propertyBindingInfo function to visualize property bindings..
1 parent e02151f commit 1c4e0a0

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

packages/live-elements-core/baseelement.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class BaseElement{
1919
constructor(){
2020
this.id = ''
2121
this.parent = null
22+
Object.defineProperty(this, '__lv', { enumerable: false, value: {} })
2223
}
2324

2425
setParent(parent){
@@ -59,7 +60,7 @@ export class BaseElement{
5960
}
6061

6162
static assignChildren(element, children){
62-
var propertyName = element['__default__']
63+
const propertyName = element.__lv.__default__
6364
element[propertyName] = children
6465
}
6566

@@ -74,22 +75,19 @@ export class BaseElement{
7475

7576
static propertyNames(element){
7677
let keys = []
77-
for (let [key, value] of Object.entries(element)) {
78-
if ( value && typeof value === 'object' && value.hasOwnProperty('expression') && key.startsWith('__') ){
79-
keys.push(key.substr(2))
80-
}
78+
for (let [key, _value] of Object.entries(element.__lv)) {
79+
if ( key !== '__default__' )
80+
keys.push(key)
8181
}
8282
return keys
8383
}
8484

8585
static getProperty(obj, name){
86-
const propMetaName = '__' + name
87-
return obj[propMetaName].value
86+
return obj.__lv[name].value
8887
}
8988

9089
static setProperty(obj, name, newValue){
91-
const propMetaName = '__' + name
92-
const pm = obj[propMetaName]
90+
const pm = obj.__lv[name]
9391
pm.value = newValue
9492
}
9593

@@ -100,30 +98,28 @@ export class BaseElement{
10098
value: ('value' in options ? options['value'] : undefined)
10199
}
102100

103-
const propMetaName = '__' + propertyName
104-
105101
if ('notify' in options){
106102
propMeta['event'] = BaseElement.addEvent(element, options['notify'], [])
107103
}
108104

109105
const isWritable = 'isWritable' in options ? options['isWritable'] : true
110106
const isDefault = 'type' in options && options['type'] === 'default'
111107

112-
element[propMetaName] = propMeta
108+
element.__lv[propertyName] = propMeta
113109

114110
if ( isDefault ){
115-
element['__default__'] = propertyName
111+
element.__lv.__default__ = propertyName
116112
}
117113

118114
if ( 'set' in options ){
119115
propMeta.setter = options['set'].bind(element)
120116
}
121117

122118
Object.defineProperty(element, propertyName, {
123-
get: 'get' in options ? options['get'] : function(){ return this[propMetaName].value },
119+
get: 'get' in options ? options['get'] : function(){ return this.__lv[propertyName].value },
124120
set: propMeta.setter
125121
? function(newValue){
126-
const pm = this[propMetaName]
122+
const pm = this.__lv[propertyName]
127123
if ( pm.value !== newValue ){
128124
if ( pm.bindings ){
129125
for ( var i = 0; i < pm.bindings.length; ++i ){
@@ -140,7 +136,7 @@ export class BaseElement{
140136
}
141137
}
142138
: function(newValue){
143-
const pm = this[propMetaName]
139+
const pm = this.__lv[propertyName]
144140
if ( pm.value !== newValue ){
145141
if ( pm.bindings ){
146142
for ( var i = 0; i < pm.bindings.length; ++i ){
@@ -202,7 +198,7 @@ export class BaseElement{
202198
var propName = eventBindings[i].eventName
203199
propName = propName.substr(0, propName.lastIndexOf('Changed'))
204200

205-
const objectId = 0
201+
let objectId = 0
206202
const objectIdIndex = objectIds.indexOf(eventBindings[i].emitterObject)
207203
if ( objectIdIndex !== -1 ){
208204
objectId = objectIdIndex
@@ -295,8 +291,12 @@ export class BaseElement{
295291
return result
296292
}
297293

294+
static propertyBindingsInfo(element, propertyName){
295+
return BaseElement.__debugEventBindings(element.__lv[propertyName].bindings)
296+
}
297+
298298
static assignPropertyExpression(element, propertyName, propertyExpression, bindings){
299-
const propMeta = element['__' + propertyName]
299+
const propMeta = element.__lv[propertyName]
300300
propMeta['expression'] = propertyExpression.bind(element)
301301

302302
const previousBindings = propMeta['bindings']

0 commit comments

Comments
 (0)