首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >秘密的TypeError:向createEpicMiddleware(rootEpic)提供你的根史诗

秘密的TypeError:向createEpicMiddleware(rootEpic)提供你的根史诗
EN

Stack Overflow用户
提问于 2018-09-07 12:01:32
回答 3查看 2.1K关注 0票数 2

我收到了这个错误

Uncaught :不再支持将根史诗提供给createEpicMiddleware(rootEpic),而是使用epicMiddleware.run(rootEpic)

当简单地使用

代码语言:javascript
复制
import 'rxjs'
import { createStore, combineReducers, applyMiddleware } from 'redux'
import { reducer as formReducer } from 'redux-form'
import thunk from 'redux-thunk'
import promise from 'redux-promise-middleware'
import { createEpicMiddleware, combineEpics } from 'redux-observable'

import app from './app'

// Bundling Epics
const rootEpic = combineEpics(
)

// Creating Bundled Epic
const epicMiddleware = createEpicMiddleware(rootEpic)

// Define Middleware
const middleware = [
  thunk,
  promise(),
  epicMiddleware
]

// Define Reducers
const reducers = combineReducers({
  form: formReducer
})

// Create Store
export default createStore(reducers,window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(), applyMiddleware(...middleware))

请帮我解决这个问题

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2018-10-01 08:07:23

尝尝这个

代码语言:javascript
复制
import 'rxjs'
import { createStore, combineReducers, applyMiddleware } from 'redux'
import { reducer as formReducer } from 'redux-form'
import thunk from 'redux-thunk'
import promise from 'redux-promise-middleware'
import { createEpicMiddleware, combineEpics } from 'redux-observable'

import app from './app'

// Bundling Epics
const rootEpic = combineEpics(
)

// Creating Bundled Epic
const epicMiddleware = createEpicMiddleware();

// Define Middleware
const middleware = [
  thunk,
  promise(),
  epicMiddleware
]

// Define Reducers
const reducers = combineReducers({
  form: formReducer
})

// Create Store
const store = createStore(reducers,window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(), applyMiddleware(...middleware))
epicMiddleware.run(rootEpic);
export default store

正式文档createEpicMiddleware

票数 1
EN

Stack Overflow用户

发布于 2018-10-01 10:47:15

首先,看看这个文档:官方文件-可观察的文件,因为我们使用的是Redux可观测的最新版本,然后查看它的文档是非常有帮助的。

在查看完文档之后,让我们看看一个小示例项目(计数器应用程序):

这是root.js文件,其中包含我的史诗和打包后的还原剂。

代码语言:javascript
复制
// This is a sample reducers and epics for a Counter app.
import { combineEpics } from 'redux-observable';
import { combineReducers } from 'redux';


import counter, {
  setCounterEpic,
  incrementEpic,
  decrementEpic
} from './reducers/counter';

// bundling Epics
export const rootEpic = combineEpics(
  setCounterEpic,
  incrementEpic,
  decrementEpic
);

// bundling Reducers
export const rootReducer = combineReducers({
  counter
});

这是store.js,我在这里定义了我的商店,然后再使用它。

代码语言:javascript
复制
import { createStore, applyMiddleware } from 'redux';
import { createEpicMiddleware } from 'redux-observable';
import { rootEpic, rootReducer } from './root';
import { composeWithDevTools } from 'redux-devtools-extension';

const epicMiddleware = createEpicMiddleware();

const middlewares = [
  epicMiddleware
]

const store = createStore(
  rootReducer,
  composeWithDevTools(applyMiddleware(middlewares))
);

epicMiddleware.run(rootEpic);

export default store;

为了成功地实现redux-observable,我们必须遵守以下命令:

  1. 使用epicMiddleware方法创建createEpicMiddleware()
  2. 使用applyMiddleware()方法注册epicMiddleware ( redux-devtools-extension是可选的)
  3. 用我们前面创建的epicMiddleware.run()调用rootEpic

这是Redux可观察文档中的指令。

有关更多信息,您可以在以下位置找到::建立中间件

票数 2
EN

Stack Overflow用户

发布于 2018-09-07 14:36:02

好吧,你试过:

代码语言:javascript
复制
import { epicMiddleware, combineEpics } from 'redux-observable'
const epicMiddleware = epicMiddleware.run(rootEpic)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52222160

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档