Open koresar opened 9 years ago
Great ideas. =)
nestable
should probably be called namespaced
, instead.assignAllOptions
with overrides
.We should add:
@ericelliott I've updated the initial issue with your suggestions.
:+1:
Hey, @ericelliott. How are you?
I was just about to publish the new version of stamp-utils module, https://www.npmjs.com/package/stamp-utils … But you are the only who has access. :)
Could you please checkout stamp-utils and run:
$ npm owner add koresar
That would be awesome to do asap while I have resources to implement the utilities! Thanks!
import stampit from 'stampit';
import _ from 'lodash';
// NOTE: to improve memory usage you can use WeakMap like this:
// _.memoize.Cache = WeakMap;
/*
Usage:
const AllHumansKiller = Memoize
.props({killAllHumans: true})
.methods({killAllHumans() {}});
*/
export default stampit
.props({
memoize: {
/*
killAllHumans: true
*/
}
})
.init(function memoizeStamp() {
_.keys(this.memoize).forEach(key => {
if (!_.isFunction(this[key]) || !this.memoize[key]) return;
this[key] = _.memoize(this[key]); // Memoizing the configured function
});
});
The following are utility stamp good to have implemented.
selfAware
- the.getStamp()
on object instances.ctor
/instanceOf
- addconstructor
propertiy forinstanceof
operator to work.mutate
(?) - will mutate the given agument, likemutatingStamp(obj)
returns theobj
but decorated with new data according to stamp descriptor:mutatingStamp(obj) === obj
cloneable
- adds.clone()
to object instances.namespaced
- a stamp with static property.nest()
:methods
props
deepProps
staticProps
deepStaticProps
convertConstructor
- should work with both ES5 and ES6 classes.overrides
- takes stamp first argument (options
) and assigns to instances as regular properties.