Skip to content

Commit

Permalink
updated onGet and onSet to wrap global functions as well
Browse files Browse the repository at this point in the history
  • Loading branch information
sal-ortiz committed Aug 7, 2019
1 parent 3655373 commit e3811a4
Showing 1 changed file with 45 additions and 7 deletions.
52 changes: 45 additions & 7 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,62 @@ class ObjectBase extends Object {
this['_op']['handlers'] = {};
}

onGet(key, callback) {
this.initHandlers(key);
onGet(/* ... */) {

if (!Configuration.singleCallbackPerAction) {
this['_op']['handlers'][key]['get'].push(callback);
if (arguments.length > 1) {
// two arguments: a target key and a callback.
let key = arguments[0];
let callback = arguments[1];

return this.setTargetedGetter(key, callback);

} else {
let data = this['_op']['handlers'][key]['get'];
// one argument: just a callback.
let callback = arguments[0];

return this.setGlobalGetter(callback);
}

}

onSet(/* ... */) {

if (arguments.length > 1) {
// two arguments: a target key and a callback.
let key = arguments[0];
let callback = arguments[1];

return this.setTargetedSetter(key, callback);

} else {
// one argument: just a callback.
let callback = arguments[0];

return this.setGlobalSetter(callback);
}

}

setTargetedGetter(key, callback) {
this.initHandlers(key);

if (Configuration.singleCallbackPerAction) {
this['_op']['handlers'][key]['get'] = [callback];

} else {
this['_op']['handlers'][key]['get'].push(callback);

}

}

onSet(key, callback) {
setTargetedSetter(key, callback) {
this.initHandlers(key);

if (!Configuration.singleCallbackPerAction) {
if (Configuration.singleCallbackPerAction) {
this['_op']['handlers'][key]['set'] = [callback];

} else {
this['_op']['handlers'][key]['set'].push(callback);

} else {
Expand Down

0 comments on commit e3811a4

Please sign in to comment.