Skip to content
This repository has been archived by the owner on Nov 13, 2020. It is now read-only.

Commit

Permalink
fix(wrappedEpic): fix actions proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkeley Martinez authored and Berkeley Martinez committed Dec 8, 2016
1 parent ce6d828 commit 7a75d90
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/wrap-root-epic.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'rxjs';
import { EmptyObservable } from 'rxjs/observable/EmptyObservable';
import { Subject } from 'rxjs/Subject';
import { Subscriber } from 'rxjs/Subscriber';
Expand All @@ -6,24 +7,28 @@ import { EPIC_END } from 'redux-observable/lib/EPIC_END';
const endAction = { type: EPIC_END };

export default function wrapRootEpic(rootEpic) {
let _actions = EmptyObservable.create();
let actionsProxy = EmptyObservable.create();
let lifecycle = EmptyObservable.create();
let subscription;
let start;
function wrappedEpic(actions, ...rest) {
const results = new Subject();
start = () => {
subscription = new Subscriber();
_actions = new Subject(actions);
actionsProxy = new Subject();
// how can subject inherit from ActionsObservable
actionsProxy.ofType = actions.ofType;
lifecycle = new Subject();
const _subscription = rootEpic(_actions, ...rest)
const actionsSubscription = actions.subscribe(actionsProxy);
const epicsSubscription = rootEpic(actionsProxy, ...rest)
.subscribe(
action => results.next(action),
err => { throw err; },
() => lifecycle.complete()
);

subscription.add(_subscription);
subscription.add(epicsSubscription);
subscription.add(actionsSubscription);
};
start();
return results;
Expand All @@ -33,12 +38,12 @@ export default function wrapRootEpic(rootEpic) {
(...args) => lifecycle.subscribe.apply(lifecycle, args);
wrappedEpic.unsubscribe = () => subscription.unsubscribe();
wrappedEpic.end = () => {
_actions.next(endAction);
_actions.complete();
actionsProxy.next(endAction);
actionsProxy.complete();
};
wrappedEpic.restart = () => {
wrappedEpic.unsubscribe();
_actions.unsubscribe();
actionsProxy.unsubscribe();
start();
};

Expand Down

0 comments on commit 7a75d90

Please sign in to comment.