2022-08-28 02:14:39 +02:00
|
|
|
export function Store(raise) {
|
2019-08-03 15:03:33 +02:00
|
|
|
this.data = new Map()
|
2020-07-18 16:48:29 +02:00
|
|
|
this.raise = raise
|
2018-08-05 16:32:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Sets a value under index key */
|
2020-07-18 16:48:29 +02:00
|
|
|
Store.prototype.set = function (key, value) {
|
2019-08-03 15:03:33 +02:00
|
|
|
this.data.set(key, value)
|
|
|
|
}
|
2018-08-05 16:32:38 +02:00
|
|
|
|
|
|
|
/** Sets a value under index key */
|
2020-07-18 16:48:29 +02:00
|
|
|
Store.prototype.setIfUnset = function (key, value) {
|
2019-08-03 15:03:33 +02:00
|
|
|
if (!this.data.has(key)) this.data.set(key, value)
|
|
|
|
}
|
2018-08-05 16:32:38 +02:00
|
|
|
|
|
|
|
/** Gets a value under index key */
|
2020-07-18 16:48:29 +02:00
|
|
|
Store.prototype.get = function (key) {
|
|
|
|
if (!this.data.has(key))
|
|
|
|
this.raise.warning(`Tried to access \`${key}\` in the \`store\` but it is not set`)
|
2019-08-03 15:03:33 +02:00
|
|
|
return this.data.get(key)
|
|
|
|
}
|
2018-08-05 16:32:38 +02:00
|
|
|
|