Skip to content

Commit

Permalink
wip: doc
Browse files Browse the repository at this point in the history
  • Loading branch information
eddort committed Aug 30, 2021
1 parent 47682e2 commit a683bd3
Showing 1 changed file with 64 additions and 1 deletion.
65 changes: 64 additions & 1 deletion packages/dotto.x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ point changes
<br>

# Status

:warning: :warning: :warning:

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

## Combine stores
# Computed

## Combine your stores

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

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

user.set('id', 'some_other_id')
```

## Computed operators

### `take`

- get value and subscribe to this paths

### `deep`

- get value and subscribe to all store

# Use with React

Install `dotto.x` binding to React:

**Using npm**

```sh
npm i @dotto.x/react
```

**Using yarn**

```sh
yarn add @dotto.x/react
```

**store.js**

```ts
import { createStore, computed, take, update } from 'dotto.x'

const user = createStore({ name: 'John', id: 'some_id' })
const projects = createStore({
some_id: { name: 'Portfolio' },
some_other_id: { name: 'Hell' }
})

export const targetProject = computed(() => {
let userId = take(user, 'id')
return take(projects, userId)
})

export const changeUser = (newUser) => {
return update(user, () => newUser)
}
```

**ProjectCard.jsx**

```jsx
import { useStore } from '@dotto.x/react'
import { targetProject } from './store'

export const ProjectCard = () => {
const project = useStore(targetProject)
return <div>{project.name}</div>
}
```

0 comments on commit a683bd3

Please sign in to comment.