Skip to content

Commit

Permalink
fix: Fixed usage of Effect's options by handleAction() and `scope.c…
Browse files Browse the repository at this point in the history
…reateEffect()` (#7)
  • Loading branch information
mnasyrov authored Oct 12, 2022
1 parent d45cb74 commit e44bd23
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 9 additions & 3 deletions packages/rx-effects/src/handleAction.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { Observable } from 'rxjs';
import { Action } from './action';
import { createEffect, Effect, EffectHandler, HandlerOptions } from './effect';
import {
createEffect,
Effect,
EffectHandler,
EffectOptions,
HandlerOptions,
} from './effect';

/**
* This helper creates `Effect` from `handler` and subscribes it to `source`.
*/
export function handleAction<Event, Result = void, ErrorType = Error>(
source: Observable<Event> | Action<Event>,
handler: EffectHandler<Event, Result>,
options?: HandlerOptions<ErrorType>,
options?: HandlerOptions<ErrorType> & EffectOptions<Event, Result>,
): Effect<Event, Result, ErrorType> {
const effect = createEffect<Event, Result, ErrorType>(handler);
const effect = createEffect<Event, Result, ErrorType>(handler, options);
effect.handle(source, options);

return effect;
Expand Down
13 changes: 10 additions & 3 deletions packages/rx-effects/src/scope.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Observable, Subscription, TeardownLogic } from 'rxjs';
import { Action } from './action';
import { Controller } from './controller';
import { createEffect, Effect, EffectHandler, HandlerOptions } from './effect';
import {
createEffect,
Effect,
EffectHandler,
EffectOptions,
HandlerOptions,
} from './effect';
import { handleAction } from './handleAction';
import { StateDeclaration } from './stateDeclaration';
import { createStore, Store, StoreOptions } from './store';
Expand Down Expand Up @@ -60,7 +66,7 @@ export type Scope = Controller<{
handleAction: <Event, Result = void, ErrorType = Error>(
source: Observable<Event> | Action<Event>,
handler: EffectHandler<Event, Result>,
options?: HandlerOptions<ErrorType>,
options?: HandlerOptions<ErrorType> & EffectOptions<Event, Result>,
) => Effect<Event, Result, ErrorType>;
}>;

Expand Down Expand Up @@ -115,8 +121,9 @@ export function createScope(): Scope {

createEffect<Event, Result, ErrorType>(
handler: EffectHandler<Event, Result>,
options?: EffectOptions<Event, Result>,
) {
const effect = createEffect<Event, Result, ErrorType>(handler);
const effect = createEffect<Event, Result, ErrorType>(handler, options);
subscriptions.add(effect.destroy);

return effect;
Expand Down

0 comments on commit e44bd23

Please sign in to comment.