define static method
Define a Step using a StepBuilder.
This method returns a builder which has two methods dep
and build
.
Calling builder.dep(stepA)
adds a dependency on stepA
and returns
a new builder. Calling builder.build(runStep)
creates a Step<T> if
runStep
is a function that returns T
and takes the result value
from dependent steps.
As adding new dependenices with builder.dep
changes the number of
arguments for the runStep
method required by the builder.build
method,
the type of the builder will be StepBuilder, StepBuilder1 through
StepBuilder9 depending on the number of dependenices. The StepBuilder
types have the same interface, except the StepBuilder and
StepBuilder9 which offers a builder.deps(Iterable<Step<S>> steps)
method that allows for an arbitrary number of dependencies. This useful if
all the dependent steps have the same type, or if a step has more than 9
dependencies.
Example
// Define a step without dependencies
final Step<Router> routerStep = Step.define('router').build(() {
return Router(/* setup request router */);
});
// Define a step without dependencies
final Step<Database> databaseStep = Step.define('database').build(() {
return Database(/* setup database connection and schema */);
});
// Define a step with two dependencies
final Step<Server> server = Step.define('server')
.dep(routerStep)
.dep(databaseStep)
.build((router, router) async {
// Setup Server using router and database
});
Implementation
static StepBuilder define(String name) => StepBuilder._(name);