From 7473ad4227772295570299873e75032431d1cf41 Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 30 May 2018 10:44:59 -0300 Subject: UI UI UI UI UI --- record-store.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 record-store.js (limited to 'record-store.js') 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]] + } + } +} -- cgit 1.3.0-6-gf8a5