Redux 角度重演史诗

Redux 角度重演史诗,redux,angular5,redux-observable,state-management,angular-redux,Redux,Angular5,Redux Observable,State Management,Angular Redux,使用angular redux库时在控制台中获取以下错误消息。此外,Redux不会在错误发生后捕获或侦听操作。我已经搜索过了,包括文档,但没有指出要修复错误。 我错过什么了吗 错误 行动 史诗 这个错误意味着你发送了一些不是动作的东西。在本例中,你的epic发出了一些不是动作的东西 谢天谢地,这是一个简单的解决办法!您只是在地图中缺少一个返回语句 这个错误意味着你发送了一些不是动作的东西。在本例中,你的epic发出了一些不是动作的东西 谢天谢地,这是一个简单的解决办法!您只是在地图中缺少一个返回

使用angular redux库时在控制台中获取以下错误消息。此外,Redux不会在错误发生后捕获或侦听操作。我已经搜索过了,包括文档,但没有指出要修复错误。 我错过什么了吗

错误

行动

史诗


这个错误意味着你发送了一些不是动作的东西。在本例中,你的epic发出了一些不是动作的东西

谢天谢地,这是一个简单的解决办法!您只是在地图中缺少一个返回语句


这个错误意味着你发送了一些不是动作的东西。在本例中,你的epic发出了一些不是动作的东西

谢天谢地,这是一个简单的解决办法!您只是在地图中缺少一个返回语句


你就是那个人!。。我在action类中添加了return语句并删除了this.ngRedux.dispatch。现在它工作了!!真不敢相信我已经做了两周了。。。!你就是那个人!。。我在action类中添加了return语句并删除了this.ngRedux.dispatch。现在它工作了!!真不敢相信我已经做了两周了。。。!
core.js:1427 ERROR Error: Actions must be plain objects. Use custom middleware for async actions.
    at Object.performAction (<anonymous>:3:2312)
    at liftAction (<anonymous>:2:27846)
    at dispatch (<anonymous>:2:31884)
    at eval (createEpicMiddleware.js:67)
    at SafeSubscriber.dispatch [as _next] (applyMiddleware.js:35)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:240)
    at SafeSubscriber.next (Subscriber.js:187)
    at Subscriber._next (Subscriber.js:128)
    at Subscriber.next (Subscriber.js:92)
    at SwitchMapSubscriber.notifyNext (switchMap.js:127)
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { select } from '@angular-redux/store';
import { ScheduleActions } from '../store/actions'

@Component({
  selector: 'app-page2',
  templateUrl: './page2.component.html',
  styleUrls: ['./page2.component.css']
})
export class Page2Component implements OnInit {

  @select(['schedule', 'scheduleList']) values: any;
  constructor(public actions: ScheduleActions) { }

  ngOnInit() {
    this.actions.loadSchedule();
  }

}
//schedule-actions.ts
import { Injectable } from '@angular/core';
import { NgRedux } from '@angular-redux/store';
import { Schedule } from '../../model/schedule.model';

@Injectable()
export class ScheduleActions {
    static readonly LOAD_SCHEDULE = 'LOAD_SCHEDULE';
    static readonly LOAD_SCHEDULE_SUCCESS = 'LOAD_SCHEDULE_SUCCESS';

    constructor(private ngRedux: NgRedux<any>){}

    loadSchedule(){
        this.ngRedux.dispatch({
            type: ScheduleActions.LOAD_SCHEDULE
        });
    }
}
//schedule-reducer.ts
import { ScheduleActions } from '../actions';

export interface SCHEDULE_STATE {
    scheduleList: any,
    scheduleDetail: any
}

const initialState: SCHEDULE_STATE = {
    scheduleList: [],
    scheduleDetail: {}
}

export const ScheduleReducer = (state: SCHEDULE_STATE = initialState, action): SCHEDULE_STATE => {
    switch(action.type){
        case ScheduleActions.LOAD_SCHEDULE_SUCCESS:
            return {...state, scheduleList: action.payload };
        case ScheduleActions.LOAD_SCHEDULE_DETAIL_SUCCESS:
            return {...state, scheduleList: action.payload };
        case ScheduleActions.CREATE_SCHEDULE_SUCCESS:
            return {...state, scheduleDetail: action.payload };
        default:
            return state;
    }
}
//schedule-epic.ts
import { Injectable } from '@angular/core';
import { ActionsObservable, ofType } from 'redux-observable';
import { ScheduleService } from '../services';
import { ScheduleActions } from '../actions';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class ScheduleEpic {
    constructor(private service: ScheduleService, 
        private actions: ScheduleActions
    ){}

    loadScheduleEpic = (action$: ActionsObservable<any>) => {
        return action$.ofType(ScheduleActions.LOAD_SCHEDULE)
        .mergeMap(action => {
            return this.service.loadSchedule().map(result => {
                this.actions.loadScheduleSuccess(result)
            })

        })
    }
}
//schedule-service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Schedule } from '../../model/schedule.model';

@Injectable()
export class ScheduleService {

    private API_URL: String = "http://mockserver.io/v2";

    constructor(private http: HttpClient){}

    loadSchedule(){
        return this.http.get(this.API_URL + '/5a6225153100004f2bde7f27').map(res => res)
    }
}
return this.service.loadSchedule().map(result => {
  this.actions.loadScheduleSuccess(result)
})

// change it to this:

return this.service.loadSchedule().map(result => {
  return this.actions.loadScheduleSuccess(result)
})