refactor: Use Object.defineProperty with a getter to invalidate #17
@ -91,9 +91,10 @@ export default class PocomathInstance {
|
|||||||
*/
|
*/
|
||||||
_invalidate(name) {
|
_invalidate(name) {
|
||||||
const self = this
|
const self = this
|
||||||
this[name] = function () {
|
Object.defineProperty(this, name, {
|
||||||
return self._bundle(name).apply(self, arguments)
|
configurable: true,
|
||||||
}
|
get: () => self._bundle(name)
|
||||||
|
})
|
||||||
if (!(name in this._imps)) {
|
if (!(name in this._imps)) {
|
||||||
this._imps[name] = {}
|
this._imps[name] = {}
|
||||||
}
|
}
|
||||||
@ -130,7 +131,7 @@ export default class PocomathInstance {
|
|||||||
if (dep === 'self') {
|
if (dep === 'self') {
|
||||||
self_referential = true
|
self_referential = true
|
||||||
} else {
|
} else {
|
||||||
refs[dep] = this._ensureBundle(dep) // assume acyclic for now
|
refs[dep] = this[dep] // assume acyclic for now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (self_referential) {
|
if (self_referential) {
|
||||||
@ -144,20 +145,10 @@ export default class PocomathInstance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const tf = this._typed(name, tf_imps)
|
const tf = this._typed(name, tf_imps)
|
||||||
this[name] = tf
|
Object.defineProperty(this, name, {configurable: true, value: tf})
|
||||||
return 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
|
* Ensure that all of the requested types and conversions are actually
|
||||||
* in the typed-function universe:
|
* in the typed-function universe:
|
||||||
|
Loading…
Reference in New Issue
Block a user