从@ngrs/effect 代码内部调用中间操作的正确方法是什么?

What is the right way to call in-between actions from inside @ngrs/effect code?

需要帮助来调用副作用操作,同时我的项目保存在 Firebase 中。

vehicle.service.ts:

...

public addVehicle(vehicle: Vehicle, success, error) {
  return this.vehicles$.push(vehicle).then(success).catch(error);
}

vehicle.effects.ts:

    @Effect()
    addVehicle$ = this.actions$
    .ofType(VehicleActions.ADD_VEHICLE)
    // NEED TO CALL: this._statusActions.dataLoading('adding new vehicle...')) 
    .switchMap(action => 
        Observable.fromPromise(
            this._vehicleService.addVehicle(action.payload,
                suc => this._statusActions.dataAdded(action.payload.name),
                err => this._statusActions.dataNotSaved(action.payload.name)
            ) // I WANT TO CALL, NOT RETURN ONE OF THEM
    ))

添加一个中间动作

 @Effect()
    addVehicleStatusChange$ = this.actions$
    .ofType(VehicleActions.ADD_VEHICLE)
    .switchMap(this._statusActions.dataLoading('adding new vehicle...')) 
    // return action type ADD_VEHICLE_START


 @Effect()
    addVehicle$ = this.actions$
    .ofType(VehicleActions.ADD_VEHICLE_START)
    .switchMap(action => 
        Observable.fromPromise(
            this._vehicleService.addVehicle(action.payload,
                // Success return action ADD_VEHICLE_SUCCESS
                // Error return ADD_VEHICLE_ERROR
           ) 
    ))

 @Effect()
    addVehicleStatusChangeSuccess$ = this.actions$
    .ofType(VehicleActions.ADD_VEHICLE_SUCCESS)
     .switchMap(suc => this._statusActions.dataAdded(action.payload.name)),
    // return action type some random action you don't care 

 @Effect()
    addVehicleStatusChangeError$ = this.actions$
    .ofType(VehicleActions.ADD_VEHICLE_ERROR)
     .switchMap( =err => this._statusActions.dataNotSaved(action.payload.name))
    // Return some random action. 

我通常做的是从组件调度 PERFORM_ACTION。在效果中听那个动作和 return 新动作 PERFORM_ACTION_START。

操作完成后,return 操作 PERFORM_ACTION_DONE。

在减速器内部,我只有 PERFORM_ACTION_DONE 的处理程序。我有 status 的特殊减速器,我在那里听 PERFORM_ACTION_START 和 PERFORM_ACTION_DONE