Skip to content

Commit

Permalink
feat(core/create): allows second argument of intercepts to be a singl…
Browse files Browse the repository at this point in the history
…e intercept
  • Loading branch information
rafamel committed Oct 18, 2019
1 parent 3e4560f commit 433726a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/create/intercepts/intercepts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ export interface InterceptsCreateOptions {
*/
export function intercepts<T extends CollectionTree>(
collection: T,
intercepts: InterceptImplementation[],
intercepts: InterceptImplementation | InterceptImplementation[],
options?: InterceptsCreateOptions
): T {
const opts = Object.assign({ prepend: true }, options);
const arr =
intercepts && !Array.isArray(intercepts) ? [intercepts] : intercepts;

return replace(collection, (element, next) => {
element = next(element);
Expand All @@ -31,8 +33,8 @@ export function intercepts<T extends CollectionTree>(
: {
...element,
intercepts: opts.prepend
? intercepts.concat(element.intercepts || [])
: (element.intercepts || []).concat(intercepts)
? arr.concat(element.intercepts || [])
: (element.intercepts || []).concat(arr)
};
}) as T;
}
Expand Down

0 comments on commit 433726a

Please sign in to comment.