@biscuit-store/core
v1.4.1
Published
Library for management javascript application states.
Downloads
156
Maintainers
Readme
JavaScript library for application state-management.
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:
- Create a duck;
- Tell the duck that it is by definition a duck so it must swim, quack and fly;
- 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 };
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);
});
Some more examples
- Asynchronous data fetching
- Application of dispatch methods
- Typescript example
- Todo list
- Adapter functions
- Listen
Tested in browsers
| Platform | | | | | | |----------|:--------:|:-----:|:-------:|:---------:|:--------:| | Version | 48+ | 11+ | 25+ | 40+ | 9+ | | Checked | | | | | |
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.
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: [email protected].
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).