/elf

🧙‍♀️ A Reactive Store with Magical Powers

Primary LanguageTypeScriptMIT LicenseMIT

Elf

A Reactive Store with Magical Powers

Elf is a reactive immutable state management solution built on top of RxJS. It uses custom RxJS operators to query the state and pure functions to update it.

Elf encourages simplicity. It eases the hassle of creating boilerplate code and comes with robust tools, suitable for both experienced and inexperienced developers.

✅  Modular by design
✅  Tree Shakeable & Fully Typed
✅  CLI
✅  First Class Entities Support
✅  Requests Status & Cache
✅  Persist State
✅  State History
✅  Pagination
✅  Devtools


@ngneat/elf commitizen PRs coc-badge semantic-release styled with prettier

🤓 Learn about it on the docs site

👩‍🎓 Check out the React Todos example

😋 Check out the Angular Todos example


import { Store, createState, withProps, select } from '@ngneat/elf';
import { withEntities, selectAll } from '@ngneat/elf-entities';

interface TodosProps {
  filter: 'ALL' | 'ACTIVE' | 'COMPLETED';
}

const { state, config } = createState(
  withProps<TodosProps>({ filter: 'ALL' }),
  withEntities<Todo>()
);

const store = new Store({ name: 'todos', state, config });

export const filter$ = store.pipe(select(({ filter }) => filter));
export const todos$ = store.pipe(selectAll());

export function setTodos(todos: Todo[]) {
  store.reduce(setEntities(todos));
}

export function updateFilter(filter: TodosProps['filter']) {
  store.reduce(state => ({
    ...state,
    filter
  }));
}