Skip to content

Commit a683bd3

Browse files
committed
wip: doc
1 parent 47682e2 commit a683bd3

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

packages/dotto.x/README.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ point changes
2828
<br>
2929

3030
# Status
31+
3132
:warning: :warning: :warning:
3233

3334
**Project in progress right now. Please wait for 1.0.0 version.**
@@ -83,7 +84,9 @@ user.watch('name', value => {
8384
userName.set('name', 'John Constantine')
8485
```
8586

86-
## Combine stores
87+
# Computed
88+
89+
## Combine your stores
8790

8891
Subscribe to store or part of stores using take. Take — computed operator.
8992

@@ -105,3 +108,63 @@ targetProject.subscribe(value => /* do something */)
105108

106109
user.set('id', 'some_other_id')
107110
```
111+
112+
## Computed operators
113+
114+
### `take`
115+
116+
- get value and subscribe to this paths
117+
118+
### `deep`
119+
120+
- get value and subscribe to all store
121+
122+
# Use with React
123+
124+
Install `dotto.x` binding to React:
125+
126+
**Using npm**
127+
128+
```sh
129+
npm i @dotto.x/react
130+
```
131+
132+
**Using yarn**
133+
134+
```sh
135+
yarn add @dotto.x/react
136+
```
137+
138+
**store.js**
139+
140+
```ts
141+
import { createStore, computed, take, update } from 'dotto.x'
142+
143+
const user = createStore({ name: 'John', id: 'some_id' })
144+
const projects = createStore({
145+
some_id: { name: 'Portfolio' },
146+
some_other_id: { name: 'Hell' }
147+
})
148+
149+
export const targetProject = computed(() => {
150+
let userId = take(user, 'id')
151+
return take(projects, userId)
152+
})
153+
154+
export const changeUser = (newUser) => {
155+
return update(user, () => newUser)
156+
}
157+
```
158+
159+
**ProjectCard.jsx**
160+
161+
```jsx
162+
import { useStore } from '@dotto.x/react'
163+
import { targetProject } from './store'
164+
165+
export const ProjectCard = () => {
166+
const project = useStore(targetProject)
167+
return <div>{project.name}</div>
168+
}
169+
```
170+

0 commit comments

Comments
 (0)