diff options
author | Florrie <towerofnix@gmail.com> | 2018-05-30 10:44:59 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2018-05-30 10:44:59 -0300 |
commit | 7473ad4227772295570299873e75032431d1cf41 (patch) | |
tree | 4169b2bb6a7a5ee40c832dd8faa219270ba733b4 /record-store.js | |
parent | a5dd84ec0e46f20954feafa83aea507c2da79a41 (diff) |
UI UI UI UI UI
Diffstat (limited to 'record-store.js')
-rw-r--r-- | record-store.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/record-store.js b/record-store.js new file mode 100644 index 0000000..d0c7623 --- /dev/null +++ b/record-store.js @@ -0,0 +1,35 @@ +const recordSymbolKey = Symbol() + +module.exports = class RecordStore { + constructor() { + // Each track (or whatever) gets a symbol which is used as a key here to + // store more information. + this.data = {} + } + + getRecord(obj) { + if (typeof obj !== 'object') { + throw new TypeError('Cannot get the record of a non-object') + } + + if (!obj[recordSymbolKey]) { + obj[recordSymbolKey] = Symbol() + } + + if (!this.data[obj[recordSymbolKey]]) { + this.data[obj[recordSymbolKey]] = {} + } + + return this.data[obj[recordSymbolKey]] + } + + deleteRecord(obj) { + if (typeof obj !== 'object') { + throw new TypeError('Non-objects cannot have a record in the first place') + } + + if (obj[recordSymbolKey]) { + delete this.data[obj[recordSymbolKey]] + } + } +} |