reaxes-toolkit 1.0.1 → 1.0.3

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 (3) hide show
  1. package/changelog.md +6 -1
  2. package/package.json +1 -1
  3. package/readme.md +70 -74
package/changelog.md CHANGED
@@ -1,4 +1,9 @@
1
- # 1.0.0-Beta.1
1
+ # 1.0.2
2
+ * doc fixed & optimized
3
+ # 1.0.1
4
+ * doc optimized
5
+
6
+ # 1.0.0
2
7
  * 将orzImport转移至reaxes-utils中并改名为xImport
3
8
  * 将orzPending改名为rexaStatus , 并且所有toolkit函数统一使用rexa作为前缀
4
9
  * 清理了rexaStatus冗余的异步逻辑,现在已改为同步修改store
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reaxes-toolkit",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Toolkit Based on `reaxes`",
5
5
  "main": "esm/index.js",
6
6
  "module": "esm/index.js",
package/readme.md CHANGED
@@ -19,41 +19,41 @@ $ npm i -S reaxes-toolkit
19
19
 
20
20
  ### 🛠 在 `reaxel` 中使用
21
21
  ```tsx
22
- import { rexaStatus } from 'reaxes-toolkit';
23
22
  //reaxels/user-bio.ts
23
+ import { rexaStatus } from 'reaxes-toolkit';
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,29 @@ 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 : { status,setStatus } } = useRef(rexaStatus());
87
+ const [ data , setData ] = useState(null);
88
+
89
+ useEffect(() => {
90
+ fetch(`api.com`).
91
+ then(( data ) => {
92
+ setData(data);
93
+ setStatus({pending:false});
94
+ }).
95
+ catch(e => {
96
+ setStatus({pending:false,error:e});
97
+ });
98
+ },[]);
99
+
100
+ if( status.pending ) {
101
+ return <div>pending...</div>;
102
+ }
103
+
104
+ if( status.error ) {
105
+ return <div>Error!</div>;
106
+ }
107
+
108
+ return <div>{ data }</div>;
113
109
  });
114
110
 
115
111
  import { rexaStatus } from 'reaxes-toolkit';