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

Unified Diff: third_party/polymer/components-chromium/core-signals/core-signals-extracted.js

Issue 592593002: Inline scripts were extracted from Polymer elements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/echo ""/echo/ Created 6 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/components-chromium/core-signals/core-signals-extracted.js
diff --git a/third_party/polymer/components-chromium/core-signals/core-signals-extracted.js b/third_party/polymer/components-chromium/core-signals/core-signals-extracted.js
new file mode 100644
index 0000000000000000000000000000000000000000..badea271332d8db1ff93e2fba423c3683eb1ff31
--- /dev/null
+++ b/third_party/polymer/components-chromium/core-signals/core-signals-extracted.js
@@ -0,0 +1,45 @@
+
+(function(){
+
+ Polymer('core-signals',{
+ attached: function() {
+ signals.push(this);
+ },
+ removed: function() {
+ var i = signals.indexOf(this);
+ if (i >= 0) {
+ signals.splice(i, 1);
+ }
+ }
+ });
+
+ // private shared database
+ var signals = [];
+
+ // signal dispatcher
+ function notify(name, data) {
+ // convert generic-signal event to named-signal event
+ var signal = new CustomEvent('core-signal-' + name, {
+ // if signals bubble, it's easy to get confusing duplicates
+ // (1) listen on a container on behalf of local child
+ // (2) some deep child ignores the event and it bubbles
+ // up to said container
+ // (3) local child event bubbles up to container
+ // also, for performance, we avoid signals flying up the
+ // tree from all over the place
+ bubbles: false,
+ detail: data
+ });
+ // dispatch named-signal to all 'signals' instances,
+ // only interested listeners will react
+ signals.forEach(function(s) {
+ s.dispatchEvent(signal);
+ });
+ }
+
+ // signal listener at document
+ document.addEventListener('core-signal', function(e) {
+ notify(e.detail.name, e.detail.data);
+ });
+
+})();

Powered by Google App Engine
This is Rietveld 408576698