Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
},
props: {
members: {}
}
});
// Let's set some defaults:
const defaults = stampit().props({
name: 'The Saloon',
specials: 'Whisky, Gin, Tequila'
});
// Classical inheritance has nothing on this. No parent/child coupling. No deep inheritance hierarchies.
// Just good, clean code reusability.
const bar = stampit.compose(defaults, membership);
// Note that you can override props on instantiation:
const myBar = bar({ name: 'Moe\'s' });
// Silly, but proves that everything is as it should be.
myBar.add({ name: 'Homer' }).open().getMember('Homer');
const myStamp = stampit().methods({
foo() {
return 'foo';
},
methodOverride() {
return false;
}
}).methods({
bar() {
return 'bar';
},
const a = options.args[0];
this.getA = () => {
return a;
};
});
a(); // Object -- so far so good.
a().getA(); // "a"
const b = stampit().init(function() {
const a = 'b';
this.getB = () => {
return a;
};
});
const c = stampit.compose(a, b);
const foo = c(); // we won't throw this one away...
foo.getA(); // "a"
foo.getB(); // "b"
// Here's a mixin with public methods, and some props:
const membership = stampit({
methods: {
// members: {},
add(member: any) {
this.members[member.name] = member;
return this;
},
getMember(name: any) {
return this.members[name];
}
},
* 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.
*
import { compose } from 'stampit';
import isStamp from 'stampit/isStamp';
import FastArray from 'fast-array';
import EventEmitter from './EventEmitter';
import Pool from './Pool';
import { isNonEmptyString } from './helpers';
/**
* This module manages the state of entities, components and systems. The heart of Entropy.
*
* @class Engine
* @extends EventEmitter
*/
const Engine = compose({
init(opts) {
// entity ids start from 1, 0 means uninitailized or disabled entity
let greatestEntityID = 1;
/**
* When entity is removed, it's ID can be reused by new entities. This pool stores old IDs ready to reuse.
*
* @private
* @name _entitiesIdsPool
* @memberof Engine#
* @type Pool
*/
this._entitiesIdsPool = Pool({
_new() {
return greatestEntityID++;
},
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;
};
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;
};
import stampit from "stampit";
export const Cloneable = stampit.init(({ instance, stamp }) => {
// Avoid adding the same method to the prototype twice.
if (!stamp.fixed.methods.clone) {
stamp.fixed.methods.clone = function () {
return stamp(this);
};
}
});
export const Frozen = stampit().init(({instance}) => {
Object.freeze(instance);
});
register(descriptor) {
this._factories[descriptor.type] = compose(Component, {
methods: pickBy(descriptor, value => isFunction(value)),
});
// generating `id` for class of components
this._componentsIdsMap[descriptor.type] = this._greatestComponentId;
this._greatestComponentId += 1;
this._pools[descriptor.type] = Pool({
_new: (...args) => {
const component = this._factories[descriptor.type]({
type: descriptor.type,
id: this._componentsIdsMap[descriptor.type],
});
component.onCreate(...args);
assert.plan(1);
const record = irecord({
a: 'a',
b: 'b'
});
const stamp = stampit({
methods: {
countProps () {
return Object.keys(this.toJS()).length;
}
}
});
const composedRecord = stampit.compose(
record.stamp,
stamp
).create();
assert.equal(composedRecord.countProps(), 2,
'should expose irecord methods');
});
'use strict';
const stampit = require('stampit');
const { pipe, split, includes } = require('ramda');
const { isFunction } = require('ramda-adjunct');
const WebElementEnhanced = stampit
.props({
webElement: null,
})
.init(function ({ webElement }) {
this.webElement = webElement;
})
.methods({
async containsClassName(className) {
const classList = await this.webElement.getAttribute('class');
return pipe(split(' '), includes(className))(classList);
},
async containsText(text) {
const elementText = await this.webElement.getText();
return includes(text, elementText);