Giter Club home page Giter Club logo

jnotify's Introduction

jNotify

A simple javascript event manager.

/*
    Add a new listener, returns the label assigned to the callback.  This may
    not seem very useful if you actually assigned a label.  But in cases where
    the user did not assign a label, a label is automatically generated.

    That label can then be used to remove the listener at a later time if
    necessary.
*/
var assigned_label = jNotify.add_listener('eventname', callback, 'test_label');

/*
    Remove Listener, returns true if the listener was found (and as a result
    removed, false if the listener could not be located for that event.
*/
jNotify.remove_listener('eventname', label);

/*
    Signal events, returns the dataobject with any modifications that might 
    have been made by the listeners.
*/
var dataobject = jNotify.signal('eventname', dataobject)

When a function receives a signal, it gets no arguments, instead, the triggered event and the data being passed can be accessed via this.event and this.data within the listener:

function callback() {
    if (this.event == 'testevent') {
        this.data.drink = 'coffee';
    }
}

jNotify.add_listener('testevent', callback);

var dataobject = {};
jNotify.signal('testevent', dataobject);

// dataobject.drink now contains 'coffee'

jnotify's People

Watchers

Chris Mendoza avatar James Cloos avatar

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.