我目前正在尝试为 ReactJs 构建一个状态管理库。但是一旦我将它实现到我的 React 项目中(使用create-react-app
),它开始丢弃此错误:
Failed to compile.
path/to/agile/dist/runtime.js 116:104
Module parse failed: Unexpected token (116:104)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| if (subscriptionContainer instanceof sub_1.CallbackContainer) subscriptionContainer.callback(); // If Component based subscription call the updateMethod which every framework has to define
|
> if (subscriptionContainer instanceof sub_1.ComponentContainer) if (this.agileInstance.integration?.updateMethod) this.agileInstance.integration?.updateMethod(subscriptionContainer.component, Runtime.formatChangedPropKeys(subscriptionContainer));
| }); // Log Job
|
如果我注释掉错误中提到的突出显示的代码行,它会跳转到另一点并在那里抱怨。但这不可能是语法错误,因为这样 TypeScript 也会在 IDE 中出现错误。
该工具的工作原理:一开始你必须定义一个框架,在本例中是 React。然后,您可以创建一个 State 并通过 Hook 将该 State 订阅到 React 功能组件。
用于将状态绑定到 React 组件的 Hook 只是创建一个触发重新渲染的回调(通过改变useReducer
) 并将此回调分配给订阅的 State。
如果您想了解更多信息,请查看此存储库:https://github.com/agile-ts/agile https://github.com/agile-ts/agile
依赖项:
第三方状态管理库:
"dependencies": {
"@types/chai": "^4.2.12",
"@types/mocha": "^8.0.2",
"chai": "^4.2.0",
"eslint-config-prettier": "^6.11.0",
"mocha": "^8.1.1",
"prettier": "2.0.5",
"ts-node": "^8.10.2",
"tsc-watch": "^4.1.0",
"tslib": "^2.0.0",
"typescript": "^3.9.7"
}
反应项目:
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3",
"typescript": "~3.7.2",
"agile-framework": "file:../../"
},
- React:
16.13.1
- NPM:
6.14.7