stampit-org / stamp-utils

Stamp utilities
MIT License
44 stars 2 forks source link

stamps to implement #1

Open koresar opened 9 years ago

koresar commented 9 years ago

The following are utility stamp good to have implemented.

var twoNested = nestable.nest({ db: dbStamp }).nest({ queue: queueStamp });
var instance = twoNested({ db: databaseConfiguration, queue: queueConfiguration });
ericelliott commented 9 years ago

Great ideas. =)

We should add:

koresar commented 9 years ago

@ericelliott I've updated the initial issue with your suggestions.

ericelliott commented 9 years ago

:+1:

koresar commented 8 years ago

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!

koresar commented 8 years ago

Memoization stamp

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
    });
  });