omniscientjs / immstruct

Immutable data structures with history for top-to-bottom properties in component based libraries like React. Based on Immutable.js
374 stars 21 forks source link

Provide ability to have history capped #54

Closed jeffbski closed 9 years ago

jeffbski commented 9 years ago

Add the ability to have history capped to a certain number of operations which is good for long running systems or heavy data use.

By specifying the optional limit, the history mechanism will release old records once it hits the threshold.

The limit is optional and if omitted, then the limit is Infinity.

// optionalKey and/or optionalLimit can be omitted from the call
var optionalLimit = 10; // only keep last 10 of history, default Infinity
var structure = immstruct.withHistory('optionalKey', optionalLimit, { 'foo': 'bar' });
var structureNoKey = immstruct.withHistory(optionalLimit, { 'foo': 'bar' });

var structureNoKeyUnlimited = immstruct.withHistory({ 'foo': 'bar' });
var structureKeyUnlimited = immstruct.withHistory('foo', { 'foo': 'bar' });
mikaelbr commented 9 years ago

Looks good to me. Makes sense to have a limit, for long living apps. Maybe you could squash the commits and I'll merge it?

jeffbski commented 9 years ago

ok, will do.

jeffbski commented 9 years ago

I'm going to make one more change to the commit comment and it will be ready.

jeffbski commented 9 years ago

ok @mikaelbr I believe it is ready to merge.

mikaelbr commented 9 years ago

Very good. Merging now. :cake:

jeffbski commented 9 years ago

Excellent. Thanks.