typescript - Can't use redux-observable with Stencil@one : "Class constructor Observable cannot be invoked without 'new'" error on ActionsObservable class
问题描述
I have a Stencil component library using @Stencil/redux, redux, redux-observable and redux-actions. Everything worked fine before but I'm trying to upgrade to Stencil@One (1.0.0-beta.5).
I have now an error during the Redux store creation. This is my store configuration :
import { Store, createStore, applyMiddleware } from 'redux';
import { createEpicMiddleware } from 'redux-observable';
import { rootEpic } from './epic';
const epicMiddleware = createEpicMiddleware();
export const ogodStore: Store<OgodState> = createStore(rootReducer, applyMiddleware(epicMiddleware));
epicMiddleware.run(rootEpic);
The error occurs on applyMiddleware call and is the following :
TypeError: Class constructor Observable cannot be invoked without 'new'
at new ActionsObservable (chunk-f18fe9c6.js:3744)
at epicMiddleware (chunk-f18fe9c6.js:3830)
at chunk-f18fe9c6.js:4579
at Array.map (<anonymous>)
at chunk-f18fe9c6.js:4578
at createStore (chunk-f18fe9c6.js:4043)
at chunk-f18fe9c6.js:4716
I am so confused over the years by the different javascript module types and targets... But here's what I know :
- This error is caused by this specific code inside redux-observable :
(ActionsObservable.__proto__ || Object.getPrototypeOf(ActionsObservable)).call(this)
- It is using
call(this)
to construct a ActionsObservable object, which is dependent on rxjs'sObservable
class - In my Typescript configuration I use what stencil created and it's still the same for new projects (module: 'esnext', target: 'es2017')
Observable
from rxjs does not support this ?! It is a class that should be constructed using ES6 syntax new
because it is supported by browsers now ?
I'd really like to know if I should create an issue in redux-observable's Github ?
解决方案
我按照@Elvynia 提供的 github 链接解决了这个问题 -
安装 redux-observable-es6-compat 并导入 -
import { createEpicMiddleware, combineEpics } from 'redux-observable-es6-compat';
代替
import { createEpicMiddleware, combineEpics } from 'redux-observable';
推荐阅读
- php - PHP PDO 无法绑定浮点参数以按整数字段搜索
- c++ - 将指针分配给字符串变量中包含的地址
- sql - VBA SQL 使用表单中的值更新/插入本地表
- ios - FrameLayout IOS 替代方案
- c++ - C++ 对象和命名空间
- javascript - 未创建图表
- apache - 如何让 Twitter 提供压缩的 js?
- python - 数据库数据的字符串编码/解码问题
- python - 如何纠正python填充之间的错误,TypeError:'PolyCollection'对象不可迭代
- angularjs - 如何在 ionic1 codova 项目中集成原生应用程序代码?