-
-
Notifications
You must be signed in to change notification settings - Fork 0
traverse deref()
Eugene Lazutkin edited this page Apr 6, 2026
·
4 revisions
Dereferences variables in place, modifying the original object.
Replaces all Variable instances with their bound values from an Env directly in the source object. Unlike assemble(), this modifies the original object rather than creating a new one.
import {variable} from 'deep6/env.js';
import unify from 'deep6/unify.js';
import deref from 'deep6/traverse/deref.js';
const x = variable('x');
const y = variable('y');
const env = unify({x: 42, y: 'hello'}, {x, y});
const obj = {a: x, b: [y, x]};
deref(obj, env); // Modifies obj in place
// obj === {a: 42, b: ['hello', 42]}Arguments:
-
source— a required value containing variables to resolve. It can be anything. This object will be modified in place. -
env— an optional Env with variable bindings, or an options object. -
options— an optional object. The following optional properties are recognized:-
circular— a boolean flag to handle circular references. -
symbols— a boolean flag to include symbol properties. -
allProps— a boolean flag to include non-enumerable properties. -
context— a custom context object. -
processObject— a custom object processor. -
processOther— a custom value processor. -
processCircular— a custom circular reference processor. -
registry— a custom type handler registry (flat array of Constructor/handler pairs). -
filters— custom filter functions.
-
The function returns the modified source with variables replaced.
The deref module exports registry and filters arrays:
import deref from 'deep6/traverse/deref.js';
deref.registry.push(MyClass, processMyClass);Implemented using walk(). This is more memory-efficient than assemble() when you don't need to preserve the original.