Skip to content

Commit 42fcd9e

Browse files
feat(overmind): add noop and run operators
1 parent 6dd358d commit 42fcd9e

File tree

1 file changed

+31
-0
lines changed
  • packages/node_modules/overmind/src

1 file changed

+31
-0
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,16 @@ export function map<Input, Output, ThisConfig extends IConfiguration = Config>(
11531153
)
11541154
}
11551155

1156+
export function noop<
1157+
Input,
1158+
ThisConfig extends IConfiguration = Config
1159+
>(): IOperator<ThisConfig, Input> {
1160+
return createOperator<ThisConfig>('noop', '', (err, context, value, next) => {
1161+
if (err) next(err, value)
1162+
else next(null, value)
1163+
})
1164+
}
1165+
11561166
export function filter<Input, ThisConfig extends IConfiguration = Config>(
11571167
operation: (context: IContext<ThisConfig>, value: Input) => boolean
11581168
): IOperator<ThisConfig, Input, Input> {
@@ -1219,6 +1229,27 @@ export function mutate<Input, ThisConfig extends IConfiguration = Config>(
12191229
)
12201230
}
12211231

1232+
export function run<Input, ThisConfig extends IConfiguration = Config>(
1233+
operation: (context: IContext<ThisConfig>, value: Input) => void
1234+
): IOperator<ThisConfig, Input, Input> {
1235+
return createOperator<ThisConfig>(
1236+
'run',
1237+
getFunctionName(operation),
1238+
(err, context, value, next) => {
1239+
if (err) next(err, value)
1240+
else {
1241+
const result = operation(context, value) as any
1242+
1243+
if (result instanceof Promise) {
1244+
next(null, result.then(() => value))
1245+
} else {
1246+
next(null, value)
1247+
}
1248+
}
1249+
}
1250+
)
1251+
}
1252+
12221253
export function catchError<Input, ThisConfig extends IConfiguration = Config>(
12231254
operation: (context: IContext<ThisConfig>, value: Error) => Input
12241255
): IOperator<ThisConfig, Input, Input> {

0 commit comments

Comments
 (0)