Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/florianguyonnet/feathers-mobx

implementation of feathers client for mobx
https://github.com/florianguyonnet/feathers-mobx

Last synced: 3 months ago
JSON representation

implementation of feathers client for mobx

Lists

README

        

## feathers-mobx

> Inplement feathers client into your mobx store

**feathers-mobx** is an integration of the Feathers Client for `mobx`.
It can be used with any mobx client like `react-mobx` and `vue-mobx`.

#### [documentation](https://florianguyonnet.github.io/feathers-mobx/#/)

#### [example](example/)

## Quick start

### installation

`yarn add feathers-mobx`

### usage

```js
//

import io from 'socket.io-client';
import feathers from '@feathersjs/feathers';
import socketio from '@feathersjs/socketio-client';

import { createServiceStore, createAuthStore } from 'feathers-mobx';

const socket = io('http://localhost:3030');
const client = feathers();

client.configure(socketio(socket));

const options = {};

export default {
todoStore: createServiceStore(feathers, 'todos', options),
userStore: createServiceStore(feathers, 'users', options),
authStore: createAuthStore(feathers, options),
};
```

```js
//

import React, { useEffect } from 'react';
import { observer } from 'mobx-react';

import useStores from '../hooks/useStores';

export default observer(() => {
const { todoStore } = useStores();

useEffect(() => {
todoStore.find();
}, []);

return (


{todoStore.isFindPending && 'loading...'}

{todoStore.errorOnFind?.message}

{todoStore.items?.map((todo) => (
{todo.name}

))}

);
});
```

### namespaces

Namespaces is a feature designed to handle different sets of items at the same time.

```js
//

import React, { useEffect } from 'react';
import { observer } from 'mobx-react';

import useStores from '../hooks/useStores';

export default observer(() => {
const { todoStore } = useStores();

useEffect(() => {
todoStore.find({
namespace: 'foo',
});
todoStore.get({
namespace: 'bar',
});
}, []);

return (


{todoStore.namespaces.bar.item?.name}

{todoStore.namespaces.foo.isFindPending && 'loading...'}

{todoStore.namespaces.foo.errorOnFind?.message}

{todoStore.namespaces.foo.items?.map((todo) => (
{todo.name}

))}

);
});
```

`update`, `patch` and `remove` actions are not scoped in each namespaces. So, the following code will not work:

```js
todoStore.namespaces.foo.isUpdatePending; // NO
todoStore.isUpdatePending; // YES
```

## License

MIT