# zeroflux

> Typed state management

Latest version **0.0.8** (published 2015-12-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install zeroflux
pnpm add zeroflux
yarn add zeroflux
bun add zeroflux
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2015-12-31 |
| First published | 2015-12-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Matt Baker |
| Maintainers | reissbaker |

## Links

- npm: https://www.npmjs.com/package/zeroflux
- npm.io page: https://npm.io/package/zeroflux

## Recent versions

- 0.0.8 (latest) — 2015-12-31
- 0.0.7 — 2015-12-31
- 0.0.6 — 2015-12-25
- 0.0.5 — 2015-12-08
- 0.0.1 — 2015-12-05

## README

Zeroflux
================================================================================

A small, typed state management library.

Example:

```typescript
'use strict';

import flux = require('zeroflux');

interface TodoAction {
  name: string;
  id: number;
}

const app = new flux.App();

const dispatcher = {
  addTodo: app.action<TodoAction>(),
  removeTodo: app.action<TodoAction>(),
};

interface State {
  todos: TodoAction[];
}

const todoStore = app.store<State>((builder) => {
  builder.reduce(dispatcher.addTodo, (state, todoAction) => {
    return {
      todos: state.todos.concat([ todoAction ])
    };
  });

  builder.reduce(dispatcher.removeTodo, (state, todoAction) => {
    return {
      todos: state.todos.filter((item) => {
        return item.id !== todoAction.id;
      })
    };
  });

  return {
    todos: []
  };
});

const julia = dispatcher.addTodo.dispatch({
  id: 0,
  name: 'julia'
});

const clone = dispatcher.addTodo.dispatch({
  id: 1,
  name: 'evil julia clone'
});

todoStore.watch((state) => {
  console.log('saw new state:', state);
});

console.log('evil clone detected:');
console.log('current state:', todoStore.state);

console.log('eliminating evil clone:');
dispatcher.removeTodo.dispatch(clone);

console.log('evil clone eliminated:');
console.log('current state:', todoStore.state);
```

---
_Source: https://npm.io/package/zeroflux · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
