Taro: 无法使用redux-saga

Created on 9 Jun 2018  ·  7Comments  ·  Source: NervJS/taro

taro-cli:v0.0.41

redux配置:
`
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk'
import createSagaMiddleware from 'redux-saga'
import rootReducer from '../reducers'
import rootSaga from '../sagas';

const sagaMiddleware = createSagaMiddleware()
let middlewares = [thunk,sagaMiddleware]

export default function configStore () {
const store = createStore(rootReducer, applyMiddleware(...middlewares));
// then run the saga
sagaMiddleware.run(rootSaga);
return store
}
`

运行报错:
image

在对应的dist/npm/redux-saga目录下,发现并没有相关的文件
image

Most helpful comment

集成过程:

1.app.js

//注意,该库的引用必须早于config-store的引用
import '@tarojs/async-await';
import {Provider,connect} from '@tarojs/redux';
import configStore from './store/config-store';

2./store/config-store.js

import { createStore, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga/dist/redux-saga';
import rootReducer from '../reducers';
import rootSaga from '../sagas';

const sagaMiddleware = createSagaMiddleware();
let middlewares = [sagaMiddleware];

export default function configStore () {
const store = createStore(rootReducer, applyMiddleware(...middlewares));
// then run the saga
sagaMiddleware.run(rootSaga);
return store
}

3.需要引用effects的地方

import {effects} from 'redux-saga/dist/redux-saga';
const {all,fork} = effects;

All 7 comments

0.0.42 修复了 redux-saga 包抽离文件的问题,但是发现运行还是有问题,因为 redux-saga 里存在循环依赖,导致小程序解析错误,目前解决方案是 ~把 redux-saga 编译好的文件下载到本地进行使用~ 这样来使用 import createSagaMiddleware from 'redux-saga/dist/redux-saga'

集成过程:

1.app.js

//注意,该库的引用必须早于config-store的引用
import '@tarojs/async-await';
import {Provider,connect} from '@tarojs/redux';
import configStore from './store/config-store';

2./store/config-store.js

import { createStore, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga/dist/redux-saga';
import rootReducer from '../reducers';
import rootSaga from '../sagas';

const sagaMiddleware = createSagaMiddleware();
let middlewares = [sagaMiddleware];

export default function configStore () {
const store = createStore(rootReducer, applyMiddleware(...middlewares));
// then run the saga
sagaMiddleware.run(rootSaga);
return store
}

3.需要引用effects的地方

import {effects} from 'redux-saga/dist/redux-saga';
const {all,fork} = effects;

您好 ,我启动服务的时候出现了这个错误,
ERROR
TS18003: No inputs were found in config file 'tsconfig.json'. Specified 'include' paths were '["src"]' and 'exclude' paths were '["__tests__","node_modules","dist","tests","jest","lib","/.test.ts","/.spec.ts"]'.

@wkh2 你好,因为 H5 的 TS 支持还没完全好,所以建议先使用 js 来开发

@luckyadam 你好,我在集成redux-saga时发现没有这个文件,redux-saga/dist/redux-saga.
版本:redux-saga:^1.0.1

-webkit-box-orient: vertical;
这个样式编译成h5就没了?微信小程序是可以的。

@luckyadam 你好,我在集成redux-saga时发现没有这个文件,redux-saga/dist/redux-saga.
版本:redux-saga:^1.0.1

@Rychou 需要降级下 redux-saga 的版本到^0.16.2

Was this page helpful?
0 / 5 - 0 ratings