Skip to content

Commit

Permalink
sidorares#2 : using __lookupGetter__ and __lookupSetter__ to retrieve…
Browse files Browse the repository at this point in the history
… user-defined getters/setters
  • Loading branch information
Sylvain Mahé committed Dec 29, 2016
1 parent 33f7eb0 commit ad26940
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,18 +683,27 @@ module.exports = function bus(conn, opts) {
let propAccessMode = Object.keys(propObj)[0]
let propType = propObj[propAccessMode]

//get user-defined getter/setters
let propGetter = obj[ifaceName].__lookupGetter__(propName)
let propSetter = obj[ifaceName].__lookupSetter__(propName)

//use default getter/setter if not user-defined
if (!propGetter) {
propGetter = function() { return this['_' + propName] }
}
if (!propSetter) {
propSetter = function(newValue) { this['_' + propName] = newValue }
}

// Copying property in "underscored" field
obj[ifaceName]['_' + propName] = obj[ifaceName][propName]

// Define getters and setters
// TODO: check access mode
Object.defineProperty (obj[ifaceName], propName, {
get: function () {
return this['_' + propName]
},
get: propGetter,
set: function (newValue) {
this['_' + propName] = newValue

propSetter.call(this, newValue)
/*
If the property is readable, emit 'PropertiesChanged' signal to propagate the
change.
Expand Down

0 comments on commit ad26940

Please sign in to comment.