Merge pull request 'refactor: Use Object.defineProperty with a getter to invalidate' (#17) from no_invalid into main

Reviewed-on: #17
This commit is contained in:
Glen Whitney 2022-07-22 22:09:17 +00:00
commit 2a60cc0989
1 changed files with 6 additions and 15 deletions

View File

@ -91,9 +91,10 @@ export default class PocomathInstance {
*/
_invalidate(name) {
const self = this
this[name] = function () {
return self._bundle(name).apply(self, arguments)
}
Object.defineProperty(this, name, {
configurable: true,
get: () => self._bundle(name)
})
if (!(name in this._imps)) {
this._imps[name] = {}
}
@ -130,7 +131,7 @@ export default class PocomathInstance {
if (dep === 'self') {
self_referential = true
} else {
refs[dep] = this._ensureBundle(dep) // assume acyclic for now
refs[dep] = this[dep] // assume acyclic for now
}
}
if (self_referential) {
@ -144,20 +145,10 @@ export default class PocomathInstance {
}
}
const tf = this._typed(name, tf_imps)
this[name] = tf
Object.defineProperty(this, name, {configurable: true, value: tf})
return tf
}
/**
* Ensure that the generated typed function is assigned to the given
* name and return it
*/
_ensureBundle(name) {
const maybe = this[name]
if (this._typed.isTypedFunction(maybe)) return maybe
return this._bundle(name)
}
/**
* Ensure that all of the requested types and conversions are actually
* in the typed-function universe: