项目作者: simbo

项目描述 :
A small, immutable and framework agnostic state store using rxjs and immer with native typescript support.
高级语言: TypeScript
项目地址: git://github.com/simbo/small-store.git
创建时间: 2020-12-13T11:46:49Z
项目社区:https://github.com/simbo/small-store

开源协议:MIT License

下载


🗃 Small Store

npm Package Version
Libraries.io dependency status for latest release
Coveralls github
Last CI Workflow Status
GitHub Repo
License MIT

A small, immutable, reactive and framework agnostic state store under 2KB
powered by rxjs and immer with native typescript support. To be used with
vanilla, react, preact, angular, vue or whatever you like.


Quick Start

  1. import { Actions, Store } from 'small-store';
  2. // state declaration
  3. interface CounterState {
  4. count: number;
  5. }
  6. // actions
  7. enum CounterAction {
  8. Increment = 'increment',
  9. Decrement = 'decrement'
  10. }
  11. // action functions
  12. const counterActions: Actions<CounterState, CounterAction> = {
  13. [CounterAction.Increment]: () => state => {
  14. state.count++;
  15. return state;
  16. },
  17. [CounterAction.Decrement]: () => state => {
  18. state.count--;
  19. return state;
  20. }
  21. };
  22. // the initial state
  23. const initialCounterState: CounterState = {
  24. count: 0
  25. };
  26. // creating the store
  27. const counterStore = new Store<CounterState, CounterAction>(
  28. initialCounterState,
  29. counterActions
  30. );
  31. // subscribing to the store's state
  32. counterStore.state$.subscribe(state => console.log(state));
  33. // dispatching actions
  34. counterStore.dispatch(CounterAction.Increment);
  35. counterStore.dispatch(CounterAction.Increment);
  36. counterStore.dispatch(CounterAction.Decrement);

See details and more examples in the docs.

Documentation

Visit simbo.codes/small-store to read
the documentation and the examples.

Development

Requirements: node.js >=14, yarn >=1.22

  1. # build using microbundle
  2. yarn build
  3. # watch and rebuild
  4. yarn build:watch
  5. # lint using prettier and eslint
  6. yarn lint
  7. # test using jest
  8. yarn test
  9. # watch and retest
  10. yarn test:watch
  11. # open coverage in default browser
  12. yarn coverage:open
  13. # check everything
  14. yarn preflight

Docs

Requirements: docker

  1. # pull slate image
  2. docker pull slatedocs/slate
  3. # serve docs on localhost:4567
  4. yarn docs:serve
  5. # build docs to ./docs-build
  6. yarn docs:build

License and Author

MIT © Simon Lepel