Comments (5)
I think I found the problem.
Cortex use array element's index as path
. After adding / removing element from array, element's index changes. However, if that element is a object, path
for that object, and path for any nested element of that object wont update.
let list = [
{ id: 0, count: 0, foo: { bar: { name: 'john' } } },
{ id: 1, count: 0, foo: { bar: { name: 'sam' } } },
];
console.log( list[1].foo.bar.name.__path ) // [1, 'foo', 'bar', 'name']
list.shift(); // remove first item
console.log( list[0].foo.bar.name.__path ) // [1, 'foo', 'bar', 'name']
from cortex.
I think there's scoping issue with the way you define individual removeItem
. Those methods probably have references to the previous cortex object instead of the updated one. Define it on the List component instead (it accepts an id and invoke and pass it in from the children). When the list changes, cortex will rewrap entire list object and since it's a brand new object the path should be correct.
from cortex.
No, it's not a scoping issue.
Please see this example
Click shift, then click setFirst, get error: Cannot read property 'getPath' of undefined
.
from cortex.
@blackChef yes this is a bug with the rewrapping mechanism. In your example if you look at list[0].__path
then it will report the right path after shift
. However, that path change isn't propagated down to every children in the subtree. Thanks for debuggin it. Let me have a look at the code and figure out a solution.
from cortex.
Hi @blackChef Thanks for finding the problem. I fixed the issue and added more test cases to cover this bug. Please let me know if you find anything missing.
from cortex.
Related Issues (20)
- cortextstore.splice not working as expected HOT 1
- cortexstore.val() out of synch with cortexstore.map() HOT 1
- Why not use Immutable.js? HOT 6
- How to handle cortex array efficiently? HOT 1
- can't remove a key of 0
- Why calling destroy on root level still trigger onUpdate callback? HOT 2
- how to work with redux + react + webpack? HOT 1
- Tests not running HOT 3
- Unable to reset a value within the same tick HOT 9
- Using setProps to do the react update is depricated, per cortex intro HOT 4
- Please add a clearChange() to cortex HOT 1
- Deprecate getChanges and didChange HOT 1
- Adding a callback to set function HOT 5
- Add "this" argument to ArrayWrapper map HOT 1
- when call set() of an empty array, the first element of the new array will be remove HOT 1
- Usage with React propTypes HOT 5
- React Native support? HOT 1
- Please publish v2.0.2 HOT 6
- Please explain this part HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cortex.