我目前正在尝试为 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 Functional Component。用于将 State 绑定到 React 组件的 Hook 只是创建一个回调,该回调触发重新渲染(通过改变 a useReducer
)并将此回调分配给订阅的 State。
如果您想了解更多信息,请查看此 repo: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"
}
- 节点:
v14.8.0
react项目:
"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
- 新产品管理:
6.14.7