Javascript events without any DOM overheat Inspired by WordPress hooks system and jQuery
- namespacing : es. triggering "updated" will trigger "updated.namespace"
- refactoring : there is always space to improvement!
- once : trigger the function or filter just once
- context : assing a context to the run function
- async : we can trigger events without locking current script
- stopPropagation : stop further events from running
- priority : set function priority just like in wordpress
- debug : console log events and action perfomed
- filter system : triggers and events and passes the result allowing changing value
- failure handler : every action is run in try-catch mode so the chain wont be broken
- trigger system : event listner core concept
This library will allow you to trigger custom events and filter data in kinda WordPress fashion!
First we need to declare listeners
Evented.on('test', function(e,a,b,c,d,e,f) {console.log(e,a,b,c,d,e,f);});
Evented.on('test', function(e,a,b,c,d,e,f) {console.log('Second',e,a,b,c,d,e,f);});
Evented.on('test', function() {console.log(arguments);});
And than we can run a trigger which will execute the code by triggering
Evented.trigger('test', [1,2,3,4,5,6]);
First we need to declare listeners
Evented.add_filter('test', function(data) {data.addme += 2; return data;});
Evented.add_filter('test', function(data) {data.addme += 5; return data;});
And than we can run a trigger which will execute the code by triggering
Evented.filter('test', [{addme: 5, deleteme: true}]);
Sometimes you need to perform action before others. Every event added will have a priority set. The default value is 50. If that space is already occupied it will become priority 51 or greater until a free slot is found.
Evented.on('test', function() {}, 50);
You can overwrite any event by forcing priority like this:
Evented.on('test', function() {}, 50, true);
Set Evented.debug = true;
to see what is happening under the hood ;)
To stop event propagation set Evented.stop = true;
and no further action will be triggered.
(Maybe in conflict with async functions, cos it's a shared value, for now).
Sometimes we need to keep the current workflow stable and don't want to lock the current workflow.
Se we can send the event(not filter) to background trought.setTimeout() and that function will be executed as soon as possible probably at the end of all the others. This function is still under research and just an idea...and may be removed.
Evented.trigger(name, args, context, async, is_filter)