Skip to content

Instantly share code, notes, and snippets.

@greg5green
Created June 12, 2015 01:21
Show Gist options
  • Save greg5green/baebf2079ca014c1ba3e to your computer and use it in GitHub Desktop.
Save greg5green/baebf2079ca014c1ba3e to your computer and use it in GitHub Desktop.
Example ES6 file
import _ from 'lodash';
let records = Symbol('records'),
find = Symbol('find');
class TallyItemModel {
constructor() {
this[records] = [];
}
add(itemName) {
this[records].push({
count: 0,
item: itemName
});
}
decrement(itemName) {
let item = this[find](itemName);
item.count--;
}
getAllRecords() {
return _.clone(this[records]);
}
increment(itemName) {
let item = this[find](itemName);
item.count++;
}
[find](itemCount) {
return _.find(this[records], { item: itemName });
}
}
export default TallyItemModel;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment