ampersand-wildemitter-datatype-mixin
v1.0.1
Published
WildEmitter datatype for Ampersand state
Downloads
3
Readme
ampersand-wildemitter-datatype-mixin
A mixin for linking WildEmitter objects with Ampersand-State so that they can be bound by Ampersand-View.
Requires that the WildEmitter object emits events with this format:
emitter.emit('change:PROPERTY', emitter, 'VALUE');
It must also make the PROPERTY
value an accessible attribute in
order for things like view bindings to work:
emitter.foo = 'new-foo';
emitter.emit('change:foo', emitter, emitter.foo);
Install
$ npm install ampersand-wildemitter-datatype-mixin
Example
var State = require('ampersand-state');
var WildEmitterMixin = require('ampersand-wildemitter-datatype-mixin');
var StateWithWildEmitter = State.extend(wildemitterMixin, {
props: {
wild: 'wildemitter',
},
derived: {
bar: {
deps: ['wild.foo'],
cache: false,
fn: function () {
return 'it works!';
}
}
}
});
var ex = new StateWithWildEmitter();
ex.wild = new WildEmitter();
ex.on('change:bar', function () {
console.log(ex.bar);
});
ex.wild.emit('change:foo', ex.wild, 'newfoo');
// -> it works!
License
MIT