SagaContext class
Manages saga context. Context is basically a key/value dictionary stored in objects member of class. Middleware creates and manages context by instantiating SagaContext.
Use Options to pass initial context to middleware. In most cases no need to instantiate this class manually. Context can be read and modified by effects GetContext and SetContext
// create middleware and pass options
var sagaMiddleware = createSagaMiddleware(
//initiate context with options
Options(context: <dynamic, dynamic>{#a: 1}),
);
// create store and apply middleware
final store = Store<int>(
counterReducer,
initialState: 0,
middleware: [applyMiddleware(sagaMiddleware)],
);
// attach store
sagaMiddleware.setStore(store);
// run saga
sagaMiddleware.run(() sync* {
var result = Result<dynamic>();
//read context
yield GetContext(#a, result: result);
//set context
yield SetContext(<dynamic, dynamic>{#b: 2});
});
Constructors
- SagaContext([Map? objects])
- Creates an instance of a SagaContext.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- keys → List
-
Returns context items keys
no setter
- objects ↔ Map
-
Context values stored at objects. It is a map dictionary with key/value pairs.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add(
dynamic name, dynamic object) → void -
Adds new item named
name
to the context with the valueobject
if it already exits then setobject
as new value -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
dynamic name) → void -
Removes context item with
name
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
dynamic name) → dynamic - Indexed get property to access context values