pipeline_plus 1.1.0 copy "pipeline_plus: ^1.1.0" to clipboard
pipeline_plus: ^1.1.0 copied to clipboard

A Pipeline allows you to pass data through a series of pipes to perform a sequence of operations with the data.

pipeline_plus #

platform platform pub package license

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(),
  ],
);

PipelineMixin #

By implementing PipelineMixin on a class, you can use the pipeThrough method for the class.

class User with PipelineMixin {}
import 'package:pipeline_plus/pipeline_plus.dart';

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

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;
  }
}

Methods #

send #

Set the data being sent through the pipeline.

..send(data: User())

through #

Set the list of pipes.

..through(
   pipes: [
    RegisterUserService(),
    AddMemberToTeamService(),
    (User user) {
      user.teamId = 1000;
      return user;
    },
    SendWelcomeEmailService(),
  ],
)

pipe #

Push additional pipes onto the pipeline.

..pipe(
    pipes: [
        AdditionalService(),
    ],
)

onFailure #

Set callback to be executed on failure pipeline.

..onFailure(callback: (passable, exception) {
    // do something
})

then #

Run the pipeline with a final destination callback.

pipeline.then(callback: (data){
// do something
});

thenReturn #

Run the pipeline and return the result.

var data = await pipeline.thenReturn();
3
likes
160
points
42
downloads

Publisher

verified publisherfaaytech.com

Weekly Downloads

A Pipeline allows you to pass data through a series of pipes to perform a sequence of operations with the data.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on pipeline_plus