How to use the stampit 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 tdzienniak / entropy / packages / entropy / src / EventEmitter.js View on Github external
* Very simple event emitter implementation.
 *
 * @example
 * const ee = EventEmitter()
 *
 * ee.on('myEvent', (e) => {
 *   console.log(e.foo);
 * })
 *
 * ee.emit('myEvent', {
 *    foo: 'bar',
 * }) // prints `bar` in the console
 *
 * @class EventEmitter
 */
const EventEmitter = stampit({
  init() {
    /**
     * Object with registered event listeners. Keys are event names.
     *
     * @private
     * @memberof EventEmitter#
     * @name _events
     * @type Object
     */
    this._events = {};
    this._responding = true;
  },
  methods: {
    /**
     * Method used to register event listener.
     *
github tdzienniak / entropy / packages / entropy / src / Query.js View on Github external
*     exclude: ["Sprite"],
 *   },
 * });
 *
 * //matches entities of type 'Ball'
 * const q3 = Query({
 *   criterions: {
 *     entityType: "Ball",
 *   },
 * });
 *
 * @class Query
 * @param {Object}       opts
 * @param {Object|Array} opts.criterions query criterions
 */
const Query = stampit({
  deepProps: {
    _shouldUpdate: false,
  },
  init(opts) {
    let include = [];
    let exclude = [];
    let includeBitset;
    let excludeBitset;

    if (isArray(opts.criterions)) {
      include = opts.criterions;
    } else if (isObject(opts.criterions)) {
      if (isNonEmptyString(opts.criterions.entityType)) {
        this._matchType = opts.criterions.entityType;
      }
github Syncano / syncano-js / src / models / hourlyusage.js View on Github external
import stampit from 'stampit';
import {Meta, Model} from './base';
import {BaseQuerySet, List, Total, StartDate, EndDate, CurrentMonth} from '../querySet';

const HourlyUsageQuerySet = stampit().compose(
  BaseQuerySet,
  List,
  Total,
  StartDate,
  EndDate,
  CurrentMonth
);

const HourlyUsageMeta = Meta({
  name: 'hourlyusage',
  pluralName: 'hourlyusages',
  endpoints: {
    'list': {
      'methods': ['get'],
      'path': '/v1.1/usage/hourly/'
    }
github Syncano / syncano-js / src / models / card.js View on Github external
});

/**
 * OO wrapper around Card.
 * @constructor
 * @type {Card}

 * @property {String} name
 * @property {String} address_zip
 * @property {String} address_state
 * @property {String} address_country
 * @property {String} address_line2
 * @property {String} address_line1
 * @property {String} address_city
 */
const Card = stampit()
  .compose(Model)
  .setQuerySet(CardQuerySet)
  .setMeta(CardMeta);

export default Card;
github tdzienniak / entropy / packages / entropy / src / Entity.js View on Github external
import stampit from 'stampit';
import { isObject, toLowerFirstCase } from './helpers';

import FastBitset from 'fastbitset';
import FastArray from 'fast-array';
import EventEmitter from './EventEmitter';

/**
 * Entity factory.
 *
 * @class Entity
 */
const Entity = stampit({
  init(opts) {
    this._modifications = FastArray();
    this._used = false;

    this.game = opts.game;
    this.type = opts.type;
    this.id = 0;
    this.bitset = new FastBitset();
    this.components = this.cs = {};
  },
  methods: {
    /**
     * Called when entity is created. Could be overriden (see {@link EntityStore#register}).
     *
     * @memberof Entity#
     */
github Syncano / syncano-js / src / models / triggertrace.js View on Github external
* This model is *read only*.
 * @constructor
 * @type {TriggerTrace}

 * @property {Number} id
 * @property {String} instanceName
 * @property {Number} triggerId
 * @property {String} status
 * @property {Date} executed_at
 * @property {Number} duration
 * @property {Object} [result = {}]
 * @property {String} result.stderr
 * @property {String} result.stdout
 * @property {String} [links = {}]
 */
const TriggerTrace = stampit()
  .compose(Model)
  .setQuerySet(TriggerTraceQuerySet)
  .setConstraints(TriggerTraceConstraints)
  .setMeta(TriggerTraceMeta);

export default TriggerTrace;
github Syncano / syncano-js / src / models / profile.js View on Github external
* @property {Object} subscription
 * @property {String} hard_limit
 * @property {String} soft_limit
 * @property {String} company_name
 * @property {String} first_name
 * @property {String} last_name
 * @property {String} address_line1
 * @property {String} address_line2
 * @property {String} address_city
 * @property {String} address_state
 * @property {String} address_zip
 * @property {String} address_country
 * @property {String} tax_number
 * @property {String} [failed_invoice = null]
 */
const Profile = stampit()
  .compose(Model)
  .setQuerySet(ProfileQuerySet)
  .setMeta(ProfileMeta);

export default Profile;
github Syncano / syncano-js / src / models / scriptendpointtrace.js View on Github external
* This model is *read only*.
 * @constructor
 * @type {ScriptEndpointTrace}

 * @property {Number} id
 * @property {String} instanceName
 * @property {String} scriptEndpointName
 * @property {String} status
 * @property {Date} executed_at
 * @property {Number} duration
 * @property {Object} [result = {}]
 * @property {String} result.stderr
 * @property {String} result.stdout
 * @property {String} [links = {}]
 */
const ScriptEndpointTrace = stampit()
  .compose(Model)
  .setMeta(ScriptEndpointTraceMeta)
  .setQuerySet(ScriptEndpointTraceQuerySet)
  .setConstraints(ScriptEndpointTraceConstraints);

export default ScriptEndpointTrace;
github Syncano / syncano-js / src / utils.js View on Github external
return this.fixed.refs._meta;
    }
  }
});

/**
 * Used as a manager for {@link http://validatejs.org/#constraints|Constraints} object (validation). **Not** meant to be used directly.
 * @constructor
 * @type {ConstraintsMixin}

 * @property {Object} _constraints private attribute which holds constraints object

 * @example {@lang javascript}
 * var MyStamp = stampit().compose(ConstraintsMixin);
 */
export const ConstraintsMixin = stampit({
  methods: {

    /**
    * Sets constraints used for validation.

    * @memberOf ConstraintsMixin
    * @instance

    * @param {Object} constraints plain JavaScript object
    * @returns {ConstraintsMixin}

    * @example {@lang javascript}
    * var MyStamp = stampit().compose(ConstraintsMixin);
    * var newObject = MyStamp().setConstraints({});

    */
github tdzienniak / entropy / packages / entropy / src / Pool.js View on Github external
import stampit from 'stampit';
import FastArray from 'fast-array';

const Pool = stampit({
  init(options) {
    this._pool = FastArray();

    this._new = options._new;
    this._reuse = options._reuse;
  },
  methods: {
    free(obj) {
      if (this._free) {
        this._free(obj);
      }

      this._pool.push(obj);
    },
    allocate(...args) {
      let obj;

stampit

Create objects from reusable, composable behaviors.

MIT
Latest version published 3 years ago

Package Health Score

62 / 100
Full package analysis