Skip to content

Commit 471ece3

Browse files
committed
docs: add read me sections
1 parent ef447c7 commit 471ece3

File tree

1 file changed

+107
-15
lines changed

1 file changed

+107
-15
lines changed

README.md

Lines changed: 107 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11

22
# React MQTT Workflow Manager
33

4-
React MQTT Workflow Manager is a React component library designed to wrap all MQTT pub/sub logic behind the scenes. This manager comunicates with your broker to dispatch actions in your front-end application. The library also was designed to work with [Workflow API Layer](https://github.com/flow-build/workflow-api).
4+
React MQTT Workflow Manager is a React component library designed to wrap all [MQTT](https://mqtt.org/) sub logic behind the scenes. It deals only with events, no commands. The manager comunicates with your broker to dispatch actions in your front-end application. The library is focused to work with [Workflow API Layer](https://github.com/flow-build/workflow-api).
55

6+
## Table of contents
67

7-
## Installation
8+
- [Installation](#installation)
9+
- [Dependencies](#dependencies)
10+
- [Usage](#usage)
11+
- [Properties](#properties)
12+
- [WorkflowManagerConfig](#workflowmanagerconfig)
13+
- [Hooks](#hooks)
14+
- [Running locally](#running-locally)
15+
- [Authors](#authors)
16+
- [License](#license)
17+
18+
## [Installation](installation)
819

920
```bash
1021
npm install @flowbuild/react-mqtt-workflow-manager --save
@@ -14,19 +25,36 @@ or
1425
```bash
1526
yarn add @flowbuild/react-mqtt-workflow-manager
1627
```
17-
## Dependencies
28+
## [Dependencies](dependencies)
1829

1930
The `WorkflowManager` component [peer depends](https://docs.npmjs.com/files/package.json#peerdependencies) on the [React](https://www.npmjs.com/package/react) and [React DOM](https://www.npmjs.com/package/react-dom) in version 18.
2031

2132
```bash
2233
npm i react@18 react-dom@18
2334
```
24-
## Usage
35+
## [Usage](usage)
36+
37+
38+
1. Before the componente usage, set the store with `WorkflowManagerConfig.setStore`.
39+
40+
```tsx
41+
// App.tsx
42+
43+
import * as React from 'react';
44+
45+
import { WorkflowManagerConfig } from '@flowbuild/react-mqtt-workflow-manager';
46+
47+
import { store } from './store'; // Your redux store
48+
2549

50+
WorkflowManagerConfig.setStore(store);
51+
52+
// ...
53+
```
2654

27-
1. Wrap you application with ``WorkflowManager`` component. Don't forget to set your store with ``WorkflowManagerConfig.setStore`` before the componente usage. This is important, because the library needs redux functions to work correctly.
55+
2. Wrap your application with `WorkflowManager`.
2856

29-
```jsx
57+
```tsx
3058
// App.tsx
3159

3260
import * as React from 'react';
@@ -56,59 +84,123 @@ export const App: React.FC = () => {
5684
};
5785
```
5886

59-
## Properties
87+
3. Lastly, set `workflowManagerReducer` to your store reducers.
88+
89+
```ts
90+
import { configureStore, createSlice } from '@reduxjs/toolkit';
91+
92+
import { workflowManagerReducer, WorkflowManagerConfig } from '@flowbuild/react-mqtt-workflow-manager';
93+
94+
const myAppSlice = createSlice({
95+
name: '@myApp',
96+
...
97+
});
98+
99+
export const store = configureStore({
100+
reducer: { myApp: myAppSlice.reducer, workflowManagerReducer },
101+
});
102+
103+
```
104+
105+
## [Properties](properties)
60106

61107
Property | Type | Required | Description
62108
--- | --- | --- | ---
63109
`brokerUrl` | *string* | false | URL to connect to broker. Use full URL like ws://
64110
`options` | *IClientOptions* | false | MQTT client options. See [MQTT.js](https://github.com/mqttjs/MQTT.js/blob/main/types/lib/client-options.d.ts).
65111

112+
## [WorkflowManagerConfig](workflowmanagerconfig)
113+
114+
The library also exposes methods and utilities for your commodity. They can be used out of the context of react components.
66115

67-
## Running locally
116+
### setStore(store)
68117

69-
Clone o projeto
118+
The library use your redux store to dispatch actions. This is used to dispatch internal actions control and for your applications.
119+
120+
### getMqttClient()
121+
122+
A utility method to be used out of context to react components. Be careful; the method must be able to return `null` if an error happens when setting connect. [See here](https://github.com/mqttjs/MQTT.js/blob/main/README.md#client).
123+
124+
### subscribe(topic/topic array/topic object, [options])
125+
126+
Works like exactly like [mqtt#subscribe](https://github.com/mqttjs/MQTT.js/blob/main/README.md#mqttclientsubscribetopictopic-arraytopic-object-options-callback), but the library implements validations and internal rules.
127+
128+
### subscribe(topic/topic array/topic object, [options])
129+
130+
Works like exactly like [mqtt#unsubscribe](https://github.com/mqttjs/MQTT.js/blob/main/README.md#mqttclientunsubscribetopictopic-array-options-callback), but the library implements validations and internal rules.
131+
132+
## [Hooks](hooks)
133+
134+
Some hooks are exported for commodity.
135+
136+
### useMqtt()
137+
138+
The hook returns a object contaning `client`, `status` and `error`.
139+
140+
Property | Type | Default value | Description
141+
--- | --- | --- | ---
142+
`client` | *MqttClient* | `null` | See type [here](https://github.com/mqttjs/MQTT.js/blob/main/types/lib/client.d.ts)
143+
`status` | *string* | `offline` | `connecting`, `connected`, `disconnected`, `reconnecting`, `offline` or `error`.
144+
`error` | *Error* | `null` |
145+
146+
### useSubscribe()
147+
148+
Returns `WorkflowManagerConfig.subscribe` for your commodity.
149+
150+
### UseUnsubscribe()
151+
152+
Returns `WorkflowManagerConfig.unsubscribe` for your commodity.
153+
154+
## [Running locally](running-locally)
155+
156+
Clone the project
70157

71158
```bash
72159
git clone https://github.com/flow-build/react-mqtt-workflow-manager.git
73160
```
74161

75-
Entre no diretório do projeto
162+
Go to the project directory
76163

77164
```bash
78165
cd react-mqtt-workflow-manager
79166
```
80167

81-
Instale as dependências
168+
Install dependencies
82169

83170
```bash
84171
npm install
85172
```
86173

87-
Inicie o servidor
174+
Start the development server
88175

89176
```bash
90177
npm run dev
91178
```
92179

180+
Go to the project example directory
181+
93182
```bash
94183
cd app
95184
```
96185

186+
Install de example dependencies
187+
97188
```bash
98189
npm install
99190
```
100191

192+
Start the example application
193+
101194
```bash
102195
npm run start
103196
```
104197

105198

106-
## Authors
199+
## [Authors](authors)
107200

108201
[@wallace-sf](https://www.github.com/wallace-sf)
109202

110203

111-
## License
204+
## [License](license)
112205

113206
[MIT](https://choosealicense.com/licenses/mit/)
114-

0 commit comments

Comments
 (0)