WildEmitter datatype for ampersand-state, so that WildEmitters can be bound to views.
Switch branches/tags
Nothing to show
Clone or download
Cannot retrieve the latest commit at this time.
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.jshintignore
.jshintrc
README.md
index.js
package.json

README.md

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