Skip to content

Commit b22504e

Browse files
committed
docs: get started
1 parent 4dcbe17 commit b22504e

File tree

11 files changed

+386
-7
lines changed

11 files changed

+386
-7
lines changed

.github/workflows/docs.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
cache-dependency-path: yarn.lock
4242
- name: Install dependencies
4343
run: yarn --immutable
44+
- name: Build packages
45+
run: yarn build
4446
- name: Build Website
4547
run: yarn workspace amos-website build
4648
- name: Setup Pages

.yarn/install-state.gz

49.5 KB
Binary file not shown.

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,9 @@
6363
"test": "jest",
6464
"check:circle": "dpdm -T packages/*/src/**/*.*"
6565
},
66-
"packageManager": "[email protected]+sha512.837566d24eec14ec0f5f1411adb544e892b3454255e61fdef8fd05f3429480102806bac7446bc9daff3896b01ae4b62d00096c7e989f1596f2af10b927532f39"
66+
"packageManager": "[email protected]+sha512.837566d24eec14ec0f5f1411adb544e892b3454255e61fdef8fd05f3429480102806bac7446bc9daff3896b01ae4b62d00096c7e989f1596f2af10b927532f39",
67+
"dependencies": {
68+
"@docusaurus/remark-plugin-npm2yarn": "^3.5.2",
69+
"@docusaurus/theme-live-codeblock": "^3.5.2"
70+
}
6771
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,77 @@
11
# 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.

website/docs/01-Introduction/02-Installation.md

-1
This file was deleted.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Setup
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# How to design state in large-scale applications

website/docusaurus.config.ts

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const config: Config = {
3030
locales: ['en'],
3131
},
3232

33+
themes: [
34+
'@docusaurus/theme-live-codeblock',
35+
],
36+
3337
presets: [
3438
[
3539
'classic',
@@ -39,6 +43,15 @@ const config: Config = {
3943
// Please change this to your repo.
4044
// Remove this to remove the "edit this page" links.
4145
editUrl: 'https://github.com/amos-project/amos/tree/main/website/',
46+
remarkPlugins: [
47+
[
48+
require('@docusaurus/remark-plugin-npm2yarn'),
49+
{
50+
sync: true,
51+
converters: ['yarn', 'pnpm'],
52+
},
53+
],
54+
],
4255
},
4356
theme: {
4457
customCss: './src/css/custom.css',
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
import * as Amos from 'amos';
3+
import * as AmosReact from 'amos/react';
4+
5+
const require = (m: string) => {
6+
return {
7+
'amos': Amos,
8+
'amos/react': AmosReact,
9+
}[m]
10+
}
11+
12+
// Add react-live imports you need here
13+
const ReactLiveScope = {
14+
React,
15+
...Amos,
16+
...AmosReact,
17+
require,
18+
};
19+
20+
export default ReactLiveScope;

0 commit comments

Comments
 (0)