elementos
v1.0.0
Published
Composable reactive state management
Downloads
3
Readme
elementos
Composable reactive state management
Elementos is a framework-agnostic, reactive state management library with an emphasis on state composition and encapsulation.
Please see the full documentation!
Install
npm install --save elementos
Basic Usage
import { atom, molecule, batched } from 'elementos'
const createVisibility$ = (defaultValue) => {
return atom(defaultValue, {
actions: (set) => ({
open: () => set(true),
close: () => set(false)
})
});
};
const createDialog$ = ({ isOpen = false, context = null } = {}) => {
const visibility$ = createVisibility$(isOpen);
const context$ = atom(context);
const dialog$ = molecule(
{
visibility: visibility$,
context: context$
},
{
actions: ({ visibility, context }) => ({
open: batched((nextContext) => {
context.actions.set(nextContext);
visibility.actions.open();
}),
close: batched(() => {
context.actions.set(null);
visibility.actions.close();
})
}),
deriver: ({ visibility, context }) => ({
isOpen: visibility,
context
})
}
);
return dialog$;
};
License
MIT © malerba118