reaxes-toolkit 0.0.10 → 1.0.0
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/changelog.md +9 -2
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -0
- package/package.json +11 -13
- package/readme.md +118 -0
- package/types/index.d.ts +1 -0
- package/types/rexaStatus/index.d.ts +10 -0
- package/index.d.ts +0 -1
- package/index.js +0 -2
- package/index.js.map +0 -1
- package/orzPending/index.d.ts +0 -8
package/changelog.md
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
# 0.0.
|
|
2
|
-
|
|
1
|
+
# 1.0.0-Beta.1
|
|
2
|
+
* 将orzImport转移至reaxes-utils中并改名为xImport
|
|
3
|
+
* 将orzPending改名为rexaStatus , 并且所有toolkit函数统一使用rexa作为前缀
|
|
4
|
+
* 清理了rexaStatus冗余的异步逻辑,现在已改为同步修改store
|
|
5
|
+
|
|
6
|
+
# 0.0.12
|
|
7
|
+
修复由于orzMobx is not defined.
|
|
8
|
+
# 0.0.10
|
|
9
|
+
修复由于react-hot-loader/babel引起的打包后产物出现__WEBPACK_EXTERNAL_MODULE的问题
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import*as e from"reaxes";var t={d:(e,r)=>{for(var a in r)t.o(r,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:r[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},r={};t.d(r,{n:()=>o});const a=(e=>{var r={};return t.d(r,e),r})({createReaxable:()=>e.createReaxable});var o=function(){var e=(0,a.createReaxable)({pending:!1,error:!1}),t=e.store,r=e.setState;e.mutate;return{status:t,setStatus:function(e){r(e)}}},n=r.n;export{n as rexaStatus};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esm/index.js","mappings":"yBACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,I,sBCIlF,MAAM,EAJE,CAACI,IACR,IAAIC,EAAI,CAAC,EAAgC,OAA7Bf,EAAoBgB,EAAED,EAAGD,GAAWC,GAGZA,CAAE,CAAE,eAAoB,IAAOE,EAAiD,iBCM9G,IAAMC,EAAa,WACzB,IAAAC,GAAgCC,EAAAA,EAAAA,gBAG7B,CACFC,SAAS,EACTC,OAAQ,IALFC,EAAKJ,EAALI,MAAMC,EAAQL,EAARK,SAAeL,EAANM,OAOtB,MAAO,CACNC,OAAOH,EACPI,UAAS,SAACD,GACTF,EAASE,EACV,EAEF,E","sources":["webpack://mono-reaxes/webpack/bootstrap","webpack://mono-reaxes/webpack/runtime/define property getters","webpack://mono-reaxes/webpack/runtime/hasOwnProperty shorthand","webpack://mono-reaxes/external module \"reaxes\"","webpack://mono-reaxes/./packages/reaxes-toolkit/src/rexaStatus/index.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","var x = (y) => {\n\tvar x = {}; __webpack_require__.d(x, y); return x\n} \nvar y = (x) => (() => (x))\nconst __WEBPACK_NAMESPACE_OBJECT__ = x({ [\"createReaxable\"]: () => (__WEBPACK_EXTERNAL_MODULE_reaxes__.createReaxable) });","/**\r\n * 🌟 **Pending & Error States in the Application** <br>\r\n * These states are **not limited** to data fetching scenarios\r\n * and can be used **in any suitable context**.\r\n *\r\n * 🔹 **Flexible Types:**\r\n * - `Pending (P)` and `Error (E)` **default to `any`**.\r\n * - **Default values:** `false`.\r\n * - **Customizable:** Use generics `<P, E>` to **enforce type constraints**.\r\n */\r\nexport const rexaStatus = <P = any,E = any>() => {\r\n\tconst {store,setState,mutate} = createReaxable<{\r\n\t\tpending:P,\r\n\t\terror:E,\r\n\t}>({\r\n\t\tpending: false as P ,\r\n\t\terror : false as E ,\r\n\t});\r\n\treturn {\r\n\t\tstatus:store,\r\n\t\tsetStatus(status:Partial<typeof store>){\r\n\t\t\tsetState(status);\r\n\t\t}\r\n\t}\r\n};\r\n\r\nimport { createReaxable } from 'reaxes';\r\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","y","x","d","__WEBPACK_EXTERNAL_MODULE_reaxes__","rexaStatus","_createReaxable","createReaxable","pending","error","store","setState","mutate","status","setStatus"],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
}
|
|
2
|
+
"name": "reaxes-toolkit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Toolkit Based on `reaxes`",
|
|
5
|
+
"main": "esm/index.js",
|
|
6
|
+
"module": "esm/index.js",
|
|
7
|
+
"types": "types/index.d.ts",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"reaxes": "^1.1.0",
|
|
10
|
+
"reaxes-utils": "^2.0.0"
|
|
11
|
+
}
|
|
12
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# 🚀 基于 `reaxes` 的工具集
|
|
2
|
+
|
|
3
|
+
## 📦 安装
|
|
4
|
+
```sh
|
|
5
|
+
$ npm i -S reaxes-toolkit
|
|
6
|
+
```
|
|
7
|
+
⚠️ **注意:** `reaxes-toolkit` 依赖 `reaxes` 运行,如果未安装 `reaxes`,则会自动安装。
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 🎯 `rexaStatus`
|
|
12
|
+
|
|
13
|
+
🔹 **简介:**
|
|
14
|
+
`rexaStatus` 是基于 `reaxes` 封装的工具,专注于 `pending` & `error` 状态管理。
|
|
15
|
+
✅ **不仅限于 UI 组件,适用于各种场景**
|
|
16
|
+
✅ `status.pending` / `status.error` 可以是任何值,且默认值均为`false`.你可以传入泛型`<P,E>`来约束`pending`和`error`的类型.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
### 🛠 在 `reaxel` 中使用
|
|
21
|
+
```tsx
|
|
22
|
+
import { rexaStatus } from 'reaxes-toolkit';
|
|
23
|
+
//reaxels/user-bio.ts
|
|
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;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
//components/UserBio.tsx
|
|
60
|
+
import { useEffect } from 'react';
|
|
61
|
+
import { reaxel_UserBio } from '../reaxels/user-bio';
|
|
62
|
+
|
|
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>;
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
### 🏗 纯 `React` 示例
|
|
84
|
+
```tsx
|
|
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>;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
import { rexaStatus } from 'reaxes-toolkit';
|
|
116
|
+
import { reaxper } from 'reaxes-react';
|
|
117
|
+
import { useEffect , useRef , useState } from 'react';
|
|
118
|
+
```
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './rexaStatus';
|
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './orzPending';
|
package/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import*as r from"reaxes-utils";var t={926:t=>{t.exports=r}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r](i,i.exports,n),i.exports}n.d=(r,t)=>{for(var e in t)n.o(t,e)&&!n.o(r,e)&&Object.defineProperty(r,e,{enumerable:!0,get:t[e]})},n.o=(r,t)=>Object.prototype.hasOwnProperty.call(r,t);var o={};(()=>{n.d(o,{s:()=>i});var r=n(926);function t(r,t){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){var e=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=e){var n,o,i,a,u=[],f=!0,l=!1;try{if(i=(e=e.call(r)).next,0===t){if(Object(e)!==e)return;f=!1}else for(;!(f=(n=i.call(e)).done)&&(u.push(n.value),u.length!==t);f=!0);}catch(r){l=!0,o=r}finally{try{if(!f&&null!=e.return&&(a=e.return(),Object(a)!==a))return}finally{if(l)throw o}}return u}}(r,t)||function(r,t){if(!r)return;if("string"==typeof r)return e(r,t);var n=Object.prototype.toString.call(r).slice(8,-1);"Object"===n&&r.constructor&&(n=r.constructor.name);if("Map"===n||"Set"===n)return Array.from(r);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return e(r,t)}(r,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function e(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}var i=function(){var e=t(r.makePair(orzMobx({pending:!1,error:!1}),(function(r){var t=r.store,e=r.setState,n="undefined"!=typeof queueMicrotask&&queueMicrotask,o=function(){var r=Promise.resolve();return r.then.bind(r)};return[t,function(r){(n||o())((function(){return e({pending:r})}))},function(r){(n||o())((function(){return e({error:r})}))}]})),2),n=t(e[1],3);return{pendingState:n[0],setPending:n[1],setError:n[2]}}})();var i=o.s;export{i as orzPending};
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"8CAEAA,EAAOC,QAAUC,C,GCDbC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaL,QAGrB,IAAID,EAASG,EAAyBE,GAAY,CAGjDJ,QAAS,CAAC,GAOX,OAHAO,EAAoBH,GAAUL,EAAQA,EAAOC,QAASG,GAG/CJ,EAAOC,OACf,CCrBAG,EAAoBK,EAAI,CAACR,EAASS,KACjC,IAAI,IAAIC,KAAOD,EACXN,EAAoBQ,EAAEF,EAAYC,KAASP,EAAoBQ,EAAEX,EAASU,IAC5EE,OAAOC,eAAeb,EAASU,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDP,EAAoBQ,EAAI,CAACK,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,G,4kCCI3E,IAAMI,EAAa,WACzB,IAoBEC,EAAAC,EApB8CC,EAAMC,SAASC,QAAQ,CACtEC,SAAS,EACTC,OAAQ,KACL,SAAAC,GAAyB,IAAtBC,EAAKD,EAALC,MAAOC,EAAQF,EAARE,SACPC,EAAqC,oBAAjBC,gBAAgCA,eACpDC,EAAU,WACf,IAAMC,EAAUC,QAAQC,UACxB,OAAOF,EAAQG,KAAKC,KAAMJ,EAC3B,EACA,MAAO,CACNL,EACA,SAACH,IACCK,GAAcE,MAAW,kBAAMH,EAAS,CAAEJ,QAAAA,GAAU,GAEtD,EACA,SAACC,IACCI,GAAcE,MAAW,kBAAMH,EAAS,CAAEH,MAAAA,GAAQ,GAEpD,EAEF,IAAE,GAAAY,EAAAjB,EAAAD,EAAA,MACF,MAAO,CAAEmB,aArBaD,EAAA,GAqBCE,WArBWF,EAAA,GAqBCG,SArBQH,EAAA,GAsB5C,C","sources":["webpack://mono-reaxes/external module \"reaxes-utils\"","webpack://mono-reaxes/webpack/bootstrap","webpack://mono-reaxes/webpack/runtime/define property getters","webpack://mono-reaxes/webpack/runtime/hasOwnProperty shorthand","webpack://mono-reaxes/./packages/reaxes-toolkit/src/orzPending/index.tsx"],"sourcesContent":["var x = y => { var x = {}; __webpack_require__.d(x, y); return x; }\nvar y = x => () => x\nmodule.exports = __WEBPACK_EXTERNAL_MODULE_reaxes_utils_40cf4af7__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","\n/**\n * pending状态和error状态\n */\nexport const orzPending = () => {\n\tconst [, [pendingState, setPending,setError]] = utils.makePair(orzMobx({\n\t\tpending: false ,\n\t\terror : false ,\n\t}), ({ store, setState }) => {\n\t\tconst qMicroTask = typeof queueMicrotask!==\"undefined\" && queueMicrotask;\n\t\tconst getThen = () => {\n\t\t\tconst promise = Promise.resolve();\n\t\t\treturn promise.then.bind( promise );\n\t\t};\n\t\treturn [\n\t\t\tstore ,\n\t\t\t(pending : boolean) => {\n\t\t\t\t(qMicroTask || getThen())(() => setState({ pending }));\n\t\t\t\treturn;\n\t\t\t},\n\t\t\t(error : boolean) => {\n\t\t\t\t(qMicroTask || getThen())(() => setState({ error }));\n\t\t\t\treturn;\n\t\t\t},\n\t\t] as const;\n\t});\n\treturn { pendingState, setPending, setError };\n};\n\n\nif(false){\n\t//@ts-ignore\n\tconst TestRender = reaxper(() => {\n\t\t\n\t\tconst { pending , error , setPending , setError } = reaxel();\n\t\t\n\t\tif( pending ) {\n\t\t\treturn <span>pending.......</span>;\n\t\t}\n\t\t\n\t\tif( error ) {\n\t\t\treturn <span>Error!</span>;\n\t\t}\n\t\t\n\t\treturn <div\n\t\t\tonClick = { () => {\n\t\t\t\tsetPending(true);\n\t\t\t} }\n\t\t>\n\t\t\tmessage\n\t\t</div>;\n\t});\n\t\n\t\n\tconst reaxel = function(){\n\t\tconst { pendingState , setPending , setError } = orzPending();\n\t\t\n\t\t\n\t\tutils.crayon.blue(pendingState.pending);\n\t\tsetPending(true);\n\t\t\n\t\tutils.orzPromise((res , rej) => {\n\t\t\tsetTimeout(() => {\n\t\t\t\trej();\n\t\t\t} , 1400);\n\t\t}).then(() => {\n\t\t\tsetPending(false);\n\t\t}).catch(() => {\n\t\t\tsetPending(false);\n\t\t\tsetError(true);\n\t\t});\n\t\treturn () => {\n\t\t\treturn {\n\t\t\t\tget pending(){\n\t\t\t\t\treturn pendingState.pending;\n\t\t\t\t} ,\n\t\t\t\tget error(){\n\t\t\t\t\treturn pendingState.error;\n\t\t\t\t} ,\n\t\t\t\tsetPending ,\n\t\t\t\tsetError ,\n\t\t\t};\n\t\t};\n\t}();\n}\n"],"names":["module","exports","__WEBPACK_EXTERNAL_MODULE_reaxes_utils_40cf4af7__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","orzPending","_utils$makePair2","_slicedToArray","utils","makePair","orzMobx","pending","error","_ref","store","setState","qMicroTask","queueMicrotask","getThen","promise","Promise","resolve","then","bind","_utils$makePair2$","pendingState","setPending","setError"],"sourceRoot":""}
|