1.2.2 • Published 2 years ago

tiamut v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Tiamut

Simple state management (React optional)

Example

https://githubbox.com/anduong96/Tiamut/tree/main/example

Installation

npm i --save tiamut

Usage with React

Basic

import { createStoreHook, createStore } from 'tiamut';

const store = createStoreHook(
  createStore({
    initialState: {
      value: 1,
    },
    actions: {
      addOne(state) {
        return {
          ...state,
          value: value + 1,
        };
      },
    },
  }),
);

const MyApp = () => {
  const value = store.useSelect((state) => state.value);

  function addOne() {
    // Call this from anywhere
    // Even outside of component
    store.actions.addOne();
  }

  return (
    <div>
      <div>{value}</div>
      <button onClick={addOne}>Add One</button>
    </div>
  );
};

With slices

import { createStore, createCombinedStoreHook } from "tiamut";

const foo = createStore({
  initialState: {
    value: 1,
  },
});

const bar = createStore({
  initialState: {
    value: 2,
  },
  actions: {
    addOne(state) {
      return {
        ...state,
        value: state.value + 1
      }
    }
  }
});

const store = createCombinedStoresHook({
  foo,
  bar,
});

const MyApp = () => {
  const value = store.useSelect((state) => state.foo.value);

  function handleAction() {
    store.actions.bar.addOne();
    // or
    // bar.actions.addOne();
  }

  return (
    <div>
      <div>{value}</div>
      <button onClick={handleAction}>Add One</button>
    </div>;
  )
};

Enhancers

Recipes

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.3-beta.2

2 years ago

1.1.3-beta.1

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago