1
0
Fork 0
freesewing/packages/core/src/store.mjs

23 lines
558 B
JavaScript
Raw Normal View History

export function Store(raise) {
2019-08-03 15:03:33 +02:00
this.data = new Map()
this.raise = raise
2018-08-05 16:32:38 +02:00
}
/** Sets a value under index key */
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 */
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 */
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