Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Mojo.Event relies on the originator of the event being a node/element in an HTML document. From what I can tell there is no built in library for events outside of the DOM context so at this point you'll have to implement your own. Depending on how complex your situation is you may be able to get a way with just creating a property on the object you're listening to and storing a function that get's called a certain time in the future:</p> <pre><code>ListeningObject = Class.create({ initialize:function(){ // instantiate instance of Subject var subject = new Subject(); // set the onEvent property of subject to an instance of this.onEvent bound to // a this instance of Listening object's context. subject.onEvent = this.onEvent.bind(this); subject.doSomethingAwesome(); }, onEvent:function(){ Mojo.Log.info("This get's called from the object we're listening to"); } }); Subject = Class.create({ doSomethingAwesome:function(){ // does stuff, maybe an ajax call or whatever // when it's done you can check if onEvent is a function and then // you can call it, we'll use setTimeout to simulate work being done setTimeout((function(){ if(Object.isFunction(this.onEvent)) this.onEvent(); }).bind(this), 200); }, onEvent:null }); // instantiate an instance of ListeningObject to see it in action var listening_object = new ListeningObject; </code></pre> <p>The biggest limitation to this model is that you can only have one object listening to the particular event but in some situations that's all you need.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload