deepMove item of array into another path from same obj/array #107
Replies: 10 comments
|
better combine 'obj path' with _.index deepMove(obj, '[0].a.[3]', '[1].b.[6]') |
|
similar to deepRemove / deepCopy but all can action by path? deepRemove(obj, '[0].a.[3]') deepCopy(obj, '[0].a.[3]', '[1].b.[6]') |
|
Let me please clarify, do you want this? _.set(obj, targetPath, _.get(obj, sourcePath)); |
|
Or this? .condenseDeep(.set(obj, targetPath, _.get(obj, sourcePath))); Note, you should decide what will you do if target path already exists. |
|
https://github.com/rhalff/dot-object#move-a-property-within-one-object-to-another-location something like this, but it lacks array support i think. |
|
Could you please describe your use cases? Also how do you see this method should behave in case of:
var res = _.moveDeep({a:1,b:2}, 'a', 'b');
var res = _.moveDeep({a:1,b:[2]}, 'a', 'b[0]');
var res = _.moveDeep({a:1,b:[2]}, 'a', 'b[3]');
var res = _.moveDeep({a:1,b:[2]}, 'a', 'b[3][2].c');
var res = _.moveDeep({a: {b: {c: 1}}}, 'a', 'a.b.c'); |
|
maybe move a card from kanban? the data structure is like [
{
randomid,
type: 'deck',
children: [
{
randomid,
type: 'group',
children: [
{
randomid,
type: 'card',
name: 'card 1',
},
{
randomid,
type: 'card',
name: 'card 2',
},
{
randomid,
type: 'card',
name: 'card 3',
},
]
},
{
randomid,
type: 'card',
name: 'card 7'
}
]
},
{
randomid,
type: 'deck',
children: [
{
randomid,
type: 'card',
name: 'card 4',
},
{
randomid,
type: 'card',
name: 'card 5',
},
{
randomid,
type: 'card',
name: 'card 6',
},
]
},
]like move 'card 5' into 0.children.1.children.2 |
|
these deep method is powerful https://github.com/YuriGor/deepdash#mapdeep when you use these with react, mobx you render the tree deeply and mutate mobx state every thing change, but sometimes we need something like swap, move, remove kv pair from nested obj or remove element from nested array etc... |
|
I think you requested too complicated method with unclear specs. |
|
Just faced with a similar use case and implemented like this:
So I am going to implement |
Uh oh!
There was an error while loading. Please reload this page.
any possible to provide such feature?
All reactions