Skip to content

Commit

Permalink
style(Store): rename select input variable
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Jul 27, 2018
1 parent 4605ff9 commit 6991562
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions modules/store/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,22 @@ export function select<
* fixed length tuples type in typescript 2.7
*/
export function select<State, Props = any, Result = any>(
props: Props,
propsOrPath: Props,
...paths: string[]
): (source$: Observable<State>) => Observable<Result>;
export function select<State, Props, K>(
pathOrMapFn: (state: State, props?: Props) => any | string,
props: Props,
props: Props | string,
...paths: string[]
) {
return function selectOperator(source$: Observable<State>): Observable<K> {
let mapped$: Observable<any>;

if (typeof pathOrMapFn === 'string') {
mapped$ =
typeof props === 'string'
? source$.pipe(pluck(pathOrMapFn, props, ...paths))
: source$.pipe(pluck(pathOrMapFn, ...paths));
const pathSlices = [<string>props, ...paths].filter(Boolean);
mapped$ = source$.pipe(pluck(pathOrMapFn, ...pathSlices));
} else if (typeof pathOrMapFn === 'function') {
mapped$ = source$.pipe(map(source => pathOrMapFn(source, props)));
mapped$ = source$.pipe(map(source => pathOrMapFn(source, <Props>props)));
} else {
throw new TypeError(
`Unexpected type '${typeof pathOrMapFn}' in select operator,` +
Expand Down

0 comments on commit 6991562

Please sign in to comment.