5.2.1 • Published 9 years ago
primitate v5.2.1
Primitate
Primitate is a javascript library for managing state of your app by the only two methods.
Methods
- createAction: Create a function the only way to change the state.
- subscribe: Emit functions when state was changed by the Action.
Official packages
- react-primitate React binding
Install
npm install --save primitateHow to use
Case 1: Initial state is a primitive value or Array
/* import { Primitate } from "primitate" // ES2015 modules style */
const { Primitate } = require("primitate");
// ---------------------------
// 1. Create Primitate Item
// ---------------------------
const Counter = Primitate(0);
// ---------------------------
// 2. Create Action
// ---------------------------
function increment(x) {
return x + 1;
}
const increment$ = Counter.createAction(increment);
// ---------------------------
// 3. Subscribe
// ---------------------------
const unsubscribe =
Counter.subscribe( count => console.log(count) );
// ---------------------------
// 4. Emit Action !!
// ---------------------------
increment$();
increment$();
// console.log: 2Case 2: Initial state is an object
const { Primitate } = require("primitate");
// ---------------------------
// 1. Create Primitate Item
// ---------------------------
const Counter = Primitate({ count1: 0, count2: 0 });
// ---------------------------
// 2. Create Action
// ---------------------------
function increment(x) {
return x + 1;
}
const increment$ = Counter.createAction(
increment,
state => state.count1
);
// ---------------------------
// 3. Subscribe
// ---------------------------
const unsubscribe = Counter.subscribe(
state => console.log(state),
[state => state.count1]
);
// ---------------------------
// 4. Emit Action !!
// ---------------------------
increment$();
increment$();
// console.log({ count1: 2, count2: 0 });Documentation
In preparation...
Lisence
MIT
5.2.1
9 years ago
5.2.0
10 years ago
5.1.0
10 years ago
5.0.0
10 years ago
4.1.1
10 years ago
4.1.0
10 years ago
4.0.0
10 years ago
3.1.6
10 years ago
3.1.5
10 years ago
3.1.4
10 years ago
3.1.3
10 years ago
3.1.2
10 years ago
3.1.1
10 years ago
3.1.0
10 years ago
3.0.1
10 years ago
3.0.0
10 years ago
2.5.2
10 years ago
2.5.1
10 years ago
2.5.0
10 years ago
2.4.0
10 years ago
2.3.0
10 years ago
2.2.4
10 years ago
2.2.3
10 years ago
2.2.2
10 years ago
2.2.1
10 years ago
2.2.0
10 years ago
2.1.0
10 years ago
2.0.3
10 years ago
2.0.2
10 years ago
2.0.1
10 years ago
2.0.0
10 years ago
1.0.0
10 years ago