Dispose called multiple times after DataModelConstructorBuilder.proto.delete
Closed this issue · 0 comments
caseyWebb commented
Package(s)
- model.builders.data, model.builders.view, model.mixins.disposalAggregator
Describe the bug
When attached to a viewModel, the DisposalAggregatorMixin erroneously tries to re-dispose any data models that were deleted (base class calls dispose on delete to prevent updating a no-longer-existent model).
To Reproduce
import {
DataModelConstructorBuilder,
ViewModelConstructorBuilder
} from '@profiscience/knockout-contrib'
test("DisposalAggregatorMixin doesn't re-dispose deleted data model", () => {
const spy = jest.fn()
class DataModel extends DataModelConstructorBuilder<void> {
public fetch = async () => ({})
public dispose() {
spy()
super.dispose()
}
}
class ViewModel extends ViewModelConstructorBuilder {
public data = new DataModel()
}
const vm = new ViewModel()
vm.data.delete()
vm.dispose()
expect(spy).toBeCalledTimes(1)
})
Expected behavior
Already disposed data model should be skipped by DisposalAggregatorMixin