| Index: pkg/polymer/lib/elements/polymer-signals/polymer-signals.html
|
| diff --git a/pkg/polymer/lib/elements/polymer-signals/polymer-signals.html b/pkg/polymer/lib/elements/polymer-signals/polymer-signals.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3aecf2ffa036069a05656c75b6a7cb3ebfd88830
|
| --- /dev/null
|
| +++ b/pkg/polymer/lib/elements/polymer-signals/polymer-signals.html
|
| @@ -0,0 +1,43 @@
|
| +<!--
|
| +Copyright 2013 The Polymer Authors. All rights reserved.
|
| +Use of this source code is governed by a BSD-style
|
| +license that can be found in the LICENSE file.
|
| +-->
|
| +<link rel="import" href="../polymer/polymer.html">
|
| +
|
| +<polymer-element name="polymer-signals">
|
| + <script>
|
| + (function(){
|
| + Polymer('polymer-signals', {
|
| + enteredView: 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('polymer-signal-' + name, {
|
| + bubbles: true,
|
| + 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('polymer-signal', function(e) {
|
| + notify(e.detail.name, e.detail.data);
|
| + });
|
| + })();
|
| + </script>
|
| +</polymer-element>
|
|
|