Skip to content

Commit 3968c84

Browse files
author
Steven Orvell
committed
Improve code formatting.
1 parent 8bcc416 commit 3968c84

File tree

1 file changed

+55
-47
lines changed

1 file changed

+55
-47
lines changed

src/lib/dom-api.html

+55-47
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@
3434
DomApi.prototype = {
3535

3636
flush: function() {
37-
flush();
37+
Polymer.dom.flush();
3838
},
3939

4040
_lazyDistribute: function(host) {
4141
// note: only try to distribute if the root is not clean; this ensures
4242
// we don't distribute before initial distribution
4343
if (host.shadyRoot && host.shadyRoot._distributionClean) {
4444
host.shadyRoot._distributionClean = false;
45-
addDebouncer(host.debounce('_distribute', host._distributeContent));
45+
Polymer.dom.addDebouncer(host.debounce('_distribute',
46+
host._distributeContent));
4647
}
4748
},
4849

@@ -766,54 +767,61 @@
766767
}
767768
};
768769

769-
// flush and debounce exposed as statics on Polymer.dom
770-
var flush = Polymer.dom.flush = function() {
771-
// flush debouncers
772-
for (var i=0; i < flush._debouncers.length; i++) {
773-
flush._debouncers[i].complete();
774-
}
775-
// clear the list of debouncers
776-
if (flush._finishDebouncer) {
777-
flush._finishDebouncer.complete();
778-
}
779-
// again make any pending CE mutations that might trigger debouncer
780-
// additions go...
781-
flush.flushPolyfills();
782-
// flush again if there are now any debouncers to process
783-
if (flush._debouncers.length && flush.guard < flush.MAX) {
784-
flush.guard++;
785-
flush();
786-
} else {
787-
if (flush.guard >= flush.MAX) {
788-
console.warn('Polymer.dom.flush aborted. Flush may not be complete.')
770+
// add flush api...
771+
Polymer.Base.extend(Polymer.dom, {
772+
773+
_flushGuard: 0,
774+
_FLUSH_MAX: 100,
775+
_needsTakeRecords: !Polymer.Settings.useNativeCustomElements,
776+
_debouncers: [],
777+
_finishDebouncer: null,
778+
779+
// flush and debounce exposed as statics on Polymer.dom
780+
flush: function() {
781+
// flush debouncers
782+
for (var i=0; i < this._debouncers.length; i++) {
783+
this._debouncers[i].complete();
784+
}
785+
// clear the list of debouncers
786+
if (this._finishDebouncer) {
787+
this._finishDebouncer.complete();
788+
}
789+
// again make any pending CE mutations that might trigger debouncer
790+
// additions go...
791+
this._flushPolyfills();
792+
// flush again if there are now any debouncers to process
793+
if (this._debouncers.length && this._flushGuard < this._FLUSH_MAX) {
794+
this._flushGuard++;
795+
this.flush();
796+
} else {
797+
if (this._flushGuard >= this._FLUSH_MAX) {
798+
console.warn('Polymer.dom.flush aborted. Flush may not be complete.')
799+
}
800+
this._flushGuard = 0;
789801
}
790-
flush.guard = 0;
791-
}
792-
};
802+
},
793803

794-
flush.guard = 0;
795-
flush.MAX = 100;
796-
flush._needsTakeRecords = !Polymer.Settings.useNativeCustomElements;
797-
// TODO(sorvell): There is currently not a good way
798-
// to process all custom elements mutations under SD polyfill because
799-
// these mutations may be inside shadowRoots.
800-
flush.flushPolyfills = function() {
801-
if (this._needsTakeRecords) {
802-
CustomElements.takeRecords();
804+
// TODO(sorvell): There is currently not a good way
805+
// to process all custom elements mutations under SD polyfill because
806+
// these mutations may be inside shadowRoots.
807+
_flushPolyfills: function() {
808+
if (this._needsTakeRecords) {
809+
CustomElements.takeRecords();
810+
}
811+
},
812+
813+
addDebouncer: function(debouncer) {
814+
this._debouncers.push(debouncer);
815+
// ensure the list of active debouncers is cleared when done.
816+
this._finishDebouncer = Polymer.Debounce(this._finishDebouncer,
817+
Polymer.dom._finishFlush);
818+
},
819+
820+
_finishFlush: function() {
821+
Polymer.dom._debouncers = [];
803822
}
804-
}
805-
flush._debouncers = [];
806-
flush._finishDebouncer;
807-
808-
var addDebouncer = Polymer.dom.addDebouncer = function(debouncer) {
809-
flush._debouncers.push(debouncer);
810-
// ensure the list of active debouncers is cleared when done.
811-
flush._finishDebouncer = Polymer.Debounce(flush._finishDebouncer,
812-
function() {
813-
flush._debouncers = [];
814-
}
815-
);
816-
};
823+
824+
});
817825

818826
function getLightChildren(node) {
819827
var children = node._lightChildren;

0 commit comments

Comments
 (0)