ngrx / core

Core functionality for the ngrx platform
MIT License
72 stars 25 forks source link

Operator above EnterZone never gets executed #17

Open colinskow opened 7 years ago

colinskow commented 7 years ago

I am using EnterZone with @ngrx/effects in order to get Angular to do change detection upon receiving data from Electron IPC. I noticed the operator immediately above .enterZone() is not executed. (Using latest rxjs v5.4.0.)

Here is my code:

import { Injectable, NgZone } from '@angular/core';
import { Actions, Effect, toPayload } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import '@ngrx/core/add/operator/enterZone';
import rxIpc from 'rx-ipc-electron/lib/renderer';
import * as player from './player.actions';

@Injectable()
export class PlayerEffects {

  @Effect()
  public openFile$: Observable<Action> = this.actions$
    .ofType(player.LOAD_MEDIA_DIALOG)
    .switchMap(() => rxIpc.runCommand('open-media-file', null))
      .switchMap(files => {
        if (!files) {
          return Observable.empty();
        }
        return Observable.of(new player.SetSourceAction(files[0]));
      })
      .do(() => console.log('THIS IS NEVER EXECUTED.'))
      .enterZone(this.zone);

  constructor(
    private zone: NgZone,
    private actions$: Actions
  ) { }

}

I believe the easiest fix is to directly fork the rxjs do operator and wrap all three subscriber callbacks in the zone.