diff --git a/src/lib/bind/accessors.html b/src/lib/bind/accessors.html
index 4704c2b41e..bb078b3ff1 100644
--- a/src/lib/bind/accessors.html
+++ b/src/lib/bind/accessors.html
@@ -21,17 +21,9 @@
_modelApi: {
_notifyChange: function(event, value) {
- 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;
+ // use a cached event here (_useCache: true) for efficiency
+ this.fire(event, {value: value},
+ {bubbles: false, cancelable: false, _useCache: true});
},
// TODO(sjmiles): removing _notifyListener from here breaks accessors.html
diff --git a/src/standard/notify-path.html b/src/standard/notify-path.html
index 354dc37a00..927f8403d4 100644
--- a/src/standard/notify-path.html
+++ b/src/standard/notify-path.html
@@ -380,10 +380,11 @@
var rootName = this._modelForPath(path);
var dashCaseName = Polymer.CaseMap.camelToDashCase(rootName);
var eventName = dashCaseName + this._EVENT_CHANGED;
+ // use a cached event here (_useCache: true) for efficiency
this.fire(eventName, {
path: path,
value: value
- }, {bubbles: false});
+ }, {bubbles: false, _useCache: true});
},
_modelForPath: function(path) {
@@ -602,6 +603,8 @@
prepareModelNotifyPath: function(model) {
this.mixin(model, {
fire: Polymer.Base.fire,
+ _getEvent: Polymer.Base._getEvent,
+ __eventCache: Polymer.Base.__eventCache,
notifyPath: Polymer.Base.notifyPath,
_get: Polymer.Base._get,
_EVENT_CHANGED: Polymer.Base._EVENT_CHANGED,
diff --git a/src/standard/utils.html b/src/standard/utils.html
index f4241f4fb0..93c5368254 100644
--- a/src/standard/utils.html
+++ b/src/standard/utils.html
@@ -198,6 +198,7 @@
});
},
+
/**
* Dispatches a custom event with an optional detail value.
*
@@ -214,18 +215,37 @@
fire: function(type, detail, options) {
options = options || Polymer.nob;
var node = options.node || this;
- var detail = (detail === null || detail === undefined) ? Polymer.nob : detail;
+ var detail = (detail === null || detail === undefined) ? {} : detail;
var bubbles = options.bubbles === undefined ? true : options.bubbles;
var cancelable = Boolean(options.cancelable);
- var event = new CustomEvent(type, {
- bubbles: Boolean(bubbles),
- cancelable: cancelable,
- detail: detail
- });
+ var useCache = options._useCache;
+ var event = this._getEvent(type, bubbles, cancelable, useCache);
+ event.detail = detail;
+ if (useCache) {
+ this.__eventCache[type] = null;
+ }
node.dispatchEvent(event);
+ if (useCache) {
+ this.__eventCache[type] = event;
+ }
return event;
},
+ __eventCache: {},
+
+ _getEvent: function(type, bubbles, cancelable, useCache) {
+ var event = useCache && this.__eventCache[type];
+ if (!event || ((event.bubbles != bubbles) ||
+ (event.cancelable != cancelable))) {
+ event = new Event(type, {
+ bubbles: Boolean(bubbles),
+ cancelable: cancelable
+ });
+ }
+ return event;
+ },
+
+
/**
* Runs a callback function asyncronously.
*