eventmaster
v2.1.0
Published
A simple, compact and consistent implementation that provides both Promise/Deferred/Flow pattern and Event/Notify/Observer/PubSub pattern
Downloads
6
Readme
EventMaster
- A simple, compact and consistent implementation of a variant of CommonJS's Promises and Events
- Provide both Promise/Deferred/Flow pattern and Event/Notify/Observer/PubSub pattern
In NodeJS
npm install eventmaster
In browser
AMD and OzJS
- EventMaster can either be viewed as an independent library, or as a part of OzJS mirco-framework.
- It's wrapped as an AMD (Asynchronous Module Definition) module. You should use it with oz.js (or require.js or similar for handling dependencies).
- If you want to make it available for both other AMD code and traditional code based on global namespace. OzJS provides a mini define/require implementation to transform AMD module into traditional module pattern.
- See http://ozjs.org for details.
Get the Code
- Download on Github
- Add to your project as new dependency:
Dependencies
Examples
API and usage
var Event = require('eventmaster');
Event(opt)
--Event.Promise(opt)
--Event.Event(opt)
--Event.when(promise, promise, ...)
--Event.pipe(prev, next)
--
var event = Event();
event.promise(subject)
--event.when(subject, subject, ...)
--event.once(subject, callback, errorCallback)
--event.done(subject, callback)
--event.fail(subject, callback)
--event.cancel(subject, callback, errorCallback)
--event.bind(subject, callback)
--event.unbind(subject, callback)
--event.on()
-- alias forevent.bind
event.off()
-- alias forevent.unbind
event.progress(subject, callback)
--event.notify(subject, [arg, arg, ...])
--event.fire(subject, [arg, arg, ...])
--event.error(subject, [arg, arg, ...])
--event.resolve(subject, [arg, arg, ...])
--event.reject(subject, [arg, arg, ...])
--event.reset(subject)
--event.disable(subject)
--event.enable(subject)
--
var promise = Event.Promise();
promise.then(callback, errorCallback)
--promise.done(callback)
--promise.fail(callback)
--promise.cancel(callback, errorCallback)
--promise.bind(callback)
--promise.unbind(callback)
--promise.progress()
--promise.notify()
--promise.fire([arg, arg, ...])
--promise.error([arg, arg, ...])
--promise.resolve([arg, arg, ...])
--promise.reject([arg, arg, ...])
--promise.reset()
--promise.disable()
--promise.enable()
--promise.merge()
--promise.follow()
--promise.end()
--promise.all()
--promise.any()
--promise.some()
--promise.pipe.fire(arg, arg, ...)
--promise.pipe.error(arg, arg, ...)
--promise.pipe.notify()
--promise.pipe.resolve(arg, arg, ...)
--promise.pipe.reject(arg, arg, ...)
--promise.pipe.disable()
--promise.pipe.enable()
--promise.pipe.reset()
--
Under construction...
More References
Release History
License
Copyright (c) 2010 - 2013 dexteryy
Licensed under the MIT license.