reaxes-toolkit 1.0.1 → 1.0.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme.md +73 -73
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reaxes-toolkit",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Toolkit Based on `reaxes`",
5
5
  "main": "esm/index.js",
6
6
  "module": "esm/index.js",
package/readme.md CHANGED
@@ -22,38 +22,38 @@ $ npm i -S reaxes-toolkit
22
22
  import { rexaStatus } from 'reaxes-toolkit';
23
23
  //reaxels/user-bio.ts
24
24
  export const reaxel_UserBio = reaxel(() => {
25
- const { status,setStatus } = rexaStatus();
26
- const { store , setState , mutate } = createReaxable({
27
- bio : null as string ,
28
- status ,
29
- });
30
-
31
- const fetchBio = () => {
32
- if( store.status.pending ) {
33
- return;
34
- }
35
- new Promise<string>(( resolve , reject ) => {
36
- setStatus({pending : true});
37
- setTimeout(() => {
38
- //Choose which code to comment out to switch different promise results.
39
- resolve(`I'm an software engineer.`);
40
- // reject('403 Forbidden');
41
- } , 2000);
42
- }).
43
- then(( bio ) => {
44
- setState({ bio });
45
- setStatus({ pending : false , error : false });
46
- }).catch(e => {
47
- setStatus({error : e,pending : false})
48
- });
49
- };
50
- const rtn = {
51
- UserBio_Store : store ,
52
- UserBio_SetState : setState ,
53
- UserBio_Mutate : mutate ,
54
- fetchBio ,
55
- };
56
- return () => rtn;
25
+ const { status,setStatus } = rexaStatus();
26
+ const { store , setState , mutate } = createReaxable({
27
+ bio : null as string ,
28
+ status ,
29
+ });
30
+
31
+ const fetchBio = () => {
32
+ if( store.status.pending ) {
33
+ return;
34
+ }
35
+ new Promise<string>(( resolve , reject ) => {
36
+ setStatus({pending : true});
37
+ setTimeout(() => {
38
+ //Choose which code to comment out to switch different promise results.
39
+ resolve(`I'm an software engineer.`);
40
+ // reject('403 Forbidden');
41
+ } , 2000);
42
+ }).
43
+ then(( bio ) => {
44
+ setState({ bio });
45
+ setStatus({ pending : false , error : false });
46
+ }).catch(e => {
47
+ setStatus({error : e,pending : false})
48
+ });
49
+ };
50
+ const rtn = {
51
+ UserBio_Store : store ,
52
+ UserBio_SetState : setState ,
53
+ UserBio_Mutate : mutate ,
54
+ fetchBio ,
55
+ };
56
+ return () => rtn;
57
57
  });
58
58
 
59
59
  //components/UserBio.tsx
@@ -61,20 +61,20 @@ import { useEffect } from 'react';
61
61
  import { reaxel_UserBio } from '../reaxels/user-bio';
62
62
 
63
63
  export default reaxper(() => {
64
- const {fetchBio,UserBio_Store} = reaxel_UserBio();
65
-
66
- React.useEffect(() => {
67
- fetchBio();
68
- } , []);
69
-
70
- if(UserBio_Store.status.error){
71
- return <div>Error Code: {UserBio_Store.status.error}</div>
72
- }
73
- if(UserBio_Store.status.pending){
74
- return <div>pending...</div>
75
- }
76
-
77
- return <div>{ UserBio_Store.bio }</div>;
64
+ const {fetchBio,UserBio_Store} = reaxel_UserBio();
65
+
66
+ React.useEffect(() => {
67
+ fetchBio();
68
+ } , []);
69
+
70
+ if(UserBio_Store.status.error){
71
+ return <div>Error Code: {UserBio_Store.status.error}</div>
72
+ }
73
+ if(UserBio_Store.status.pending){
74
+ return <div>pending...</div>
75
+ }
76
+
77
+ return <div>{ UserBio_Store.bio }</div>;
78
78
  });
79
79
  ```
80
80
 
@@ -83,33 +83,33 @@ export default reaxper(() => {
83
83
  ### 🏗 纯 `React` 示例
84
84
  ```tsx
85
85
  const Test = reaxper(() => {
86
- const { current : {
87
- pendingState,
88
- setError,
89
- setPending
90
- } } = useRef(rexaStatus());
91
- const [ data , setData ] = useState(null);
92
-
93
- useEffect(() => {
94
- fetch(`api.com`).
95
- then(( data ) => {
96
- setData(data);
97
- setPending(false);
98
- }).
99
- catch(e => {
100
- setError(e);
101
- });
102
- },[]);
103
-
104
- if( pendingState.pending ) {
105
- return <div>pending...</div>;
106
- }
107
-
108
- if( pendingState.error ) {
109
- return <div>Error!</div>;
110
- }
111
-
112
- return <div>{ data }</div>;
86
+ const { current : {
87
+ pendingState,
88
+ setError,
89
+ setPending
90
+ } } = useRef(rexaStatus());
91
+ const [ data , setData ] = useState(null);
92
+
93
+ useEffect(() => {
94
+ fetch(`api.com`).
95
+ then(( data ) => {
96
+ setData(data);
97
+ setPending(false);
98
+ }).
99
+ catch(e => {
100
+ setError(e);
101
+ });
102
+ },[]);
103
+
104
+ if( pendingState.pending ) {
105
+ return <div>pending...</div>;
106
+ }
107
+
108
+ if( pendingState.error ) {
109
+ return <div>Error!</div>;
110
+ }
111
+
112
+ return <div>{ data }</div>;
113
113
  });
114
114
 
115
115
  import { rexaStatus } from 'reaxes-toolkit';