Skip to content

Commit ef447c7

Browse files
committed
docs(README): description, usage, deps, props etc
1 parent 13191f8 commit ef447c7

File tree

1 file changed

+63
-130
lines changed

1 file changed

+63
-130
lines changed

README.md

Lines changed: 63 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,181 +1,114 @@
1-
# TSDX React w/ Storybook User Guide
21

3-
Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
2+
# React MQTT Workflow Manager
43

5-
> This TSDX setup is meant for developing React component libraries (not apps!) that can be published to NPM. If you’re looking to build a React-based app, you should use `create-react-app`, `razzle`, `nextjs`, `gatsby`, or `react-static`.
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).
65

7-
> If you’re new to TypeScript and React, checkout [this handy cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet/)
86

9-
## Commands
10-
11-
TSDX scaffolds your new library inside `/src`, and also sets up a [Parcel-based](https://parceljs.org) playground for it inside `/example`.
12-
13-
The recommended workflow is to run TSDX in one terminal:
7+
## Installation
148

159
```bash
16-
npm start # or yarn start
10+
npm install @flowbuild/react-mqtt-workflow-manager --save
1711
```
18-
19-
This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
20-
21-
Then run either Storybook or the example playground:
22-
23-
### Storybook
24-
25-
Run inside another terminal:
12+
or
2613

2714
```bash
28-
yarn storybook
15+
yarn add @flowbuild/react-mqtt-workflow-manager
2916
```
17+
## Dependencies
3018

31-
This loads the stories from `./stories`.
32-
33-
> NOTE: Stories should reference the components as if using the library, similar to the example playground. This means importing from the root project directory. This has been aliased in the tsconfig and the storybook webpack config as a helper.
34-
35-
### Example
36-
37-
Then run the example inside another:
19+
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.
3820

3921
```bash
40-
cd example
41-
npm i # or yarn to install dependencies
42-
npm start # or yarn start
22+
npm i react@18 react-dom@18
4323
```
24+
## Usage
4425

45-
The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. **No symlinking required**, we use [Parcel's aliasing](https://parceljs.org/module_resolution.html#aliases).
4626

47-
To do a one-off build, use `npm run build` or `yarn build`.
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.
4828

49-
To run tests, use `npm test` or `yarn test`.
29+
```jsx
30+
// App.tsx
5031

51-
## Configuration
32+
import * as React from 'react';
5233

53-
Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
34+
import { Provider } from 'react-redux';
35+
import { WorkflowManager, WorkflowManagerConfig } from '@flowbuild/react-mqtt-workflow-manager';
5436

55-
### Jest
37+
import { store } from './store'; // Your redux store
5638

57-
Jest tests are set up to run with `npm test` or `yarn test`.
5839

59-
### Bundle analysis
40+
WorkflowManagerConfig.setStore(store);
6041

61-
Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`.
62-
63-
#### Setup Files
64-
65-
This is the folder structure we set up for you:
66-
67-
```txt
68-
/example
69-
index.html
70-
index.tsx # test your component here in a demo app
71-
package.json
72-
tsconfig.json
73-
/src
74-
index.tsx # EDIT THIS
75-
/test
76-
blah.test.tsx # EDIT THIS
77-
/stories
78-
Thing.stories.tsx # EDIT THIS
79-
/.storybook
80-
main.js
81-
preview.js
82-
.gitignore
83-
package.json
84-
README.md # EDIT THIS
85-
tsconfig.json
42+
export const App: React.FC = () => {
43+
return (
44+
<Provider store={store}>
45+
<WorkflowManager
46+
brokerUrl="ws://broker.mqttdashboard.com:8000/mqtt"
47+
options={{
48+
clientId: `clientId-${Math.random().toString(36).substring(2, 9)}`,
49+
keepalive: 60,
50+
}}
51+
>
52+
{/* Your child component here */}
53+
</WorkflowManager>
54+
</Provider>
55+
);
56+
};
8657
```
8758

88-
#### React Testing Library
89-
90-
We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this.
91-
92-
### Rollup
93-
94-
TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
95-
96-
### TypeScript
97-
98-
`tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.
99-
100-
## Continuous Integration
59+
## Properties
10160

102-
### GitHub Actions
61+
Property | Type | Required | Description
62+
--- | --- | --- | ---
63+
`brokerUrl` | *string* | false | URL to connect to broker. Use full URL like ws://
64+
`options` | *IClientOptions* | false | MQTT client options. See [MQTT.js](https://github.com/mqttjs/MQTT.js/blob/main/types/lib/client-options.d.ts).
10365

104-
Two actions are added by default:
10566

106-
- `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
107-
- `size` which comments cost comparison of your library on every pull request using [size-limit](https://github.com/ai/size-limit)
67+
## Running locally
10868

109-
## Optimizations
69+
Clone o projeto
11070

111-
Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
112-
113-
```js
114-
// ./types/index.d.ts
115-
declare var __DEV__: boolean;
116-
117-
// inside your code...
118-
if (__DEV__) {
119-
console.log('foo');
120-
}
71+
```bash
72+
git clone https://github.com/flow-build/react-mqtt-workflow-manager.git
12173
```
12274

123-
You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
124-
125-
## Module Formats
126-
127-
CJS, ESModules, and UMD module formats are supported.
128-
129-
The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
130-
131-
## Deploying the Example Playground
132-
133-
The Playground is just a simple [Parcel](https://parceljs.org) app, you can deploy it anywhere you would normally deploy that. Here are some guidelines for **manually** deploying with the Netlify CLI (`npm i -g netlify-cli`):
75+
Entre no diretório do projeto
13476

13577
```bash
136-
cd example # if not already in the example folder
137-
npm run build # builds to dist
138-
netlify deploy # deploy the dist folder
78+
cd react-mqtt-workflow-manager
13979
```
14080

141-
Alternatively, if you already have a git repo connected, you can set up continuous deployment with Netlify:
81+
Instale as dependências
14282

14383
```bash
144-
netlify init
145-
# build command: yarn build && cd example && yarn && yarn build
146-
# directory to deploy: example/dist
147-
# pick yes for netlify.toml
84+
npm install
14885
```
14986

150-
## Named Exports
151-
152-
Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.
87+
Inicie o servidor
15388

154-
## Including Styles
89+
```bash
90+
npm run dev
91+
```
15592

156-
There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.
93+
```bash
94+
cd app
95+
```
15796

158-
For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.
97+
```bash
98+
npm install
99+
```
159100

160-
## Publishing to NPM
101+
```bash
102+
npm run start
103+
```
161104

162-
We recommend using [np](https://github.com/sindresorhus/np).
163105

164-
## Usage with Lerna
106+
## Authors
165107

166-
When creating a new package with TSDX within a project set up with Lerna, you might encounter a `Cannot resolve dependency` error when trying to run the `example` project. To fix that you will need to make changes to the `package.json` file _inside the `example` directory_.
108+
[@wallace-sf](https://www.github.com/wallace-sf)
167109

168-
The problem is that due to the nature of how dependencies are installed in Lerna projects, the aliases in the example project's `package.json` might not point to the right place, as those dependencies might have been installed in the root of your Lerna project.
169110

170-
Change the `alias` to point to where those packages are actually installed. This depends on the directory structure of your Lerna project, so the actual path might be different from the diff below.
111+
## License
171112

172-
```diff
173-
"alias": {
174-
- "react": "../node_modules/react",
175-
- "react-dom": "../node_modules/react-dom"
176-
+ "react": "../../../node_modules/react",
177-
+ "react-dom": "../../../node_modules/react-dom"
178-
},
179-
```
113+
[MIT](https://choosealicense.com/licenses/mit/)
180114

181-
An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead. [However, that might cause other problems.](https://github.com/palmerhq/tsdx/issues/64)

0 commit comments

Comments
 (0)