Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Side by Side Diff: pkg/template_binding/lib/js/flush.js

Issue 723393003: update to polymer js 0.5.1 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: final tweaks Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. 2 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 * This code may only be used under the BSD style license found at http://polyme r.github.io/LICENSE.txt 3 * This code may only be used under the BSD style license found at http://polyme r.github.io/LICENSE.txt
4 * The complete set of authors may be found at http://polymer.github.io/AUTHORS. txt 4 * The complete set of authors may be found at http://polymer.github.io/AUTHORS. txt
5 * The complete set of contributors may be found at http://polymer.github.io/CON TRIBUTORS.txt 5 * The complete set of contributors may be found at http://polymer.github.io/CON TRIBUTORS.txt
6 * Code distributed by Google as part of the polymer project is also 6 * Code distributed by Google as part of the polymer project is also
7 * subject to an additional IP rights grant found at http://polymer.github.io/PA TENTS.txt 7 * subject to an additional IP rights grant found at http://polymer.github.io/PA TENTS.txt
8 */ 8 */
9 9
10 (function(scope) { 10 (function(scope) {
11 11
12 /**
13 * @class Polymer
14 */
15
16 // imports
17 var endOfMicrotask = scope.endOfMicrotask;
18
19 // logging
20 var log = window.WebComponents ? WebComponents.flags.log : {};
21
12 // inject style sheet 22 // inject style sheet
13 var style = document.createElement('style'); 23 var style = document.createElement('style');
14 style.textContent = 'template {display: none !important;} /* injected by platfor m.js */'; 24 style.textContent = 'template {display: none !important;} /* injected by platfor m.js */';
15 var head = document.querySelector('head'); 25 var head = document.querySelector('head');
16 head.insertBefore(style, head.firstChild); 26 head.insertBefore(style, head.firstChild);
17 27
28
29 /**
30 * Force any pending data changes to be observed before
31 * the next task. Data changes are processed asynchronously but are guaranteed
32 * to be processed, for example, before paintin. This method should rarely be
33 * needed. It does nothing when Object.observe is available;
34 * when Object.observe is not available, Polymer automatically flushes data
35 * changes approximately every 1/10 second.
36 * Therefore, `flush` should only be used when a data mutation should be
37 * observed sooner than this.
38 *
39 * @method flush
40 */
18 // flush (with logging) 41 // flush (with logging)
19 var flushing; 42 var flushing;
20 function flush() { 43 function flush() {
21 if (!flushing) { 44 if (!flushing) {
22 flushing = true; 45 flushing = true;
23 scope.endOfMicrotask(function() { 46 endOfMicrotask(function() {
24 flushing = false; 47 flushing = false;
25 logFlags.data && console.group('Platform.flush()'); 48 log.data && console.group('flush');
26 scope.performMicrotaskCheckpoint(); 49 Platform.performMicrotaskCheckpoint();
27 logFlags.data && console.groupEnd(); 50 log.data && console.groupEnd();
28 }); 51 });
29 } 52 }
30 }; 53 };
31 54
32 // polling dirty checker 55 // polling dirty checker
33 // flush periodically if platform does not have object observe. 56 // flush periodically if platform does not have object observe.
34 if (!Observer.hasObjectObserve) { 57 if (!Observer.hasObjectObserve) {
35 var FLUSH_POLL_INTERVAL = 125; 58 var FLUSH_POLL_INTERVAL = 125;
36 window.addEventListener('WebComponentsReady', function() { 59 window.addEventListener('WebComponentsReady', function() {
37 flush(); 60 flush();
38 scope.flushPoll = setInterval(flush, FLUSH_POLL_INTERVAL); 61 // watch document visiblity to toggle dirty-checking
62 var visibilityHandler = function() {
63 // only flush if the page is visibile
64 if (document.visibilityState === 'hidden') {
65 if (scope.flushPoll) {
66 clearInterval(scope.flushPoll);
67 }
68 } else {
69 scope.flushPoll = setInterval(flush, FLUSH_POLL_INTERVAL);
70 }
71 };
72 if (typeof document.visibilityState === 'string') {
73 document.addEventListener('visibilitychange', visibilityHandler);
74 }
75 visibilityHandler();
39 }); 76 });
40 } else { 77 } else {
41 // make flush a no-op when we have Object.observe 78 // make flush a no-op when we have Object.observe
42 flush = function() {}; 79 flush = function() {};
43 } 80 }
44 81
45 if (window.CustomElements && !CustomElements.useNative) { 82 if (window.CustomElements && !CustomElements.useNative) {
46 var originalImportNode = Document.prototype.importNode; 83 var originalImportNode = Document.prototype.importNode;
47 Document.prototype.importNode = function(node, deep) { 84 Document.prototype.importNode = function(node, deep) {
48 var imported = originalImportNode.call(this, node, deep); 85 var imported = originalImportNode.call(this, node, deep);
49 CustomElements.upgradeAll(imported); 86 CustomElements.upgradeAll(imported);
50 return imported; 87 return imported;
51 } 88 };
52 } 89 }
53 90
54 // exports 91 // exports
55 scope.flush = flush; 92 scope.flush = flush;
93 // bc
94 Platform.flush = flush;
56 95
57 })(window.Platform); 96 })(window.Polymer);
58 97
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698