Skip to content

Commit

Permalink
📝 docs: add Readme document
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Apr 2, 2023
1 parent 1a7bc9c commit f05ec4b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,48 @@ const Wrapper = () => {
It become a component, can be used in any other app.
# createStoreUpdater
`createStoreUpdater` is a function for updating the value of a specified key in the Store.
## Parameters
`createStoreUpdater` takes a `StoreApi` object as its parameter, which contains methods for manipulating the Store, such as `getState`, `setState`, `subscribe`, and `destroy`.
`createStoreUpdater` returns a function that takes the following parameters:
- `key`: the key in the Store that needs to be updated;
- `value`: the value that needs to be updated;
- `deps`: an array of dependencies, defaults to `[value]`;
- `setStoreState`: an optional callback function for updating the Store state, defaults to `storeApi.setState`.
## Return Value
`createStoreUpdater` returns a function that updates the value of the specified key in the Store.
## Example
```typescript
import { createStoreUpdater } from 'path/to/createStoreUpdater';
import { useStore } from 'path/to/useStore';

interface User {
name: string;
age: number;
}

const storeApi = useStore<User>({ name: '', age: 0 });
const updateUser = createStoreUpdater(storeApi);

// Update name
updateUser('name', 'John Doe');

// Update age
updateUser('age', 18);
```
In the example above, we first create a Store using `useStore`, then create an updater `updateUser` using `createStoreUpdater`, and finally update the `name` and `age` in the Store by calling `updateUser`.
## License
[MIT](./LICENSE)
2 changes: 0 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,6 @@ const Wrapper = () => {
这样它就变成了一个组件,可以被其他任何应用消费。
好的,以下是 `createStoreUpdater` 的说明文档:
## createStoreUpdater
`createStoreUpdater` 是一个用于更新 Store 中指定 key 的值的函数。
Expand Down

0 comments on commit f05ec4b

Please sign in to comment.