Skip to content

Commit

Permalink
Re-use data change events. Remove unused/undocumented listener object…
Browse files Browse the repository at this point in the history
… specific node listening feature.
  • Loading branch information
Steven Orvell committed Oct 23, 2015
1 parent 2ba08ec commit 8bdedf3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
42 changes: 25 additions & 17 deletions src/lib/bind/accessors.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

Polymer.Bind = {

_dataEventCache: {},

// for prototypes (usually)

prepareModel: function(model) {
Expand All @@ -22,7 +24,17 @@
_modelApi: {

_notifyChange: function(event, value) {
Polymer.Base.fire(event, {value: value}, {bubbles: false, node: this});
var cache = Polymer.Bind._dataEventCache;
var e = cache[event];
if (e) {
cache[event] = null;
} else {
e = new CustomEvent(event,
{bubbles: false, cancelable: false, detail: {}});
}
e.detail.value = value;
this.dispatchEvent(e);
cache[event] = e;
},

// TODO(sjmiles): removing _notifyListener from here breaks accessors.html
Expand Down Expand Up @@ -182,7 +194,7 @@

_addAnnotatedListener: function(model, index, property, path, event) {
var fn = this._notedListenerFactory(property, path,
this._isStructured(path), this._isEventBogus);
this._isStructured(path));
var eventName = event ||
(Polymer.CaseMap.camelToDashCase(property) + '-changed');
model._bindListeners.push({
Expand All @@ -202,27 +214,23 @@
return e.path && e.path[0] !== target;
},

_notedListenerFactory: function(property, path, isStructured, bogusTest) {
return function(e, target) {
if (!bogusTest(e, target)) {
if (e.detail && e.detail.path) {
this._notifyPath(this._fixPath(path, property, e.detail.path),
e.detail.value);
_notedListenerFactory: function(property, path, isStructured) {
return function(target, value, targetPath) {
if (targetPath) {
this._notifyPath(this._fixPath(path, property, targetPath), value);
} else {
value = value !== undefined ? value : target[property];
if (!isStructured) {
this[path] = value;
} else {
var value = target[property];
if (!isStructured) {
this[path] = target[property];
} else {
// TODO(kschaaf): dirty check avoids null references when the object has gone away
if (this.__data__[path] != value) {
this.set(path, value);
}
// TODO(kschaaf): dirty check avoids null references when the object has gone away
if (this.__data__[path] != value) {
this.set(path, value);
}
}
}
};
},

// for instances

prepareInstance: function(inst) {
Expand Down
14 changes: 9 additions & 5 deletions src/standard/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,14 @@
// effects and side effects must not be processed before ready time,
// handling is queue/defered until then.
_notifyListener: function(fn, e) {
if (!this._clientsReadied) {
this._queueHandler([fn, e, e.target]);
} else {
return fn.call(this, e, e.target);
if (!Polymer.Bind._isEventBogus(e, e.target)) {
var value = e.detail.value;
var path = e.detail.path;
if (!this._clientsReadied) {
this._queueHandler([fn, e.target, value, path]);
} else {
return fn.call(this, e.target, value, path);
}
}
},

Expand All @@ -201,7 +205,7 @@
_flushHandlers: function() {
var h$ = this._handlers;
for (var i=0, l=h$.length, h; (i<l) && (h=h$[i]); i++) {
h[0].call(this, h[1], h[2]);
h[0].call(this, h[1], h[2], h[3]);
}
// reset handlers array
//
Expand Down
13 changes: 2 additions & 11 deletions src/standard/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,8 @@
listeners: {},

_listenListeners: function(listeners) {
var node, name, key;
for (key in listeners) {
if (key.indexOf('.') < 0) {
node = this;
name = key;
} else {
name = key.split('.');
node = this.$[name[0]];
name = name[1];
}
this.listen(node, name, listeners[key]);
for (eventName in listeners) {
this.listen(this, eventName, listeners[eventName]);
}
},

Expand Down

0 comments on commit 8bdedf3

Please sign in to comment.