Skip to content

biscuit-js/biscuit-store

Repository files navigation

biscuit

JavaScript library for application state-management.

Build Status Typescript npm version release Build Status download

Twitter

Official library website

Description

Biscuit is a modular tool for creating and editing configurable containers for managed states. The goal of the Biscuit-store is to simplify the process of working with states as much as possible, while at the same time providing a consistent architectural approach.

Advantages:

  • Flexible architecture
  • immutable
  • Asynchronous out of the box
  • React support
  • Simple extension with middleware
  • Easy debugging

The approach to creating containers in a biscuit is simple and can be described using the example of creating a duck:

  1. Create a duck;
  2. Tell the duck that it is by definition a duck so it must swim, quack and fly;
  3. Teach the duck to swim, fly and quack.

Installation

Installation of core files

npm install @biscuit-store/core

installing the adapter extension

npm install @biscuit-store/adapter 

Installing an extension to share with react

npm install @biscuit-store/react 

Documentation

Help


Basic exemple

This example describes the process of creating a repository using the createStore method.

import { createStore } from "@biscuit-store/core";
import { connect } from "./counterAdapter";

const { store, actions } = createStore({
  name: "counter",
  initial: { value: 0 },
  actions: {
    increment: "increment/action",
    decrement: "decrement/action"
  },
  middleware: [connect]
});

const { increment, decrement } = actions;

increment.subscribe(() => {
  console.log("incremented");
})

decrement.subscribe(() => {
  console.log("decremented");
})

store.subscribe(({ value }) => {
  console.log("count:", value);
})

increment.dispatch({value: 1});

The adapter module is used for encapsulated state management.

import { createAdapter } from "@biscuit-store/adapter";
const { action, connect } = createAdapter();

action("increment/action", ({ payload, state }) => {
  state.value += payload.value;
});

action("decrement/action", ({ payload, state }) => {
  state.value -= payload.value;
});

export { connect };

Edit Biscuit-store/example-javascript

Example with combined actions

Combined actions are a way to create a repository with built-in managed states. This approach is ideal for stores with a small logical load.

import { createStore } from "@biscuit-store/core";

const { actions } = createStore({
  name: "counter",
  initial: { value: 0 },
  combineActions: {
    increment: (state) => {
      state.value += 1;
    },
    decrement: (state) => {
      state.value -= 1;
    },
  }
});

const { increment, decrement } = actions;

increment.dispatch().after(({ value }) => {
   console.log("count:", value);
});

Edit Biscuit-store/example-javascript (forked)

Some more examples

Tested in browsers

Platform chrome ie opera ff safari
Version 48+ 11+ 25+ 40+ 9+
Checked chrome chrome chrome chrome chrome

Contributing

If you liked the library, you have many ways to help it develop.

  • You can write about the biscuit-store on various forums;
  • Put a star on github;
  • Write about the bugs found and suggest improvements;
  • Participate in the development, offer your pull request;
  • Or you can just help financially;

The rules of assistance can be found here.

Donate

Any financial help will help the biscuit to become better.

Buy Me A Coffee

Inspiration

The idea of developing this library was inspired by the Redux project. During the introduction to the biscuit-store, you will see several patterns that are similar to the concepts of Redux. Nevertheless, biscuit is a separate library that uses completely different architectural principles.

Feedback

If you have any questions, suggestions, comments, suggestions for cooperation, or if you like the library and want to become a sponsor, please contact the developer by email: biscuitstorejs@gmail.com.

Changelog

You can see the list of changes here

Adolescence

  • The library is still young and is in beta testing, for this reason, you may stumble upon bugs and flaws. Please be constructive and help us make this tool better.
  • The developer is not a full-fledged native speaker of English, for this reason, there may be errors and tautologies in the documentation, if you have the opportunity to make the documentation better, then I will be glad of any help.

License

Copyright (c) 2021 Philipp Zhulev

MIT License (MIT).