Licence
MIT
Version
1.0.2
Deps
2
Size
51 kB
Vulns
0
Weekly
0
@ekz/async-data
Type-safe async state for promises.
Documentation: https://docs.ekz.io/async-data/
Install
npm install @ekz/async-data @ekz/option
Quick example
import { Empty, Ready, observePromise } from '@ekz/async-data';
let data = Empty<User>();
data = data.pending();
data = Ready({ id: 1, name: 'Ada' });
const label = data.match(
{
Ready: (user) => user.name,
Pending: () => 'Loading…',
},
() => '—',
);
See the docs for states, promise observation, and extractors.