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]') |
Beta Was this translation helpful? Give feedback.
-
similar to deepRemove / deepCopy but all can action by path? deepRemove(obj, '[0].a.[3]') deepCopy(obj, '[0].a.[3]', '[1].b.[6]') |
Beta Was this translation helpful? Give feedback.
-
Let me please clarify, do you want this? _.set(obj, targetPath, _.get(obj, sourcePath)); |
Beta Was this translation helpful? Give feedback.
-
Or this? .condenseDeep(.set(obj, targetPath, _.get(obj, sourcePath))); Note, you should decide what will you do if target path already exists. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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'); |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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... |
Beta Was this translation helpful? Give feedback.
-
I think you requested too complicated method with unclear specs. |
Beta Was this translation helpful? Give feedback.
-
Just faced with a similar use case and implemented like this:
So I am going to implement |
Beta Was this translation helpful? Give feedback.
-
any possible to provide such feature?
Beta Was this translation helpful? Give feedback.
All reactions