5.2.1 • Published 7 years ago

primitate v5.2.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

Primitate

Build Status

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

Install

npm install --save primitate

How 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: 2

Case 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

7 years ago

5.2.0

7 years ago

5.1.0

8 years ago

5.0.0

8 years ago

4.1.1

8 years ago

4.1.0

8 years ago

4.0.0

8 years ago

3.1.6

8 years ago

3.1.5

8 years ago

3.1.4

8 years ago

3.1.3

8 years ago

3.1.2

8 years ago

3.1.1

8 years ago

3.1.0

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.5.2

8 years ago

2.5.1

8 years ago

2.5.0

8 years ago

2.4.0

8 years ago

2.3.0

8 years ago

2.2.4

8 years ago

2.2.3

8 years ago

2.2.2

8 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.0

8 years ago