Skip to content

Commit

Permalink
new documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
arieh committed Dec 25, 2011
1 parent e8f9499 commit d849254
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions README.md
Expand Up @@ -20,7 +20,7 @@ The simplest way to enable events support is like this:




function MyObject(){ function MyObject(){
Events.call(this); Events.call(this);
} }




Expand Down Expand Up @@ -58,23 +58,26 @@ Dispathces an event, passing arguments:


###removeEvent(type, fn) ###removeEvent(type, fn)
Removes a listener. Removes a listener.

obj.removeEvent('show', this.bound.handleShow); obj.removeEvent('show', this.bound.handleShow);


###addEventOnce(type, fn) ###addEventOnce(type, fn)
Same as `addEvent` only it will remove the listener automatically once dispatched. Same as `addEvent` only it will remove the listener automatically once dispatched.


##Pseudo events ##Pseudo events
The library supports 2 specific pseudo events: The library supports a few pseudo events out of the box:

1. `:once` - when used event will be added once. 1. `:once` - when used event will be added once.
2. `:latched` - see latched section 2. `:latched` - see latched section

3. `:times(number)` - same as once, only it will execute X times (as passed by parameter).
4. `:delayed(ms)` - on `fireEvent`, will delay X miliseconds before firing the event. On `addEvent` will delay each execution of specific function.


obj.addEvent('test:once', function(){/* ... */ }); obj.addEvent('test:once', function(){/* ... */ });

obj.fireEvent('load:latched'); obj.fireEvent('load:latched');


obj.addEvent('test:times(5)', fn);

You can also add your own pseudo events, by adding them to Events.Pseudoes. You can also add your own pseudo events, by adding them to Events.Pseudoes.
In order to create a new pseudo-event, add an object to the collection, containing either `addEvent` method, `fireEvent` method or both. In order to create a new pseudo-event, add an object to the collection, containing either `addEvent` method, `fireEvent` method or both.
You can even add a parameter to the pseudo-event. You can even add a parameter to the pseudo-event.
Expand All @@ -83,28 +86,26 @@ For example:
Events.Pseudoes.delayed = { Events.Pseudoes.delayed = {
addEvent : function(type, fn, time){ addEvent : function(type, fn, time){
this.addEvent(type, function(){ this.addEvent(type, function(){
setTimeout(fn, time); setTimeout(fn, time);
}); });
} }
}; };


This will allow you to do: This will allow you to do:


obj.addEvent('test:delayed(1000)', fn);//will add a delayed event obj.addEvent('test:delayed(1000)', fn);//will add a delayed event


Some important notes: The `addEvent` and `fireEvent` methods will be fired *instead* of the default methods. It's arguments will be the same as their default, with a third argument, which is the passed pseudo-parameter (if any).
* the `addEvent` method will be fired *instead* of the default `addEvent` method. It's arguments will be `event-type`, the function, and passed parameter (if exists).
* the `fireEvent` method will be fire *after* the default `fireEvent` method. It's arguments will be `event-type` and the event created by the method.


##Latched events ##Latched events
Latched events are events that once fired once will dispatch automatically afterwards. Examples for such events can be Latched events are events that once fired once will dispatch automatically afterwards. Examples for such events can be
a 'load' event, or a 'domready' event. If any arguments were passed, they will be passed on as well. For example: a 'load' event, or a 'domready' event. If any arguments were passed, they will be passed on as well. For example:


obj.fireEvent('load:latched',{someParam:"a"}); obj.fireEvent('load:latched',{someParam:"a"});


//will be fire automatically //will be fire automatically
obj.addEvent('load', function(e){ obj.addEvent('load', function(e){
e.args.someParam; //a e.args.someParam; //a
}); });




Expand Down

0 comments on commit d849254

Please sign in to comment.