# memorux

> Simple state container for your vqua components

Latest version **1.3.4** (published 2017-11-01) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.4 |
| Published | 2017-11-01 |
| First published | 2016-10-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Igor Sterjakov |
| Maintainers | sterjakov |
| Keywords | vqua, dispatcher, store, state container |

## Links

- npm: https://www.npmjs.com/package/memorux
- Repository: https://github.com/sterjakovigor/memorux
- Homepage: https://github.com/sterjakovigor/memorux#readme
- Issues: https://github.com/sterjakovigor/memorux/issues
- npm.io page: https://npm.io/package/memorux

## Dependencies (1)

- [vqua-utils](https://npm.io/package/vqua-utils.md) ^1.0.6

## Alternatives

- [@reckona/mreact-store](https://npm.io/package/@reckona/mreact-store.md) — 976 weekly downloads
- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads

## Recent versions

- 1.3.4 (latest) — 2017-11-01
- 1.3.3 — 2017-10-31
- 1.3.2 — 2017-10-30
- 1.3.1 — 2017-10-18
- 1.3.0 — 2017-10-18
- 1.2.2 — 2017-10-13
- 1.2.1 — 2017-10-13
- 1.2.0 — 2017-10-13
- 1.1.14 — 2017-02-07
- 1.1.13 — 2016-11-24
- 1.1.12 — 2016-11-23
- 1.1.11 — 2016-11-02
- 1.1.10 — 2016-11-02
- 1.1.9 — 2016-10-30
- 1.1.8 — 2016-10-24
- … 9 more at https://npm.io/package/memorux/versions

## README

![alt tag](https://raw.githubusercontent.com/sterjakovigor/memorux/master/logo.jpg)

# Memorux
Minimalistic state container for your [vqua](https://github.com/sterjakovigor/vqua) components

# Example

## Step 1. Declare your store

```javascript
class Cat {

  constructor() {

    this.state = {
      say: null
    }

  }

  dispatch(state, action) {

    switch (action.name) {

      case 'update': {

        return action.data

        break

      }

      default: {

        return action.data

      }

    }
  }

}
```

## Step 2. Assign your stores

```javascript
const memorux = require('memorux')

const memorux = new Memorux({ Cat })

memorux.store // => { Cat: { say: null } }
```

## Step 3. Dispatch action

```javascript
memorux.dispatch('Cat#update', { say: 'meow' })

// or

memorux.dispatch({
  name: 'Cat#update',
  data: { say: 'meow' }
})

// or

memorux.dispatch([
  {
    name: 'Cat#update',
    data: { say: 'meow' }
  },
])
```

## Step 4. Listen changes

```javascript
memorux.onChange(store =>

  // store => { Cat: { say: 'meow' } }

)
```

## Delayed actions

just return a promise like callback from your dispatch method

```javascript
class Cat {

  constructor() {

    this.state = {
      say: null
    }

  }

  dispatch(state, action) {

    switch (action.name) {

      case 'update': {

        return (resolve, reject) => {

          setImmediate(() => {

            resolve(action.data)

          })

        }

        break

      }

      default: {

        return action.data

      }

    }
  }

}
```

Also, if you dispatch a few delayed actions
you may need an event ending all of the actions, you can do so

```javascript
memorux.dispatch([

  // delayed action
  // delayed action
  // delayed action

]).then((store) => {

  // do something with store
  // after all actions ready

})
```

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