applyTrace
Applies tracedFabric
mutations
to the given value. The value should have the same state as the traceFabric
value before allied mutations.
WARNING
This function mutates the value directly.
Demo
Following the previous example from traceFabric
demo, here is an extended one with applyTrace
function in use.
Todo list (as JS object)
[ { "name": "📝 Add todo items", "done": false } ]
Trace (all mutations of the todoList)
[]
The trace will be cleared after applying the changes. All changes made to the todo list will be applied to the non-traced todo list. Please note that initial state of the non-traced todo list is not the same as the traced one.
Copy of the Todo List (non-traced)
[ { "name": "📝 Add todo items", "done": false } ]
Arguments
- value - the object to which the trace will be directly applied.
- trace - the
trace
(array ofmutations
) to apply to the given value.
Example
typescript
const fabric = traceFabric({
season: 'winter',
besetDays: [12, 15, 17],
});
const target = {
season: 'winter',
besetDays: [12, 15, 17],
};
target.season = 'summer';
target.besetDays.push(20);
applyTrace(target, fabric.trace);
console.log(target);
// {
// season: "summer",
// besetDays: [ 12, 15, 17, 20 ],
// }