Skip to content

assign

A deeply recursive version of Object.assign.

Arrays are copied, not merged: a source array replaces the target’s array at that key wholesale, which is what you want for a new data or groupBy list.

import {assign} from "@d3plus/dom";

assign(
  {tags: ["a", "b"], deep: {list: [1]}},
  {tags: ["c"], deep: {list: [2, 3]}},
);

A deep Object.assign: later sources win for plain values, but nested objects are merged rather than replaced, so deep.group survives alongside the new deep.value. This is how every d3plus config() call layers over the existing configuration.

import {assign} from "@d3plus/dom";

assign({id: "foo", deep: {group: "A"}}, {id: "bar", deep: {value: 20}});

Any number of sources can be passed and they are applied left to right. Starting from an empty object leaves defaults untouched for the next call.

import {assign} from "@d3plus/dom";

const defaults = {font: {size: 12, family: "Inter"}, color: "#1c7ed6"};
const theme = {font: {size: 14}};
const overrides = {color: "#c92a2a"};

assign({}, defaults, theme, overrides);

Parameters

import {assign} from "@d3plus/dom";
objectsrequiredArray.<Record>

The source objects to merge into the target.