rednib
v0.0.2
Published
an event binder
Downloads
3
Maintainers
Readme
rednib v0.0.2
rednib takes any object and makes it observable.
var pojo = {};
rednib(pojo);
var onFoo = function () { console.log('onFoo'); };
pojo.bind('foo', onFoo);
pojo.trigger('foo', onFoo); // logs 'onFoo'
pojo.unbind('bar', onBar); // omit the handler to remove all 'bar' handlers
The following will be added to your observable objects:
- bind (Function)
- unbind (Function)
- trigger (Function)
- _handlers (Array)
If you would prefer different function names, you can alias them.
rednib.alias('bind', 'when');
rednib.alias('trigger', 'broadcast');
rednib.alias('unbind', 'forget');
pojo.when('foo', onFoo);
pojo.broadcast('foo', onFoo); // logs 'onFoo'
pojo.forget('foo', onFoo);
================================================
More Info
You an assign multiple handlers at once with an object.
pojo.bind({
foo: function () {},
bar: function () {},
baz: function () {}
});
rednib
, bind
, trigger
, and unbind
all return the observable object, so they can be chained.
rednib({}).
bind('foo', function () { console.log('yo'); }).
trigger('foo').
unbind('foo');
You can include data when triggering an event.
obj.on('foo', function (data) {
// do something with data
});
obj.trigger('foo', { bar: true, baz: false });
================================================
Please create an issue for feature requests or to report bugs.
Coming Soon
- once
- handler scope