@triggery/signals
v0.10.0
Published
Signals adapter for Triggery — read a signal's value from a trigger condition without engaging signal-tracking on the host component
Maintainers
Readme
@triggery/signals
Read a signal from a Triggery condition without engaging signal-tracking on the host component. Compatible with:
@preact/signals-corealien-signals- Any structurally-similar signal exposing
peek()or.value
Install
pnpm add @triggery/core @triggery/react @triggery/signals
# + the signal library of your choice, e.g.
pnpm add @preact/signals-coreUsage
import { signal } from '@preact/signals-core';
import { createTrigger } from '@triggery/core';
import { useSignalCondition } from '@triggery/signals';
const settings = signal({ sound: true, notifications: true });
const messageTrigger = createTrigger<{
events: { 'new-message': { text: string } };
conditions: { settings: { sound: boolean; notifications: boolean } };
actions: { showToast: { body: string } };
}>({
id: 'message-received',
events: ['new-message'],
required: ['settings'],
handler({ event, conditions, actions }) {
if (!conditions.settings.notifications) return;
actions.showToast?.({ body: event.payload.text });
},
});
function SettingsBridge() {
useSignalCondition(messageTrigger, 'settings', settings);
return null;
}With a selector:
useSignalCondition(messageTrigger, 'settings', profile, (p) => p.settings);How it works
Pull-only: the signal is read only when a trigger fires. The adapter prefers peek() (no dependency tracking) and falls back to .value if peek is missing. Either way, no subscriber is registered against the signal, so the host component never re-renders on signal updates.
If a component also needs to render the signal, use useSignal() from @preact/signals-react or the equivalent in your signal library — the two paths are orthogonal.
API
useSignalCondition<V, S, K>(
trigger: Trigger<S>,
name: K,
signal: { peek?(): V; readonly value?: V },
selector?: (value: V) => ConditionMap<S>[K],
): voidDocumentation
Full documentation, recipes and API reference at https://triggeryjs.github.io/packages/signals/.
Related packages
@triggery/core— Required peer.@triggery/react— Required peer.@triggery/reatom— Alternative adapter for Reatom atoms.@triggery/jotai— Alternative adapter for Jotai atoms.
See the full package list in the repo README.
License
MIT © Aleksey Skhomenko
