tdispatcher
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "tdispatcher", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "simple Flux dispatcher, for huge applications", | ||
@@ -5,0 +5,0 @@ "main": "tDispatcher.js", |
@@ -0,3 +1,4 @@ | ||
# tDispatcher | ||
inspired by Facebooks Flux, I made a simpler dispatcher, with a more common API. | ||
Flux-Dispatcher, with common API for huge applications | ||
@@ -19,3 +20,3 @@ So this project is for guys who are interested to use Flux and do it in a simple way, that might be familiar with other eventsystems. | ||
// it can be used as a in backbone event just .on('eventname',callback) | ||
//or better: an object, containing | ||
//or better: an object, containing | ||
{ event:'theEventname', | ||
@@ -26,27 +27,32 @@ name:'nameThatCanBeRequired', | ||
} | ||
2. tDispatcher.off;// to remove eventlistener. .off(), | ||
2. tDispatcher.off;// to remove eventlistener. .off(), | ||
// without params will remove all listener on the Dispatcher | ||
.off(event) | ||
.off(event) | ||
// will remove all listener for that event,(event is a string) | ||
.off(event, name) | ||
.off(event, name) | ||
// the listener with that name | ||
.off(event,callback) | ||
// will the listener with the corresponding | ||
.off(event,callback) | ||
// will the listener with the corresponding | ||
// callback (slow search in a loop) | ||
3. tDispatcher.trigger() // to execute an event. It will pass the action object to the listeners callback | ||
//.trigger(name) | ||
//.trigger(name) | ||
// call it with a string will execute the listener on that eventname | ||
//.trigger(name,value) | ||
//.trigger(name,value) | ||
// will pass add the value to the value-key on the action object. | ||
//.trigger(action) | ||
// an object that need to have an event key, as string, | ||
// describing the event to be executed and all | ||
// other values on other key names, that you want to | ||
//.trigger(action) | ||
// an object that need to have an event key, as string, | ||
// describing the event to be executed and all | ||
// other values on other key names, that you want to | ||
// pass to the listener. | ||
4. tDispatcher.addAction(name) | ||
// name is the name of a new function, that will trigger the event of the same name | ||
``` | ||
##Developer | ||
[Tobias Nickel](http://tnickel.de/) | ||
![alt text](https://avatars1.githubusercontent.com/u/4189801?s=150) | ||
![alt text](https://avatars1.githubusercontent.com/u/4189801?s=150) |
@@ -1,6 +0,1 @@ | ||
// ==ClosureCompiler== | ||
// @output_file_name default.js | ||
// @compilation_level SIMPLE_OPTIMIZATIONS | ||
// ==/ClosureCompiler== | ||
/** | ||
@@ -22,2 +17,3 @@ * @author Tobias Nickel | ||
} | ||
/** | ||
@@ -45,6 +41,9 @@ * method that you will want to write in the documentation of your class/object. | ||
if (!(store.event in this._events)) | ||
if (!(store.event in this._events)){ | ||
this._events[store.event] = {}; | ||
} | ||
this._events[store.event][store.name] = store; | ||
} | ||
this.addAction(store.name); | ||
}; | ||
/** | ||
@@ -76,3 +75,4 @@ * method to remove an eventlistener or even all. | ||
} | ||
} | ||
}; | ||
/** | ||
@@ -87,7 +87,7 @@ * executing all listener that are registered on the event | ||
} | ||
if(value!== undefined){ | ||
if(value !== undefined){ | ||
action.value=value; | ||
} | ||
if (!action.event) return; | ||
this._actions.push(action) | ||
this._actions.push(action); | ||
if(this.isDispatching) return; | ||
@@ -104,3 +104,3 @@ | ||
for(var i in events){ | ||
todoEvents[i]=events[i]; | ||
todoEvents[i] = events[i]; | ||
} | ||
@@ -114,3 +114,3 @@ | ||
var found=false; | ||
for(var r = 0;r<todoEvents[i].require.length;r++){ | ||
for(var r = 0; r<todoEvents[i].require.length; r++){ | ||
if(!done[todoEvents[i].require[r]]){ | ||
@@ -136,3 +136,3 @@ found=true; | ||
this.isDispatching = false; | ||
} | ||
}; | ||
@@ -139,0 +139,0 @@ /** |
20932
57
210