Overview

Mates exports boolean type guards that inspect branded runtime flags on atoms, actions, events, and related primitives. Use them in shared helpers, DevTools-style inspectors, or library code that accepts unknown values.

They are not TypeScript type predicates with narrow generics for every case — treat the return as a boolean runtime check and cast when needed.

isAtom / isAction / isAsyncAction

Probe live primitives created in the playground.

import { html, atom, action, asyncAction, renderApp, isAtom, isAction, isAsyncAction } from 'mates';

const count = atom(0);
const bump = action(() => count.set(c => c + 1));
const load = asyncAction(async () => ({ ok: true }));

const App = () => {
const rows = atom([
['count', isAtom(count)],
['bump', isAction(bump)],
['load', isAsyncAction(load)],
['plain', isAtom({})],
]);

return () => html`
<div class="m-col m-gap">
<button class="btn-primary" @click=${() => bump()}>bump (action)</button>
<p class="muted m-t-5">count=${count()}</p>
<div class="card card-body">
<span class="overline">Guards</span>
${rows().map(([name, ok]) => html`
<div class="mono">${name}: ${ok ? '✓' : '✗'}</div>
`)}
</div>
</div>
`;
};
renderApp(App, document.getElementById('app'));

Mixed values

Compare atoms vs sync/async functions vs plain data.

import { html, atom, renderApp, isAtom, isFunction, isAsyncFunction } from 'mates';

const samples = [
['atom(0)', atom(0)],
['() => 1', () => 1],
['async () => 1', async () => 1],
['42', 42],
];

const App = () => () => html`
<div class="m-col m-gap">
<div class="card card-body">
<span class="overline">isAtom / isFunction / isAsyncFunction</span>
${samples.map(([label, v]) => html`
<div class="mono">
${label}:
atom=${isAtom(v) ? 'Y' : 'N'}
fn=${isFunction(v) ? 'Y' : 'N'}
async=${isAsyncFunction(v) ? 'Y' : 'N'}
</div>
`)}
</div>
</div>
`;
renderApp(App, document.getElementById('app'));