Greetings ladies and gentlemen! In this article, I will introduce the Biscuit-store JavaScript library.
Description
Biscuit is a multifunctional, flexible, modular tool for creating and conveniently working with managed state containers in JavaScript applications.
The main objectives of the article
Tell about the biscuit-store and its goals;
Comparison with other similar tools;
Give a brief overview of the functionality.
Here I will not dive under the hood, but will only give a brief overview.
Pros of the biscuit-store
Striving for simplicity of execution;
-
;
;
Middleware;
;
;
;
.
core โ 18Kb, Gzip: 6.2 ( CommonJs);
react โ 6.8, Gzip: 2.0;
adapter โ 9.6, Gzip: 3.5 ( CommonJs);
:
Internet-explorer 11+;
Chrome 48+;
Opera 25+;
Mozilla firefox 40+;
Safari 9+.
TypeScript.
?
, JavaScript state-management, : redux mobx.
Redux
, 2kB js . redux . C redux . .
, , .
,
GitHub , . , , -, . , โฆ - , . Redux-utils , .
.
, 2015, , . 2021 JavaScript. , middleware, redux-saga redux-thunk. : .
Redux โฆ . - -, - reselect, reducers switch โ - redux-actions. .
: - .
Redux - , , , .
Mobx
mobx:
โ, , . โ.
redux - , , mobx - state-management. : โ , ยป.
โ , , , , . , , โฆ , , .
. , .
Biscuit
biscuit-store - redux mobx. , . , .
, biscuit , .
: ยซ ?ยป, โฆ - , biscuit :
;
, , , ;
, .
,
, ( ).
redux, , . , Biscuit-store .
import { createStore } from '@biscuit-store/core';
export const { store, actions } = createStore({
name: 'duck',
initial: { value: '' },
});
. . , .
, , .
import { createStore } from '@biscuit-store/core';
import { adapter } from './adapter';
export const { store, actions } = createStore({
name: 'duck',
initial: { value: '' },
actions: {
duckSwim: 'duck/swim',
duckFly: 'duck/fly',
duckQuack: 'duck/quack',
},
middleware: [adapter]
});
actions , -, , . .
import { createAdapter } from '@biscuit-store/adapter';
const { action, connect } = createAdapter();
action('duck/swim', () => {
return { value: 'duck flews' };
});
action('duck/fly', () => {
return { value: 'duck flews' };
});
action('duck/quack', (payload, state, { send }) => {
// This is an asynchronous way of transmitting the payload
send({ value: 'duck quacks' });
});
export const adapter = connect;
Adapter is a middleware module that allows you to tie logic to states.
Our duck is ready to go to the big world.
Let's check what she is capable of.
import { actions, store } from './store/duck'
const { duckQuack } = actions;
store.subscribe((state) => {
console.log(state.value); // 'duck quacks'
})
duckQuack.dispatch();
You can also do it like this:
import { actions } from './store/duck'
const { duckQuack } = actions;
duckQuack.dispatch().after((current) => {
console.log(current); // 'duck quacks'
});
And this is how it will look in React .
import { observer, useDispatch } from '@biscuit-store/react';
import { actions } from './store/duck';
const { duckQuack } = actions;
export default observer(
({ value }) => {
const [setQuack] = useDispatch(duckQuack);
return (
<div className='DuckWrapper'>
<p>action: {value}</p>
<button onClick={setQuack}>Duck quacks</button>
</div>
);
},
[duckQuack]
);
Here's a small demo .
That's all, thanks for your attention!
Biscuit-store is young and needs support
Biscuit is still very young and in beta testing.
If you like this library, please help it grow as an asterisk on GitHub '