Store class
A Store
is a repository and manager of app state. This class should be
extended to fit the needs of your application and its data. The number and
hierarchy of stores is dependent upon the state management needs of your
application.
General guidelines with respect to a Store
's data:
- A
Store
's data should not be exposed for direct mutation. - A
Store
's data should be mutated internally in response to ActionV2s. - A
Store
should expose relevant data ONLY via public getters.
To receive notifications of a Store
's data mutations, Store
s can be
listened to. Whenever a Store
's data is mutated, the trigger
method is
used to tell all registered listeners that updated data is available.
In a typical application using w_flux
, a FluxComponent listens to
Store
s, triggering re-rendering of the UI elements based on the updated
Store
data.
Constructors
- Store()
- Construct a new Store instance.
- Store.withTransformer(StreamTransformer transformer)
- Construct a new Store instance with a transformer.
Properties
-
didDispose
→ Future<
Null> -
A Future that will complete when this object has been disposed.
no setterinherited
- disposableTypeName → String
-
A type name, similar to runtimeType but intended to work
with minified code.
no setter
- disposalTreeSize → int
-
The total size of the disposal tree rooted at the current Disposable
instance.
no setterinherited
-
first
→ Future<
Store> -
The first element of this stream.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- isBroadcast → bool
-
Whether this stream is a broadcast stream.
no setteroverride
- isDisposed → bool
-
Whether this object has been disposed.
no setterinherited
-
isEmpty
→ Future<
bool> -
Whether this stream contains any elements.
no setterinherited
- isLeakFlagSet → bool
-
Whether the leak flag for this object has been set.
no setterinherited
- isOrWillBeDisposed → bool
-
Whether the disposal of this object has been requested, is in progress, or
is complete.
no setterinherited
-
last
→ Future<
Store> -
The last element of this stream.
no setterinherited
-
length
→ Future<
int> -
The number of elements in this stream.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
single
→ Future<
Store> -
The single element of this stream.
no setterinherited
-
stream
→ Stream<
Store> -
The stream underlying trigger events and listen.
no setter
Methods
-
any(
bool test(Store element)) → Future< bool> -
Checks whether
test
accepts any element provided by this stream.inherited -
asBroadcastStream(
{void onListen(StreamSubscription< Store> subscription)?, void onCancel(StreamSubscription<Store> subscription)?}) → Stream<Store> -
Returns a multi-subscription stream that produces the same events as this.
inherited
-
asyncExpand<
E> (Stream< E> ? convert(Store event)) → Stream<E> -
Transforms each element into a sequence of asynchronous events.
inherited
-
asyncMap<
E> (FutureOr< E> convert(Store event)) → Stream<E> -
Creates a new stream with each data event of this stream asynchronously
mapped to a new event.
inherited
-
awaitBeforeDispose<
T> (Future< T> future) → Future<T> -
Add
future
to a list of futures that will be awaited before the object is disposed.inherited -
cast<
R> () → Stream< R> -
Adapt this stream to be a
Stream<R>
.inherited -
contains(
Object? needle) → Future< bool> -
Returns whether
needle
occurs in the elements provided by this stream.inherited -
dispose(
) → Future< Null> -
Dispose of the object, cleaning up to prevent memory leaks.
inherited
-
distinct(
[bool equals(Store previous, Store next)?]) → Stream< Store> -
Skips data events if they are equal to the previous data event.
inherited
-
drain<
E> ([E? futureValue]) → Future< E> -
Discards all data on this stream, but signals when it is done or an error
occurred.
inherited
-
elementAt(
int index) → Future< Store> -
Returns the value of the
index
th data event of this stream.inherited -
every(
bool test(Store element)) → Future< bool> -
Checks whether
test
accepts all elements provided by this stream.inherited -
expand<
S> (Iterable< S> convert(Store element)) → Stream<S> -
Transforms each element of this stream into a sequence of elements.
inherited
-
firstWhere(
bool test(Store element), {Store orElse()?}) → Future< Store> -
Finds the first element of this stream matching
test
.inherited -
flagLeak(
[String? description]) → void -
Flag the object as having been disposed in a way that allows easier
profiling.
inherited
-
fold<
S> (S initialValue, S combine(S previous, Store element)) → Future< S> -
Combines a sequence of values by repeatedly applying
combine
.inherited -
forEach(
void action(Store element)) → Future< void> -
Executes
action
on each element of this stream.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.inherited -
getManagedDisposer(
Disposer disposer) → ManagedDisposer -
Automatically handle arbitrary disposals using a callback.
inherited
-
getManagedPeriodicTimer(
Duration duration, void callback(Timer timer)) → Timer -
Creates a periodic Timer that will be cancelled if active
upon disposal.
inherited
-
getManagedTimer(
Duration duration, void callback()) → Timer -
Creates a Timer instance that will be cancelled if active
upon disposal.
inherited
-
handleError(
Function onError, {bool test(dynamic error)?}) → Stream< Store> -
Creates a wrapper Stream that intercepts some errors from this stream.
inherited
-
join(
[String separator = ""]) → Future< String> -
Combines the string representation of elements into a single string.
inherited
-
lastWhere(
bool test(Store element), {Store orElse()?}) → Future< Store> -
Finds the last element in this stream matching
test
.inherited -
listen(
StoreHandler? onData, {Function? onError, void onDone()?, bool? cancelOnError}) → StreamSubscription< Store> -
Adds a subscription to this
Store
.override -
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
andonDone
handlers.inherited -
manageActionSubscription(
ActionSubscription subscription) → void - Registers an ActionSubscription to be canceled when the store is disposed.
-
manageAndReturnTypedDisposable<
T extends Disposable> (T disposable) → T -
Automatically dispose another object when this object is disposed.
inherited
-
manageCompleter<
T> (Completer< T> completer) → Completer<T> -
Ensure that a completer is completed when the object is disposed.
inherited
-
manageDisposable(
Disposable disposable) → void -
inherited
-
manageStreamController(
StreamController controller) → void -
Automatically cancel a stream controller when this object is disposed.
inherited
-
map<
S> (S convert(Store event)) → Stream< S> -
Transforms each element of this stream into a new stream event.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onDispose(
) → Future< Null> -
Callback to allow arbitrary cleanup on dispose.
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.
inherited
-
pipe(
StreamConsumer< Store> streamConsumer) → Future -
Pipes the events of this stream into
streamConsumer
.inherited -
reduce(
Store combine(Store previous, Store element)) → Future< Store> -
Combines a sequence of values by repeatedly applying
combine
.inherited -
singleWhere(
bool test(Store element), {Store orElse()?}) → Future< Store> -
Finds the single element in this stream matching
test
.inherited -
skip(
int count) → Stream< Store> -
Skips the first
count
data events from this stream.inherited -
skipWhile(
bool test(Store element)) → Stream< Store> -
Skip data events from this stream while they are matched by
test
.inherited -
take(
int count) → Stream< Store> -
Provides at most the first
count
data events of this stream.inherited -
takeWhile(
bool test(Store element)) → Stream< Store> -
Forwards data events while
test
is successful.inherited -
timeout(
Duration timeLimit, {void onTimeout(EventSink< Store> sink)?}) → Stream<Store> -
Creates a new stream with the same events as this stream.
inherited
-
toList(
) → Future< List< Store> > -
Collects all elements of this stream in a List.
inherited
-
toSet(
) → Future< Set< Store> > -
Collects the data of this stream in a Set.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
transform<
S> (StreamTransformer< Store, S> streamTransformer) → Stream<S> -
Applies
streamTransformer
to this stream.inherited -
trigger(
) → void -
Trigger a "data updated" event. All registered listeners of this
Store
will receive the event, at which point they can use the latest data from thisStore
as necessary. -
triggerOnAction(
ActionV2 action, [void onAction(dynamic payload)?]) → dynamic -
A convenience method for listening to an
action
and triggering automatically once the callback for said action has completed. -
triggerOnActionV2<
T> (ActionV2< T> action, [FutureOr onAction(T payload)?]) → void -
A convenience method for listening to an
action
and triggering automatically once the callback for said action has completed. -
where(
bool test(Store event)) → Stream< Store> -
Creates a new stream from this stream that discards some elements.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited