0

I believe what I am trying to achieve is similar to an HTTP Patch or deep extend function, but I want to achieve it with rxjs. Say I have the following objects:

const arr1 = {
  obj1: { a: 'dog', b: 'cat', c: 'bird' },
  obj2: { a: 'boy', b: 'girl', c: 'guitar' },
  obj3: { a: '1', b: '2', c: '3' }
}

const arr2 = {
  obj1: { a: 'wolf', b: 'lion', c: 'hawk', z: 'bear' },
  obj2: { c: 'car'}
}

I then want to use rxjs in order to get the following output:

const output = {
  obj1: { a: 'wolf', b: 'lion', c: 'hawk', z: 'bear' },
  obj2: { a: 'boy', b: 'girl', c: 'car' },
  obj3: { a: '1', b: '2', c: '3' }
}

Is there an efficient way to achieve this?

1
  • 1
    Can you explain your case further? What's the reasoning behind using RxJS here? If all of data pieces are objects and available in one piece at current moment of time, I don't see what it has to do with RxJS. It's just deep merge/extend which comes in a bunch of different flavours (btw they are objects of objects, not arrays). Commented Oct 9, 2016 at 20:38

1 Answer 1

1

RxJS is not for merging Objects, it is An API for asynchronous programming with observable streams

If you want to merge Objects you can use Lodash merge

var object = {
  'a': [{ 'b': 2 }, { 'd': 4 }]
};

var other = {
  'a': [{ 'c': 3 }, { 'e': 5 }]
};

_.merge(object, other);
// => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }

Or the Object spread operator (not officially supported) https://babeljs.io/docs/plugins/transform-object-rest-spread/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.