# flux-framework

> My first flux-based framework

Latest version **1.0.0** (published 2018-11-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install flux-framework
pnpm add flux-framework
yarn add flux-framework
bun add flux-framework
```

## 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.0.0 |
| Published | 2018-11-11 |
| First published | 2018-11-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | ajmdag |

## Links

- npm: https://www.npmjs.com/package/flux-framework
- Repository: https://github.com/Ajmdag/flux-framework
- Homepage: https://github.com/Ajmdag/flux-framework#readme
- Issues: https://github.com/Ajmdag/flux-framework/issues
- npm.io page: https://npm.io/package/flux-framework

## Recent versions

- 1.0.0 (latest) — 2018-11-11
- 2.0.0 — 2018-11-11

## README

# flux-framework
My first flux-based framework

[![Build Status](https://travis-ci.org/Ajmdag/flux-framework.svg?branch=master)](https://travis-ci.org/Ajmdag/flux-framework)

## Installation
```
npm i -D ajmdag/flux-framework
```

## Development
```
git clone https://github.com/Ajmdag/flux-framework.git
cd flux-framework
npm i
```

# Documentation

## Usage
To use this library, you should create Store instance.
```js
import Store from 'flux-framework';

const store = new Store(stateUpdator, initialState);
```
`stateUpdator` and `initialState` are required.

### stateUpdator
`stateUpdator` is a function that knows how to change state, depending on the input data. Should return new state.

```js
function stateUpdator(state, action) {
  switch(action.type) {
  case 'INCREMENT':
    return { count: state.count + action.amount };
  case 'DECREMENT':
    return { count: state.count - action.amount };
  default: return state;
  }
}
```

### initialState
`initialState` is a data, that describes the initial state of your application or component.

```js
const initialState = {
  count: 0
};
```

### create actions
```js
const incrementAction = { type: "INCREMENT", amount: 3 };
const decrementAction = { type: "DECREMENT", amount: 5 };
```

### udpate store with actions
```js
store.update(incrementAction);
store.update(decrementAction);
```

### subscribe
`subscribe(callback)`. `callback` is a function that will be called when store will be changed.
```js
store.subscribe(() => console.log("State changed", store.state));
```

### unsubscribe
To unsubscribe from store changes just put `store.subscribe(callback)` in a variable(or constant) and call it as a function.
```js
const unsubscribe = store.subscribe(() => console.log("State changed", store.state));
unsubscribe();
```

### getState
To get a store use this method:
```js
store.getState;
```

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