merge() function
Home > @rimitive/core > merge
merge() function
Section titled “merge() function”Merge additional properties into a Use context.
Creates a new Use that has all properties from the base plus the additions. The base service instances are preserved (not cloned), so you stay on the same reactive graph.
Signature:
export declare function merge<TSvc, TAdditions extends object>(base: Use<TSvc>, additions: TAdditions): Use<Omit<TSvc, keyof TAdditions> & TAdditions>;Parameters
Section titled “Parameters”|
Parameter |
Type |
Description |
|---|---|---|
|
base |
Use<TSvc> | |
|
additions |
TAdditions |
Returns:
Use<Omit<TSvc, keyof TAdditions> & TAdditions>
Example 1
Section titled “Example 1”import { compose, merge } from '@rimitive/core';import { SignalModule } from '@rimitive/signals/extend';
const svc = compose(SignalModule);
// Add new propertiesconst extended = merge(svc, { theme: createTheme() });extended.theme; // availableextended.signal; // same instance as svc.signal
// Override existing properties for a subtreeconst childSvc = merge(svc, { signal: customSignal });Example 2
Section titled “Example 2”Inside a behavior
const myBehavior = (svc) => { // Add router for this subtree const childSvc = merge(svc, createRouter(svc));
return () => childSvc(ChildComponent);};