Pluxbox Logo

Concatenate object block

Purpose:

Combine multiple objects / attributes into a single object. Only executes, when both base and patch has been set.

An attribute is simply a key-value pair. Like age : 26 where 'age' is the key, and '26' is the value. The value, can also be another / multiple keys, but it shall always end with a value at some point. Even if the value is null.

Input

  • Base
    Set the base object, that you whish to expand. Will not trigger any output, so it's safe to override with new base. The base is forgotten, when output has been provided.

  • Patch
    The object you whish to merge into the base. Can be a single key-value pair, or a full object. The patch is forgotten, when output has been provided.

Output

  • Value
    Single object containg everything from the patch and base. If any conflicts between patch and base, the value from patch will win.

Example

To create an object like this:

classDiagram
class  Person {
	Name  :  "Omar"
	Age  : 26
}

We can use two of the 'set data' blocks, to create the two attributes. By combining the attributes with the 'concatenate object' block, we create our object.

graph LR
	A(set data - name) --Base--> C(Concatenate object)
	B(set data - age) --Patch--> C
	C --Object--> D(Destination) 

OBS, if the attribute 'Person' is wanted as a 'wrapper' for the object, use the 'set data' block as destination.

It also works with nested objects. The patch will always overwrite, if there's a match on a 'key'.

Caveats

Make sure the base is set, when adding the patch, otherwise you'll get no output. In some cases, it makes sense to load in an empty object {} directly into the base.