Skip to content

Commit

Permalink
feat(tasks): adds context transform
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Feb 17, 2021
1 parent b788530 commit 4494630
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/tasks/transform/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Task, Context } from '../../definitions';
import { run } from '../consume/run';
import { UnaryFn, Empty } from 'type-core';

export function context(
context:
| Empty
| Partial<Context>
| UnaryFn<Context, Partial<Context> | Empty>,
task: Task
): Task.Async {
const fn = typeof context === 'function' ? context : () => context;
return async (context: Context): Promise<void> => {
await run(task, { ...context, ...fn(context) });
};
}
1 change: 1 addition & 0 deletions src/tasks/transform/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './context';
export * from './select';

0 comments on commit 4494630

Please sign in to comment.