|
1 | 1 | # Get started
|
| 2 | + |
| 3 | +Amos is an all-in-one, modern state management solution. It incorporates all the best features found |
| 4 | +in state management libraries to date, including decentralization (atomic), immutability, |
| 5 | +predictability, strong typing, and simplicity. Additionally, its unique data-structure-based state |
| 6 | +node design allows for comprehensive state management without the need for external tools. Amos also |
| 7 | +includes commonly used solutions within the state management ecosystem, such as persistence, |
| 8 | +batching, caching, and concurrency control. |
| 9 | + |
| 10 | +With these features, Amos offers a complete capability and concept set that enables effortless state |
| 11 | +management in large and expanding applications, with a near-zero marginal cost. |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +Amos has only one npm package, making installation extremely simple. |
| 16 | + |
| 17 | +```bash npm2yarn |
| 18 | +npm install amos |
| 19 | +``` |
| 20 | + |
| 21 | +For an enhanced development experience, you may need to set up devtools extensions and modify |
| 22 | +compiler configurations. You can find complete information on how to do this [here](./02-setup.md). |
| 23 | + |
| 24 | +## Basic Example |
| 25 | + |
| 26 | +```tsx live noInline showLineNumbers |
| 27 | +import { createStore, numberBox } from 'amos'; |
| 28 | +import { Provider, useDispatch, useSelector } from 'amos/react'; |
| 29 | + |
| 30 | +const countBox = numberBox('count'); |
| 31 | + |
| 32 | +const App = React.memo(() => { |
| 33 | + const dispatch = useDispatch(); |
| 34 | + const count = useSelector(countBox); |
| 35 | + return ( |
| 36 | + <div> |
| 37 | + <div>Count: {count}</div> |
| 38 | + <button onClick={() => dispatch(countBox.add(1))}>Click me!</button> |
| 39 | + </div> |
| 40 | + ); |
| 41 | +}); |
| 42 | + |
| 43 | +const store = createStore(); |
| 44 | + |
| 45 | +render( |
| 46 | + <Provider store={store}> |
| 47 | + <App /> |
| 48 | + </Provider>, |
| 49 | +); |
| 50 | +``` |
| 51 | + |
| 52 | +You can click the button above ☝️ to try it out or edit the code. |
| 53 | + |
| 54 | +As you can see, the concepts Amos uses are largely similar to those in other state management |
| 55 | +libraries you're familiar with, such as `store`, `selector`, `dispatch`, and `provider`. However, |
| 56 | +there are some new elements as well: **`box`**, which is somewhat like an `atom` in `Recoil` or |
| 57 | +`Jotai`, but with additional features. For instance, in the example above, `numberBox` and |
| 58 | +`countBox.add(1)` demonstrate one of Amos's unique aspects. By binding the state’s data structure |
| 59 | +with its data node, Amos allows us to avoid implementing a separate data operation interface for |
| 60 | +each state node (or relying on third-party libraries). |
| 61 | + |
| 62 | +In the example above, `count` is a state of type number, and `countBox` is its corresponding state |
| 63 | +node. Since `count` is of numeric type, we use `numberBox` to construct it, enabling `countBox` to |
| 64 | +naturally provide the operations and query methods required for `count`, such as `add`, `mod`, |
| 65 | +`toFixed`, and more. These methods allow us to directly query or modify the value of the `count` |
| 66 | +state. |
| 67 | + |
| 68 | +You can find more detailed information on Amos's concepts [here](./03-concepts.md). |
| 69 | + |
| 70 | +## What's Next |
| 71 | + |
| 72 | +Next, you can go to the [Concepts](./03-concepts.md) page to learn about the core ideas in Amos, or |
| 73 | +explore topics of interest in the menu on the left 👈 of this document. |
| 74 | + |
| 75 | +We recommend starting with our |
| 76 | +article, [How to design state in large-scale applications](./04-how-to), to understand the |
| 77 | +reasoning behind Amos's design and to help you make the most of it. |
0 commit comments