fix: clear behaviors that depend on an object property
All checks were successful
/ test (pull_request) Successful in 17s
All checks were successful
/ test (pull_request) Successful in 17s
This commit is contained in:
parent
b2b41d6348
commit
447c62eae9
3 changed files with 10 additions and 6 deletions
|
@ -1,10 +1,7 @@
|
|||
import {onType} from './helpers.js'
|
||||
|
||||
export class Type {
|
||||
constructor(f, options = {}) {
|
||||
this.test = f
|
||||
this.from = options.from ?? onType() // empty Implementations if no ...
|
||||
// ... conversions specified
|
||||
this.from = options.from ?? {patterns: []} // mock empty Implementations
|
||||
}
|
||||
toString() {
|
||||
return this.name || `[Type ${this.test}]`
|
||||
|
|
|
@ -32,7 +32,11 @@ export class TypeDispatcher {
|
|||
for (const key in spec) {
|
||||
let val = spec[key]
|
||||
if (val instanceof Type) {
|
||||
// TODO: Need to wipe out any dependencies on types[key]!
|
||||
// The design here is that we have set up the `types` property to
|
||||
// be watched like any other, so the following assignment will
|
||||
// cause any behaviors that depend on the type named `key` in the
|
||||
// list of types to be cleared out automagically. Seems to work
|
||||
// so far.
|
||||
this.types[key] = val
|
||||
val.name = key
|
||||
continue
|
||||
|
@ -353,7 +357,7 @@ const DependencyWatcher = (object, path, repo) => new Proxy(object, {
|
|||
// First see if this setting has any dependencies:
|
||||
const newPath = path.slice()
|
||||
newPath.push(prop)
|
||||
const key = newPath.unshift()
|
||||
const key = newPath.shift()
|
||||
const depSet = repo._dependencies[key]?.get(newPath)
|
||||
if (depSet?.size) {
|
||||
// It does. So if we are changing it, invalidate them:
|
||||
|
|
|
@ -41,6 +41,9 @@ describe('TypeDispatcher', () => {
|
|||
incremental.add.resolve([Undefined, NumberT]).returns,
|
||||
NumberT)
|
||||
assert.strictEqual(incremental.isnan(NaN), 1)
|
||||
incremental.merge(booleans)
|
||||
assert.strictEqual(incremental.boolean(undefined), false)
|
||||
assert.strictEqual(incremental.isnan(NaN), true)
|
||||
})
|
||||
it('changes methods when their dependencies change', () => {
|
||||
const gnmath = new TypeDispatcher(generics, numbers)
|
||||
|
|
Loading…
Add table
Reference in a new issue