Created
June 12, 2015 01:21
-
-
Save greg5green/baebf2079ca014c1ba3e to your computer and use it in GitHub Desktop.
Example ES6 file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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