Re:React-cursor: a JavaScript implementation of the Cursor c...
by polskibus on Tuesday September 23, 2014 @03:03PM
(#8357429)
How do I use the cursor to build a recursive json editor that allows appending the tree? Does onChange support adding new elements to the cursor or can I only operate on elements that have been previously fed to the cursor?
[ Parent
| on HN ]
Re:React-cursor: a JavaScript implementation of the Cursor c...
by dustingetz on Tuesday September 23, 2014 @03:47PM
(#8357711)
if your state is { foo: ['a','b','c'] }, you can either do:
cursor.refine('foo', 3).onChange('d')
cursor.refine('foo').onChange(['a', 'b', 'c', 'd'])
(indexes in a js array are the same as keys in a map)It is possible to implement `push` and other list/object ops that are exposed by React.addons.update, they have not been implemented yet because they make the interface more complicated.
http://facebook.github.io/react/docs/update.html
I opened an issue for discussion: https://github.com/dustingetz/react-cursor/issues/10
Re:React-cursor: a JavaScript implementation of the Cursor c...
by polskibus on Tuesday September 23, 2014 @04:28PM
(#8357966)
Thanks, I was more wondering whether I can have something like :
cursor.refine('foo').onChange({'child':{}});
in one place and then in some other, code that would dwelve inside that child recursively (and append the "add child" action to that node as well)My goal is to have a json editor with json as the only model in the application and have react/cursor automatically render the tree, and allow its modification (removing and adding nodes).
Such functionality would require cursor to "dive" inside a json node without knowing its name - I'm not sure whether the 'push' op you are mentioning would be required to achieve this.