Skip to content

The dart-pipeline library offers a seamless way to pass an object between multiple classes and execute various tasks on it. This fluid process allows you to perform complex operations and obtain the final result once all the tasks have been completed.

License

Notifications You must be signed in to change notification settings

mi-sch-ka/dart-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

The dart-pipeline library offers a seamless way to pass an object between multiple classes and execute various tasks on it. This fluid process allows you to perform complex operations and obtain the final result once all the tasks have been completed.

What is Pipeline?

The Pipeline class is implemented based on the Chain of Responsibility design pattern. This design promotes flexibility and scalability in task handling by decoupling senders and receivers of requests.

In summary; the pipelines take a job, process it, and forward it to the next pipeline.

How to use

Pipeline with Functions

var pipelineFactory = PipelineFactory();
var result = pipelineFactory.create()
    .send("Hello")
    .pipe([
      (dynamic passable, Function(dynamic nextPassable) next) => next([passable,"World"].join(" "))
    ])
    .thenReturn();

assert(result is String);
assert(result == "Hello World");

Pipeline with Objects

var pipelineFactory = PipelineFactory();

var result = pipelineFactory.create()a
    .send("ewogICJsYW5ndWFnZSI6ImRhcnQiCn0=")
    .pipe([Base64Decoder(), JsonDecoder()])
    .thenReturn();

assert(result is Map<String, dynamic>);
assert(result["language"] == "dart");

You can define your pipe object by implementing the PipeInterface:

import 'package:dart_pipeline/dart_pipeline.dart';

class Base64Decoder implements PipeInterface {
  
  @override
  dynamic handle(dynamic passable, Function(dynamic nextPassable) next) {
    var bytes = base64.decode(passable);
    var decoded = utf8.decode(bytes);
    return next(decoded);
  }
}

class JsonDecoder implements PipeInterface {
  
  @override
  dynamic handle(dynamic passable, Function(dynamic nextPassable) next) {
    return next(jsonDecode(passable));
  }
}

About

The dart-pipeline library offers a seamless way to pass an object between multiple classes and execute various tasks on it. This fluid process allows you to perform complex operations and obtain the final result once all the tasks have been completed.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages