Giter Site home page Giter Site logo

evented's Introduction

Evented.js

Javascript events without any DOM overheat Inspired by WordPress hooks system and jQuery

Roadmap

  • 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

So what we can do?

This library will allow you to trigger custom events and filter data in kinda WordPress fashion!

Do actions, the output will not be changed

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]);

Do action and change the output (or FILTER)

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}]);

Events / filters priority

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);

Debugging?

Set Evented.debug = true; to see what is happening under the hood ;)

How to stopEventPropagation?

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).

Trigger in async mode (testing)

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)

evented's People

Contributors

keyseedev avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

marcusdiy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.