pipeline_plus

Last updated:

0 purchases

pipeline_plus Image
pipeline_plus Images
Add to Cart

Description:

pipeline plus

pipeline_plus #




A Pipeline allows you to pass data through a series of pipes to perform a
sequence of operations with the data. Each pipe is a callable piece of code: A
class method, a function. Since each pipe operates on the data in isolation (the
pipes don't know or care about each other), then that means you can easily
compose complex workflows out of reusable actions that are also very easy to
test because they aren't interdependent.
Usage #
A simple usage example:
import 'package:pipeline_plus/pipeline_plus.dart';

var pipeline = Pipeline()
..send(data: User())
..onFailure(callback: (passable, exception) {
// do something
})
..through(
pipes: [
RegisterUserService(),
AddMemberToTeamService(),
(User user) {
// do something
return user;
},
SendWelcomeEmailService(),
],
);
copied to clipboard
PipelineMixin #
By implementing PipelineMixin on a class, you can use the pipeThrough method for the class.
class User with PipelineMixin {}
copied to clipboard
import 'package:pipeline_plus/pipeline_plus.dart';

var userPipeline = User().pipeThrough(
pipes: [
RegisterUserService(),
AddMemberToTeamService(),
(User user) {
// do something
return user;
},
SendWelcomeEmailService(),
],
);

copied to clipboard
Sample pipe #
class SendWelcomeEmailService implements Pipe<User> {
@override
Future<User> handle(User user) async {
print('The welcome email is being sent.');
user.welcomeEmailIsSent = true;

return user;
}
}
copied to clipboard
Methods #
send #
Set the data being sent through the pipeline.
..send(data: User())
copied to clipboard
through #
Set the list of pipes.
..through(
pipes: [
RegisterUserService(),
AddMemberToTeamService(),
(User user) {
user.teamId = 1000;
return user;
},
SendWelcomeEmailService(),
],
)
copied to clipboard
pipe #
Push additional pipes onto the pipeline.
..pipe(
pipes: [
AdditionalService(),
],
)
copied to clipboard
onFailure #
Set callback to be executed on failure pipeline.
..onFailure(callback: (passable, exception) {
// do something
})
copied to clipboard
then #
Run the pipeline with a final destination callback.
pipeline.then(callback: (data){
// do something
});
copied to clipboard
thenReturn #
Run the pipeline and return the result.
var data = await pipeline.thenReturn();
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.