1.0.79 • Published 1 year ago

compax v1.0.79

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

Compax 🤏🏻

State management tool for quick & easy usage.

Usage

import * as compax from 'compax';

Initial State

Generate a new store object using the store method:

const initState = {
  counter: 0,
};

const store = compax.store(initState);

Configure deafult setters for state members:

const store = compax.store(initState, {
  counter: val => val + 1,
});

Store Methods

value

Get the state value using the value method:

const state = store.value();

patch

Set the state value using the patch method:

store.patch({counter: 1});

Pass a function to get the previous state:

store.patch(prev => ({counter: prev.counter + 1}));

reset

Reset the state to initial value using the reset method:

store.reset();

Pass a dependencies array to reset selective members of the state:

store.reset(['counter']);

merge

Merge component's props with state members using the merge method:

export default store.merge(Component);

HOC listening to state changes and updating the props

fetch

Get updated state value inside a functional component using the fetch method:

const {counter} = store.fetch();

Hook listening to state changes and returns the updated state value


Named by Chat-GPT 🤖

1.0.79

1 year ago

1.0.77

1 year ago

1.0.76

1 year ago

1.0.75

1 year ago

1.0.74

1 year ago

1.0.73

1 year ago

1.0.72

1 year ago

1.0.71

1 year ago

1.0.70

1 year ago

1.0.69

1 year ago

1.0.68

1 year ago

1.0.67

1 year ago

1.0.66

1 year ago

1.0.65

1 year ago

1.0.64

1 year ago

1.0.63

1 year ago

1.0.62

1 year ago

1.0.61

1 year ago

1.0.60

1 year ago

1.0.59

1 year ago

1.0.58

1 year ago