react-sync-ui 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# react-sync-ui
|
|
2
2
|
|
|
3
|
-
`react-sync-ui`
|
|
3
|
+
`react-sync-ui` promisify your React Components and make your UI awaitable.
|
|
4
4
|
|
|
5
5
|
## usage example
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
await syncAlert("Invalid password, keep trying");
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
await syncAlert(`Congratulation
|
|
17
|
+
await syncAlert(`Congratulation ${name}, you are logged in`);
|
|
18
18
|
}}
|
|
19
19
|
>
|
|
20
20
|
Login
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
|
|
24
24
|

|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
into the promisified
|
|
26
|
+
`react-sync-ui` provides function `makeSyncUI<InputData, ResolveValue>` which transform your declarative React Components
|
|
27
|
+
into the promisified awaitable functions.
|
|
28
28
|
|
|
29
29
|
```tsx
|
|
30
30
|
// defining of your custom react-sync-ui component
|
|
@@ -38,23 +38,25 @@ export const syncAlert = makeSyncUI<string, void>((props) => (
|
|
|
38
38
|
);
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
## what
|
|
41
|
+
## what is `react-sync-ui` solving?
|
|
42
42
|
|
|
43
43
|
For a long time, I did not like that React's functional way of declarative UI forced you to write nice UI code, but with ugly distributed business logic.
|
|
44
44
|
When you have a complex business use case which is a composition of asynchronous actions like HTTP requests together with user interactions,
|
|
45
|
-
your business logic code is distributed over many async React handlers and it's really hard to understand the sequence of
|
|
45
|
+
your business logic code is distributed over many async React handlers and it's really hard to understand the sequence of business logic.
|
|
46
46
|
|
|
47
|
-
People very often solve this problem by dependencies in the `useEffect(..., [dependency])` which transfer
|
|
48
|
-
When you change the variable value, the different components will register the dependency change
|
|
49
|
-
With this event-driven programming, your code complexity is
|
|
47
|
+
People very often solve this problem by dependencies in the `useEffect(..., [dependency])` which transfer React logic to the event-driven architecture.
|
|
48
|
+
When you change the dependency variable value, the different components will register the dependency change, and `useEffect` will be re-called.
|
|
49
|
+
With this event-driven programming style, your code complexity is 1000 times more complex, and your newcomer programmes who see the code have the business workflow is.
|
|
50
50
|
|
|
51
51
|
A nice solution for this problem is to wrap your declarative React components into Promise wrappers which split your UIs into many
|
|
52
52
|
smaller functions that can be simply composed together inside of your Javascript function and you'll get very complex business logic in just a few lines of code.
|
|
53
53
|
|
|
54
|
-
Thanks to `react-sync-ui` you
|
|
54
|
+
Thanks to `react-sync-ui` you can simply promisify your React Components UI and make your UI awaitable.
|
|
55
55
|
|
|
56
56
|
And that's why `react-sync-ui` was created. ❤
|
|
57
57
|
|
|
58
|
+
PS: i took inspiration from awesome functions: `window.alert`, `window.confirm` and `window.prompt`.
|
|
59
|
+
|
|
58
60
|
## Installation
|
|
59
61
|
|
|
60
62
|
```bash
|