Skip to content

merge() function

Home > @rimitive/core > merge

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>;

Parameter

Type

Description

base

Use<TSvc>

additions

TAdditions

Returns:

Use<Omit<TSvc, keyof TAdditions> & TAdditions>

import { compose, merge } from '@rimitive/core';
import { SignalModule } from '@rimitive/signals/extend';
const svc = compose(SignalModule);
// Add new properties
const extended = merge(svc, { theme: createTheme() });
extended.theme; // available
extended.signal; // same instance as svc.signal
// Override existing properties for a subtree
const childSvc = merge(svc, { signal: customSignal });

Inside a behavior

const myBehavior = (svc) => {
// Add router for this subtree
const childSvc = merge(svc, createRouter(svc));
return () => childSvc(ChildComponent);
};