Action<T> class

A command that can be dispatched and listened to.

An Action manages a collection of listeners and the manner of their invocation. It does not rely on Stream for managing listeners. By managing its own listeners, an Action can track a Future that completes when all registered listeners have completed. This allows consumers to use await to wait for an action to finish processing.

var asyncListenerCompleted = false;
action.listen((_) async {
  await new Future.delayed(new Duration(milliseconds: 100), () {
    asyncListenerCompleted = true;
  });
});

var future = action();
print(asyncListenerCompleted); // => 'false'

await future;
print(asyncListenerCompleted). // => 'true'

Providing a Future for listener completion makes actions far easier to use when a consumer needs to check state changes immediately after invoking an action.

Implemented types
Mixed in types

Constructors

Action()

Properties

didDispose Future<Null>
A Future that will complete when this object has been disposed.
read-only, inherited
disposalTreeSize int
The total size of the disposal tree rooted at the current Disposable instance. [...]
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
isDisposed bool
Whether this object has been disposed.
read-only, inherited
isDisposedOrDisposing bool
Whether this object has been disposed or is currently disposing. [...]
read-only, inherited
isDisposing bool
Whether this object is in the process of being disposed. [...]
read-only, inherited
isLeakFlagSet bool
Whether the leak flag for this object has been set. [...]
read-only, inherited
isOrWillBeDisposed bool
Whether the disposal of this object has been requested, is in progress, or is complete. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

call([T payload ]) Future
Dispatch this Action to all listeners. If a payload is supplied, it will be passed to each listener's callback, otherwise null will be passed.
clearListeners() → void
Cancel all subscriptions that exist on this Action as a result of listen being called. Useful when tearing down a flux cycle in some module or unit test.
@Deprecated('Use (and await) dispose() instead. $v3Deprecation')
listen(dynamic onData(T event)) ActionSubscription
Supply a callback that will be called any time this Action is dispatched. A payload of type T will be passed to the callback if supplied at dispatch time, otherwise null will be passed. Returns an ActionSubscription which provides means to cancel the subscription.
onDispose() Future<Null>
Callback to allow arbitrary cleanup on dispose.
override
awaitBeforeDispose<T>(Future<T> future) Future<T>
Add future to a list of futures that will be awaited before the object is disposed. [...]
@mustCallSuper, inherited
dispose() Future<Null>
Dispose of the object, cleaning up to prevent memory leaks.
inherited
flagLeak([String description ]) → void
Flag the object as having been disposed in a way that allows easier profiling. [...]
@mustCallSuper, inherited
getManagedDelayedFuture<T>(Duration duration, T callback()) Future<T>
Creates a Future that will complete, with the value returned by callback, after the given amount of time has elapsed. [...]
@mustCallSuper, inherited
getManagedDisposer(Disposer disposer) ManagedDisposer
Automatically handle arbitrary disposals using a callback. [...]
@mustCallSuper, inherited
getManagedPeriodicTimer(Duration duration, void callback(Timer timer)) Timer
Creates a periodic Timer that will be cancelled if active upon disposal.
@mustCallSuper, inherited
getManagedTimer(Duration duration, void callback()) Timer
Creates a Timer instance that will be cancelled if active upon disposal.
@mustCallSuper, inherited
listenToStream<T>(Stream<T> stream, void onData(T event), { Function onError, void onDone(), bool cancelOnError }) StreamSubscription<T>
Returns a StreamSubscription which handles events from the stream using the provided onData, onError and onDone handlers. [...]
@mustCallSuper, inherited
manageAndReturnDisposable(Disposable disposable) Disposable
Automatically dispose another object when this object is disposed. [...]
@mustCallSuper, inherited
manageAndReturnTypedDisposable<T extends Disposable>(T disposable) → T
Automatically dispose another object when this object is disposed. [...]
@mustCallSuper, inherited
manageCompleter<T>(Completer<T> completer) Completer<T>
Ensure that a completer is completed when the object is disposed. [...]
@mustCallSuper, inherited
manageDisposable(Disposable disposable) → void
Automatically dispose another object when this object is disposed. [...]
@mustCallSuper, inherited
manageDisposer(Disposer disposer) → void
Automatically handle arbitrary disposals using a callback. [...]
@mustCallSuper, inherited
manageStreamController(StreamController controller) → void
Automatically cancel a stream controller when this object is disposed. [...]
@mustCallSuper, inherited
manageStreamSubscription(StreamSubscription subscription) → void
Automatically cancel a stream subscription when this object is disposed. [...]
@mustCallSuper, inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
onWillDispose() Future<Null>
Callback to allow arbitrary cleanup as soon as disposal is requested (i.e. dispose is called) but prior to disposal actually starting. [...]
@protected, inherited
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(Object other) bool
Actions are only deemed equivalent if they are the exact same Object
override