Git Product home page Git Product logo

broadcast's Introduction

#Broadcast

simple events broadcasting using list of callbacks

methods: on, off, one, trig, aTrig, clean, events, getAllEvents

Rules for how to use:

  • messages can be with any symbol, except ".", because it is identifier for namespace
  • namespace MUST BE start from "." symbol. it's for separate from messages
  • maximum arguments for .trig() = 3, if you need more arguments for send data, use object structures

examples:

// will create group of events with collision detect
var eventsGroup = broadcast.events('my-group', {
    myEv1: 'myEv1',
    myEv2: 'myEv2'
})


var eventsGroup2 = broadcast.events('my-group-2', {
    myEv1: 'myEv1',
    myEv2: 'myEv2'
})

broadcast.trig(evs.myEv1, opt1, opt2); - will trigger message with arguments

// will return evs group
var evs = broadcast.events('my-group');

// bind handler to evs.myEv1 = 'my-group' trigger
broadcast.on(evs.myEv1, function(params){
  console.log(params.params1); //see 'ohh now'
});

// 'myHandler' will call only once
broadcast.one('my-event', '.my-namespace', myHandler);

// bind to different messages to 'myHandler'
broadcast.on(['my-event1', 'my-event2'], '.my-namespace', myHandler);


// unbind all callbacks from MESSAGE
broadcast.off('my-event');

unbind all callbacks from NAMESPACE
broadcast.off('.namespace');

// will trigger immedially from current point
broadcast.trig('my-event', {param1: 'ohh now', param2: 2}); // or without params

// will trigger after current callstack is done
broadcast.aTrig('my-event', params);

licence: MIT, dudiq 2012

broadcast's People

Contributors

dudiq avatar

Watchers

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