Noodles, Poodles and More!

    ampersand-wildemitter-datatype-mixin

    1.0.1 • Public • Published

    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

    Keywords

    none

    Install

    npm i ampersand-wildemitter-datatype-mixin

    DownloadsWeekly Downloads

    4

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • lancestout