Skip to content

Commit

Permalink
Release 2.2.0
Browse files Browse the repository at this point in the history
 - export the native window API so native plugins can detect when
   games are listening for events on the window object

   ```
   import devkit.native.Window as nativeWindow;

   nativeWindow.on('newListener', function (type, cb) {
   	 console.log("new native listener for", type);
   });

   window.addEventListener("devicemotion", function () { ... });
   ```
  • Loading branch information
Martin Hunt committed Mar 6, 2015
1 parent 26b855c commit fc14933
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/clientapi/native/Window.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,22 @@
* along with the Game Closure SDK. If not, see <http://mozilla.org/MPL/2.0/>.
*/

"use import";

import lib.PubSub;

var _evts = new lib.PubSub();
module.exports = new lib.PubSub();

window.open = window.open || window.setLocation;

window.addEventListener = function (evtName, cb, isBubble) {
_evts.subscribe(evtName, window, cb);
module.exports.on(evtName, cb);
}

window.removeEventListener = function (evtName, cb, isBubble) {
_evts.unsubscribe(evtName, window, cb);
module.exports.removeListener(evtName, cb);
}

window.__fireEvent = function (name, evt) {
if (!evt) { evt = {}; }
evt.type = name;
_evts.publish(name, evt);
if (!evt) { evt = {}; }
evt.type = name;
module.exports.publish(name, evt);
}

0 comments on commit fc14933

Please sign in to comment.