Can't reference items removed from the store
davidgilbertson opened this issue · 1 comments
davidgilbertson commented
If a user references an array item in the store, then empties the array, this breaks the reference.
The following fails:
it('should keep a reference', () => {
store.testArray = [{ name: 'David' }];
const david = store.testArray[0];
store.testArray = [];
expect(david.name).toBe('David');
});
When reading from the object (david.name
), it's redirected to nextStore
at the path store.testArray.0.name
where that item no longer exists.
I'm not sure what can be done about this.
A workaround would be to use a deep clone function to 'extract' something from the store, striping the proxy away so it can be read like a normal object. That will be OK sometimes, but suck for otherwise-simple things like popping. E.g. this fails:
it('should handle popping an item', () => {
store.testArray = [{ name: 'David' }];
const david = store.testArray.pop();
expect(david.name).toBe('David');
});
Perhaps in some cases (like .slice()
and .pop()
at least) the returned item could be stripped of its proxy.
davidgilbertson commented
Fixed in 5.0.0