|
70 | 70 | } |
71 | 71 | }, |
72 | 72 |
|
73 | | - // Intentionally static object |
74 | | - _templatizerStatic: { |
75 | | - count: 0, |
76 | | - callbacks: {}, |
77 | | - debouncer: null |
78 | | - }, |
79 | | - |
80 | 73 | // Extension point for overrides |
81 | 74 | _instanceProps: Polymer.nob, |
82 | 75 |
|
83 | | - created: function() { |
84 | | - // id used for consolidated debouncer |
85 | | - this._templatizerId = this._templatizerStatic.count++; |
86 | | - }, |
| 76 | + _parentPropPrefix: '_parent_', |
87 | 77 |
|
88 | 78 | /** |
89 | 79 | * Prepares a template containing Polymer bindings by generating |
|
162 | 152 | }, |
163 | 153 |
|
164 | 154 | _debounceTemplate: function(fn) { |
165 | | - this._templatizerStatic.callbacks[this._templatizerId] = fn.bind(this); |
166 | | - this._templatizerStatic.debouncer = |
167 | | - Polymer.Debounce(this._templatizerStatic.debouncer, |
168 | | - this._flushTemplates.bind(this, true)); |
| 155 | + Polymer.dom.addDebouncer(this.debounce('_debounceTemplate', fn)); |
169 | 156 | }, |
170 | 157 |
|
171 | 158 | _flushTemplates: function(debouncerExpired) { |
172 | | - var db = this._templatizerStatic.debouncer; |
173 | | - // completely flush any re-queued callbacks resulting from stamping |
174 | | - while (debouncerExpired || (db && db.finish)) { |
175 | | - db.stop(); |
176 | | - var cbs = this._templatizerStatic.callbacks; |
177 | | - this._templatizerStatic.callbacks = {}; |
178 | | - for (var id in cbs) { |
179 | | - cbs[id](); |
180 | | - } |
181 | | - debouncerExpired = false; |
182 | | - } |
| 159 | + Polymer.dom.flush(); |
183 | 160 | }, |
184 | 161 |
|
185 | 162 | _customPrepEffects: function(archetype) { |
|
236 | 213 | // to template instances through abstract _forwardParentProp API |
237 | 214 | // that should be implemented by Templatizer users |
238 | 215 | for (prop in parentProps) { |
239 | | - var parentProp = '_parent_' + prop; |
| 216 | + var parentProp = this._parentPropPrefix + prop; |
240 | 217 | var effects = [{ |
241 | 218 | kind: 'function', |
242 | 219 | effect: this._createForwardPropEffector(prop) |
|
263 | 240 | }, |
264 | 241 |
|
265 | 242 | _createHostPropEffector: function(prop) { |
| 243 | + var prefix = this._parentPropPrefix; |
266 | 244 | return function(source, value) { |
267 | | - this.dataHost['_parent_' + prop] = value; |
| 245 | + this.dataHost[prefix + prop] = value; |
268 | 246 | }; |
269 | 247 | }, |
270 | 248 |
|
|
304 | 282 | // Call extension point for Templatizer sub-classes |
305 | 283 | dataHost._forwardInstancePath.call(dataHost, this, path, value); |
306 | 284 | if (root in dataHost._parentProps) { |
307 | | - dataHost.notifyPath('_parent_' + path, value); |
| 285 | + dataHost.notifyPath(dataHost._parentPropPrefix + path, value); |
308 | 286 | } |
309 | 287 | }, |
310 | 288 |
|
311 | 289 | // Overrides Base notify-path module |
312 | 290 | _pathEffector: function(path, value, fromAbove) { |
313 | 291 | if (this._forwardParentPath) { |
314 | | - if (path.indexOf('_parent_') === 0) { |
| 292 | + if (path.indexOf(this._parentPropPrefix) === 0) { |
315 | 293 | this._forwardParentPath(path.substring(8), value); |
316 | 294 | } |
317 | 295 | } |
318 | 296 | Polymer.Base._pathEffector.apply(this, arguments); |
319 | 297 | }, |
320 | 298 |
|
321 | 299 | _constructorImpl: function(model, host) { |
322 | | - this._rootDataHost = host._getRootDataHost(); |
| 300 | + this._rootDataHost = host._getRootDataHost() || host; |
323 | 301 | this._setupConfigure(model); |
324 | 302 | this._pushHost(host); |
325 | 303 | this.root = this.instanceTemplate(this._template); |
|
391 | 369 | model = model || {}; |
392 | 370 | if (this._parentProps) { |
393 | 371 | for (var prop in this._parentProps) { |
394 | | - model[prop] = this['_parent_' + prop]; |
| 372 | + model[prop] = this[this._parentPropPrefix + prop]; |
395 | 373 | } |
396 | 374 | } |
397 | 375 | return new this.ctor(model, this); |
|
0 commit comments