simproktools

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

simproktools

simproktools #
simproktools is a small library consisting of useful machines for simprokmachine framework.
Installation #
Add the line into pubspec.yaml:
dependencies:
simproktools: ^1.1.2
copied to clipboard
BasicMachine #
In your Dart code use:
import 'package:simproktools/basic.dart';
copied to clipboard
A machine with an injectable processing behavior.
final Machine<Input, Output> machine = BasicMachine(
processor: (Input input, Handler<Output> callback) {
// processing goes here
}
);
copied to clipboard
BasicWidgetMachine #
In your Dart code use:
import 'package:simproktools/basic.dart';
copied to clipboard
A class that describes a widget machine with an injectable child widget.
final WidgetMachine<Input, Output> machine = BasicWidgetMachine(child: MyWidget());
copied to clipboard
ProcessMachine #
In your Dart code use:
import 'package:simproktools/process.dart';
copied to clipboard
A machine with an injectable processing behavior over the injected object.
final Object object = ...;

final Machine<Input, Output> machine = ProcessMachine.create(
object: object,
processor: (Object object, Input, input, Handler<Output> callback) {
// processing goes here
}
);
copied to clipboard
JustMachine #
In your Dart code use:
import 'package:simproktools/just.dart';
copied to clipboard
A machine that accepts a value which is passed back into the callback every time an event is received.
final Machine<Input, int> _ = JustMachine(0); // int can be replaced with any type
copied to clipboard
SingleMachine #
In your Dart code use:
import 'package:simproktools/single.dart';
copied to clipboard
A machine that accepts a value which is passed back into the callback THE FIRST time an event is received.
final Machine<Input, int> _ = SingleMachine(0); // int can be replaced with any type
copied to clipboard
ValueMachine #
In your Dart code use:
import 'package:simproktools/value.dart';
copied to clipboard
A machine that accepts a value as an input and immediately passes it back into the callback as an output.
final Machine<T, T> _ = ValueMachine();
copied to clipboard
NeverMachine #
In your Dart code use:
import 'package:simproktools/never.dart';
copied to clipboard
A machine that accepts an input and ignores it never passing back any output.
final Machine<Input, Output> _ = NeverMachine();
copied to clipboard
ReducerMachine #
In your Dart code use:
import 'package:simproktools/reducer.dart';
copied to clipboard
A machine that receives input, reduces it into state and emits it.

// bool and int can be replaced with any types

final Machine<bool, int> _ = ReducerMachine<bool, int>(initial: 0, reducer: (int state, bool event) {
// return ReducerResult.set(0); // 0 will be a new State and will be passed as output
// return ReducerResult.skip(); // state won't be changed and passed as output
});

copied to clipboard
ClassicMachine #
In your Dart code use:
import 'package:simproktools/classic.dart';
copied to clipboard
A machine that receives input, reduces it into state and array of outputs that are emitted.

// bool, String, and int can be replaced with any types

final Machine<String, int> _ = ClassicMachine<bool, String, int>(
initial: ClassicResult<bool, int>.values(state: false, outputs: [0, 1, 2]), // initial state and initial outputs that are emitted when machine is subscribed to
reducer: (bool state, String event) {
return ClassicResult<bool, int>.values(state: true, outputs: [3, 4, 5]); // new state `true` and outputs `3, 4, 5`
}
);
copied to clipboard
Scan operator #
In your Dart code use:
import 'package:simproktools/scan.dart';
copied to clipboard
Takes this and applies specific behavior.
When parent machine sends new input, it is either reduced into new child state and sent to the this or mapped into parent output and emitted back.
When child machine sends new output, it is either reduced into new child state and sent back to the this or mapped into parent output and emitted.

// All the types can be replaced with anything else.

final Machine<bool, int> machine = ...

final Machine<String, double> result = machine.scan(initial: true, reducer: (bool state, ScanInput<String, int> event) {
// event has either come from parent as input or from child as output.
// output should either go to the parent as output or to the child as new input and state.

// Return
// ScanOutput<double, bool>.state(true); // when input has to be sent to the child machine AND state has to be changed.
// ScanOutput<double, bool>.event(11.11); // when output has to be sent to the parent machine.
...
});
copied to clipboard
ConnectableMachine #
In your Dart code use:
import 'package:simproktools/connectable.dart';
copied to clipboard
A machine for dynamic creation and connection of other machines.
final Machine<Input, Output> = ConnectableMachine<Input, Output, BasicConnection<Input, Output>>(
initial: BasicConnection<Input, Output>({ /* machines go here */ }),
reducer: (BasicConnection<Input, Output> connection, Input input) {
// ConnectionType.reduce() // to connect new machines
// ConnectionType.inward() // to send input to the connected machines
}
);
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.