How to use the stampit.convertConstructor function in stampit

To help you get started, we’ve selected a few stampit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ericelliott / feature-toggle / feature-toggle-client.js View on Github external
activeFeatures = 
            activeFeatures.filter(function (feature) {
              return !contains(features, feature);
            });
          setFlags(activeFeatures);
          this.emit('deactivated', features);
          return this;
        }
      },

      // Creates the feature toggle object by
      // composing the methods above with an
      // event emitter using the Stampit
      // prototypal inheritance library.
      ft = stampit.compose(
        stampit.convertConstructor(EventEmitter),
        stampit(methods)
      ).create();

    // Kick things off by setting feature classes
    // for the currently active features.
    setFlags(activeFeatures);

    return ft;
  };
github ericelliott / feature-toggle / dist / feature-toggle-client.js View on Github external
activeFeatures = 
            activeFeatures.filter(function (feature) {
              return !contains(features, feature);
            });
          setFlags(activeFeatures);
          this.emit('deactivated', features);
          return this;
        }
      },

      // Creates the feature toggle object by
      // composing the methods above with an
      // event emitter using the Stampit
      // prototypal inheritance library.
      ft = stampit.compose(
        stampit.convertConstructor(EventEmitter),
        stampit(methods)
      ).create();

    // Kick things off by setting feature classes
    // for the currently active features.
    setFlags(activeFeatures);

    return ft;
  };
github ericelliott / qconf / lib / make-config.js View on Github external
'use strict';
var stampit = require('stampit'),
  EventEmitter = require('events').EventEmitter,
  events = stampit.convertConstructor(EventEmitter),
  dotty = require('dotty');

module.exports = function makeConfig(sources) {
  return stampit.compose(events)
    .enclose(function () {
      var factory = stampit(),
          attrs = factory
            .state.apply(factory, 
              sources)
            .create();

      return stampit.extend(this, {
        /**
         * Return the value of the attribute requested.
         * @param  {String} attr The name of the attribute to return.
         * @return {Any} The value of the requested attribute.
github ozzyogkush / formation / src / utilities / node-event-emitter-stamp.js View on Github external
'use strict';

const stampit = require('stampit');
const EventEmitter = require('events').EventEmitter;

/**
 * Turn a node `EventEmitter` into a Stamp.
 *
 * @copyright     Copyright (c) 2016, Derek Rosenzweig
 * @author        Derek Rosenzweig 
 * @package       Formation
 * @namespace     Formation.eventEmitter
 * @mixin         Formation.eventEmitter
 */
const eventEmitterStamp = stampit.convertConstructor(EventEmitter);

/**
 * Provides an interface for defining Formation Node events.
 *
 * @copyright     Copyright (c) 2016, Derek Rosenzweig
 * @author        Derek Rosenzweig 
 * @package       Formation
 * @namespace     Formation.eventEmitterEvents
 * @mixin         Formation.eventEmitterEvents
 *
 * @mixes         Formation.eventEmitter
 */
const eventEmitterEventsStamp = stampit()
  .init(function() {

    /**
github Syncano / syncano-js / src / utils.js View on Github external
}
  }
  return null;
}

export {validate};

/**
 * Simple wrapper around `EventEmitter`
 * @constructor
 * @type {EventEmittable}

 * @example {@lang javascript}
 * var EmittableModel = stampit().compose(EventEmittable);
 */
export const EventEmittable = stampit.convertConstructor(EventEmitter);


/**
 * Used as a manager for {@link Syncano} base object. **Not** meant to be used directly.
 * @constructor
 * @type {ConfigMixin}

 * @property {Syncano} _config private attribute which holds {@link Syncano} object

 * @example {@lang javascript}
 * var MyStamp = stampit().compose(ConfigMixin);
 */
export const ConfigMixin = stampit({
  methods: {
    /**
    * Gets default properties.
github digsjs / digs / lib / common / object.js View on Github external
'use strict';

let stampit = require('stampit');
let EventEmitter = require('events').EventEmitter;
let EventEmittable = stampit.convertConstructor(EventEmitter);
let Joi = require('joi');
let _ = require('digs-utils');
let define = require('digs-utils/define');

const DigsObject = define({
  init: function init(context) {
    const digs = _.first(context.args);
    Joi.assert(digs, Joi.object({
      settings: Joi.object({
        app: Joi.object({
          namespace: Joi.string()
            .required(),
          project: Joi.string()
            .required()
        })
          .required()
github ericelliott / irecord / source / index.js View on Github external
return history[history.length - 1];
  };

  const update = function update (value) {
    if (state() === value) return;

    const previous = state();

    history.push(value);
    instance.emit('change', {value, previous});
  };

  history.push(immutable.fromJS(obj));

  stamp =
    stampit.convertConstructor(events.EventEmitter)
    .methods({
      get (key) {
        return state().getIn(dp(key));
      },
      set (key, val) {
        update(state().setIn(dp(key), val));
        return this;
      },
      remove (key) {
        update(state().removeIn(dp(key)));
        return this;
      },
      toJS () {
        return state().toJS();
      }
    })

stampit

Create objects from reusable, composable behaviors.

MIT
Latest version published 4 years ago

Package Health Score

69 / 100
Full package analysis