-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): CHECKOUT-2450 Create new observable from observable-like a…
…ction
- Loading branch information
Showing
6 changed files
with
47 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { Observable } from 'rxjs/Observable'; | ||
import { SubscribableOrPromise } from 'rxjs/Observable'; | ||
import Action from './action'; | ||
import ThunkAction from './thunk-action'; | ||
import ReadableDataStore from './readable-data-store'; | ||
|
||
export default interface DispatchableDataStore<TTransformedState, TAction extends Action> extends ReadableDataStore<TTransformedState> { | ||
dispatch: <TDispatchAction extends TAction>( | ||
action: TDispatchAction | Observable<TDispatchAction>, | ||
action: DispatchableAction<TDispatchAction, TTransformedState>, | ||
options?: DispatchOptions | ||
) => Promise<TTransformedState>; | ||
} | ||
|
||
export interface DispatchOptions { | ||
queueId?: string; | ||
} | ||
|
||
export type DispatchableAction<TAction = Action, TState = any> = TAction | SubscribableOrPromise<TAction> | ThunkAction<TAction, TState>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Observable } from 'rxjs'; | ||
import createAction from './create-action'; | ||
import isObservableActionLike from './is-observable-action-like'; | ||
|
||
describe('isObservableActionLike()', () => { | ||
it('returns true if observable action', () => { | ||
expect(isObservableActionLike(Observable.of(createAction('FOOBAR')))) | ||
.toEqual(true); | ||
}); | ||
|
||
it('returns true if promise-like action', () => { | ||
expect(isObservableActionLike(Promise.resolve(createAction('FOOBAR')))) | ||
.toEqual(true); | ||
}); | ||
|
||
it('returns false if not observable action or promise-like action', () => { | ||
expect(isObservableActionLike(createAction('FOOBAR'))) | ||
.toEqual(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Subscribable, SubscribableOrPromise } from 'rxjs/Observable'; | ||
import { DispatchableAction } from './dispatchable-data-store'; | ||
import Action from './action'; | ||
|
||
export default function isObservableActionLike<TAction extends Action = Action>( | ||
action: DispatchableAction<TAction> | ||
): action is SubscribableOrPromise<TAction> { | ||
return ( | ||
typeof (action as Subscribable<TAction>).subscribe === 'function' || | ||
typeof (action as PromiseLike<TAction>).then === 'function' | ||
); | ||
} |