|
34 | 34 | DomApi.prototype = {
|
35 | 35 |
|
36 | 36 | flush: function() {
|
37 |
| - flush(); |
| 37 | + Polymer.dom.flush(); |
38 | 38 | },
|
39 | 39 |
|
40 | 40 | _lazyDistribute: function(host) {
|
41 | 41 | // note: only try to distribute if the root is not clean; this ensures
|
42 | 42 | // we don't distribute before initial distribution
|
43 | 43 | if (host.shadyRoot && host.shadyRoot._distributionClean) {
|
44 | 44 | host.shadyRoot._distributionClean = false;
|
45 |
| - addDebouncer(host.debounce('_distribute', host._distributeContent)); |
| 45 | + Polymer.dom.addDebouncer(host.debounce('_distribute', |
| 46 | + host._distributeContent)); |
46 | 47 | }
|
47 | 48 | },
|
48 | 49 |
|
|
766 | 767 | }
|
767 | 768 | };
|
768 | 769 |
|
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; |
789 | 801 | }
|
790 |
| - flush.guard = 0; |
791 |
| - } |
792 |
| - }; |
| 802 | + }, |
793 | 803 |
|
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 = []; |
803 | 822 | }
|
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 | + }); |
817 | 825 |
|
818 | 826 | function getLightChildren(node) {
|
819 | 827 | var children = node._lightChildren;
|
|
0 commit comments