Skip to content

hash

Stable hash that serializes functions by their source, so function-valued config props (accessors, formatters) still register as changed when their body changes. Wrappers use this to diff config across a framework’s render cycles — two structurally identical config objects hash equal, so an unchanged config skips a re-render.

A stable string for a config object. Functions are serialized by their source, so two configs built separately but with the same accessors hash the same, while changing an accessor’s body (d.year → d.month) changes the hash. The framework wrappers compare hashes between renders to skip redrawing when nothing changed. Circular references are tolerated.

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

const a = {groupBy: "id", x: d => d.year, tooltipConfig: {title: d => d.name}};
const b = {groupBy: "id", x: d => d.year, tooltipConfig: {title: d => d.name}};
const c = {groupBy: "id", x: d => d.month, tooltipConfig: {title: d => d.name}};
const circular = {label: "self"};
circular.self = circular;

hash(a);
hash(a) === hash(b);
hash(a) === hash(c);
hash(circular);

Parameters

import {hash} from "@d3plus/dom";
valrequiredunknown

Any config value.