From 447c62eae9e427a76b0ca35dabaf1eb1b2760485 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Sun, 13 Apr 2025 02:00:20 -0700 Subject: [PATCH] fix: clear behaviors that depend on an object property --- src/core/Type.js | 5 +---- src/core/TypeDispatcher.js | 8 ++++++-- src/core/__test__/TypeDispatcher.spec.js | 3 +++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/core/Type.js b/src/core/Type.js index 18530bc..7c728a2 100644 --- a/src/core/Type.js +++ b/src/core/Type.js @@ -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}]` diff --git a/src/core/TypeDispatcher.js b/src/core/TypeDispatcher.js index 963f033..64757ce 100644 --- a/src/core/TypeDispatcher.js +++ b/src/core/TypeDispatcher.js @@ -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: diff --git a/src/core/__test__/TypeDispatcher.spec.js b/src/core/__test__/TypeDispatcher.spec.js index 8c5bf81..81d91a3 100644 --- a/src/core/__test__/TypeDispatcher.spec.js +++ b/src/core/__test__/TypeDispatcher.spec.js @@ -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)