Store<S> class
abstract
A redux like store that manages state.
Contrary to the original design the store doesn't use configured actions, but instead uses a synchronous update callback. Furthermore, various extensions are provided to asynchronously let an Observable or Future manipulate the state.
Middleware is provided by providing other implementations of the Store interface, and possibly wrapping and delegating to the DefaultStore.
The canonical example with the counter looks like this:
// Create a store with the initial value 0. final store = Store
// Subscribe to state changes and print the new state to the console. store.subscribe(Observer.next((state) => print(state)));
// Increment the value by one. In a more complicated example one // could extract the function to be standalone, or generalize it to // handle different actions. store.update((state) => state + 1);
// Alternatively, one can subscribe to an observable and provide // reducer functions for its events to update the state asynchronously. // The following lines set the state to a random value every 10 seconds. final randomValue = timer(period: Duration(seconds: 10)) .map((_) => Random().nextInt(100)); store.addObservable(randomValue, next: (state, value) => value);
- Implemented types
-
- Observable<
S>
- Observable<
- Implementers
- Available extensions
- AuditOperator
- BufferOperator
- CastOperator
- CatchErrorOperator
- CombineLatestOperator
- ComposeOperator
- ConcatOperator
- CountOperator
- DebounceOperator
- DefaultIfEmptyOperator
- DelayOperator
- DematerializeOperator
- DistinctOperator
- DistinctUntilChangedOperator
- ExhaustAllOperator
- ExhaustMapOperator
- FinalizeOperator
- FirstOperator
- FlatMapOperator
- FlattenObservable
- FoldOperator
- FutureStoreExtension
- IgnoreElementsOperator
- IsEmptyOperator
- LastOperator
- MapOperator
- MaterializeOperator
- MergeAllOperator
- MergeMapOperator
- MulticastOperator
- ObservableStoreExtension
- ObservableToFuture
- ObservableToStream
- ObserveOnOperator
- PairwiseOperator
- PublishOperator
- ReduceOperator
- RepeatOperator
- SampleOperator
- SingleOperator
- SkipOperator
- SkipUntilOperator
- SkipWhileOperator
- StreamStoreExtension
- SwitchAllOperator
- SwitchMapOperator
- TakeLastOperator
- TakeOperator
- TakeUntilOperator
- TakeWhileOperator
- TapOperator
- ThrottleOperator
- TimeoutOperator
- ToListOperator
- ToMapOperator
- ToSetOperator
- WhereOperator
- WhereTypeOperator
Constructors
- Store(S initialState)
-
Constructs a standard store from an initial state.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → S
-
Returns the current state.
no setter
Methods
-
addFuture<
T> (Future< T> future, {S onValue(S state, T value)?, S onError(S state, Object error, StackTrace stackTrace)?}) → Future<S> -
Available on Store<
Adds anS> , provided by the FutureStoreExtension extensionfuture
that asynchronously contributes to the state throughonValue
andonError
reducers. These functions receive the current state and resolution of the Future to produce a new state. -
addObservable<
T> (Observable< T> observable, {S next(S state, T value)?, S error(S state, Object error, StackTrace stackTrace)?, S complete(S state)?, bool ignoreErrors = false}) → Disposable -
Available on Store<
Adds anS> , provided by the ObservableStoreExtension extensionobservable
that asynchronously contributes to the state throughnext
,error
andcomplete
reducers. These functions receive the current state and the events of the Observer to produce a new state. -
addStream<
T> (Stream< T> stream, {S onData(S state, T event)?, S onError(S state, Object error, StackTrace stackTrace)?, S onDone(S state)?, bool? cancelOnError}) → StreamSubscription<T> -
Available on Store<
Adds aS> , provided by the StreamStoreExtension extensionstream
that asynchronously contributes to the state throughonData
,onError
andonDone
reducers. These functions receive the current state and the events of the Stream to produce a new state. -
audit<
R> (DurationSelector< T, R> durationSelector) → Observable<T> -
Available on Observable<
Ignores values from this Observable for a duration determined by the Observable returned fromT> , provided by the AuditOperator extensiondurationSelector
, then emits the most recent source value, then repeats the process. -
auditTime(
Duration duration, {Scheduler? scheduler}) → Observable< T> -
Available on Observable<
Ignores values from this Observable for the givenT> , provided by the AuditOperator extensionduration
, then emits the most recent source value, then repeats the process. -
beginWith(
Observable< T> observable) → Observable<T> -
Available on Observable<
Prepends the emission of items with an Observable.T> , provided by the ConcatOperator extension -
buffer<
R> ({Scheduler? scheduler, Observable< R> ? trigger, int? maxLength, Duration? maxAge}) → Observable<List< T> > -
Available on Observable<
Gathers the items emitted by this Observable and bundles these items into a list until eitherT> , provided by the BufferOperator extension -
cast<
R> () → Observable< R> -
Available on Observable<
Casts the values from this Observable toT> , provided by the CastOperator extensionR
. -
catchError<
E> (ErrorHandler< T, E> handler) → Observable<T> -
Available on Observable<
Catches errors of typeT> , provided by the CatchErrorOperator extensionE
thrown by this Observable and handles them by either returning a new Observable of typeT
, throwing the same or a different error, or returningnull
to complete the Observable. -
combineLatest(
) → Observable< List< T> > -
Available on Observable<
Combines multiple source to create an Observable whose values are calculated from the latest values of each of its inputs.Observable< , provided by the CombineLatestOperator extensionT> > -
compose<
R> (Transformer< T, R> transformation) → Observable<R> -
Available on Observable<
Prepends the emission of items withT> , provided by the ComposeOperator extensiontransformation
. -
count(
) → Observable< int> -
Available on Observable<
Counts the number of emissions of this Observable and emits that number on completion.T> , provided by the CountOperator extension -
debounce<
R> (DurationSelector< T, R> durationSelector) → Observable<T> -
Available on Observable<
Emits a value from this Observable only after a particular time span determined by another Observable has passed without another emission.T> , provided by the DebounceOperator extension -
debounceTime(
Duration duration, {Scheduler? scheduler}) → Observable< T> -
Available on Observable<
Emits a value from this Observable only after a particular time span has passed without another emission.T> , provided by the DebounceOperator extension -
defaultIfEmpty(
T value) → Observable< T> -
Available on Observable<
Emits a given value if this Observable completes without emitting any value, otherwise mirrors the source.T> , provided by the DefaultIfEmptyOperator extension -
delay<
R> (DurationSelector< T, R> durationSelector) → Observable<T> -
Available on Observable<
Delays the emission of items from this Observable until the Observable returned fromT> , provided by the DelayOperator extensiondurationSelector
triggers. -
delayTime(
Duration duration, {Scheduler? scheduler}) → Observable< T> -
Available on Observable<
Delays the emission of items from this Observable by a given timeout.T> , provided by the DelayOperator extension -
dematerialize(
) → Observable< T> -
Available on Observable<
Dematerialize events of this Observable into from a sequence of Event objects.Event< , provided by the DematerializeOperator extensionT> > -
distinct(
{Predicate2< T, T> ? equals, Map1<T, int> ? hashCode}) → Observable<T> -
Available on Observable<
Emits all items emitted by this Observable that are distinct from the previous ones.T> , provided by the DistinctOperator extension -
distinctUntilChanged<
K> ({Map1< T, K> ? key, Predicate2<K, K> ? compare}) → Observable<T> -
Available on Observable<
Emits all items emitted by this Observable that are different from the previous one.T> , provided by the DistinctUntilChangedOperator extension -
endWith(
Observable< T> observable) → Observable<T> -
Available on Observable<
Appends the emission of items with an Observable.T> , provided by the ConcatOperator extension -
exhaustAll(
{int concurrent = 1}) → Observable< T> -
Available on Observable<
Emits and completes higher-order Observable. Subscribes to at mostObservable< , provided by the ExhaustAllOperator extensionT> >concurrent
sources, and drops observables exceeding this threshold. -
exhaustMap<
R> (Map1< T, Observable< project, {int concurrent = 1}) → Observable<R> >R> -
Available on Observable<
Emits and completes values from a higher-order Observable retrieved by projecting the values of the source to higher-order Observables. Subscribes to at mostT> , provided by the ExhaustMapOperator extensionconcurrent
sources, drops observables exceeding this threshold. -
exhaustMapTo<
R> (Observable< R> observable, {int concurrent = 1}) → Observable<R> -
Available on Observable<
Emits and completes values from single higher-order Observable. Subscribes to at mostT> , provided by the ExhaustMapOperator extensionconcurrent
sources, drops observables exceeding this threshold. -
finalize(
CompleteCallback finalize) → Observable< T> -
Available on Observable<
Return an Observable that mirrors this Observable, but will call a specified function when the source terminates on completion or error.T> , provided by the FinalizeOperator extension -
findFirst(
Predicate1< T> predicate) → Observable<T> -
Available on Observable<
Emits the first item of this Observable sequence matching theT> , provided by the FirstOperator extensionpredicate
, or emits an TooFewError otherwise. -
findFirstOrDefault(
Predicate1< T> predicate, T value) → Observable<T> -
Available on Observable<
Emits the first item of this Observable sequence matching theT> , provided by the FirstOperator extensionpredicate
, or the provided defaultvalue
otherwise. -
findFirstOrElse(
Predicate1< T> predicate, Map0<T> callback) → Observable<T> -
Available on Observable<
Emits the first item of this Observable sequence matching theT> , provided by the FirstOperator extensionpredicate
, or evaluate the providedcallback
otherwise. -
findLast(
Predicate1< T> predicate) → Observable<T> -
Available on Observable<
Emits the last item of this Observable matching theT> , provided by the LastOperator extensionpredicate
, or emits an TooFewError otherwise. -
findLastOrDefault(
Predicate1< T> predicate, T value) → Observable<T> -
Available on Observable<
Emits the last item of this Observable matching theT> , provided by the LastOperator extensionpredicate
, or the provided defaultvalue
otherwise. -
findLastOrElse(
Predicate1< T> predicate, Map0<T> callback) → Observable<T> -
Available on Observable<
Emits the last item of this Observable matching theT> , provided by the LastOperator extensionpredicate
, or evaluate the providedcallback
otherwise. -
first(
) → Observable< T> -
Available on Observable<
Emits the first item of this Observable, or emits an TooFewError otherwise.T> , provided by the FirstOperator extension -
firstOrDefault(
T value) → Observable< T> -
Available on Observable<
Emits the first item of this Observable, or the provided defaultT> , provided by the FirstOperator extensionvalue
otherwise. -
firstOrElse(
Map0< T> callback) → Observable<T> -
Available on Observable<
Emits the first item of this Observable, or evaluate the providedT> , provided by the FirstOperator extensioncallback
otherwise. -
flatMap<
R> (Map1< T, Observable< project, {int concurrent = maxInteger}) → Observable<R> >R> -
Available on Observable<
For each value of this Observable, transform that value to a higher-order observable with the providedT> , provided by the FlatMapOperator extensionproject
function and merge its emitted values. Subscribe to at mostconcurrent
sources. -
flatMapTo<
R> (Observable< R> observable, {int concurrent = maxInteger}) → Observable<R> -
Available on Observable<
For each value of this Observable, merge all values from the single higher-orderT> , provided by the FlatMapOperator extensionobservable
. Subscribe to at mostconcurrent
sources. -
flatten(
{int concurrent = maxInteger}) → Observable< T> -
Available on Observable<
For each observable of this Observable, subscribe to at mostObservable< , provided by the FlattenObservable extensionT> >concurrent
observables and emit all values. -
fold<
R> (R initialValue, Map2< R, T, R> transform) → Observable<R> -
Available on Observable<
Combines a sequence of values by repeatedly applyingT> , provided by the FoldOperator extensiontransform
, starting with the providedinitialValue
. -
ignoreElements(
) → Observable< T> -
Available on Observable<
Ignores all items emitted by this Observable and only passes errors and completion events.T> , provided by the IgnoreElementsOperator extension -
isEmpty(
) → Observable< bool> -
Available on Observable<
EmitsT> , provided by the IsEmptyOperator extensiontrue
if this Observable completes without emitting any values, otherwise emitsfalse
. -
last(
) → Observable< T> -
Available on Observable<
Emits the last item of this Observable, or emits an TooFewError otherwise.T> , provided by the LastOperator extension -
lastOrDefault(
T value) → Observable< T> -
Available on Observable<
Emits the last item of this Observable, or the provided defaultT> , provided by the LastOperator extensionvalue
otherwise. -
lastOrElse(
Map0< T> callback) → Observable<T> -
Available on Observable<
Emits the last item of this Observable, or evaluate the providedT> , provided by the LastOperator extensioncallback
otherwise. -
map<
R> (Map1< T, R> transform) → Observable<R> -
Available on Observable<
Applies the given projection functionT> , provided by the MapOperator extensiontransform
to each value emitted by this Observable, and emits the resulting value. -
mapTo<
R> (R value) → Observable< R> -
Available on Observable<
Emits a constantT> , provided by the MapOperator extensionvalue
for each value emitted by this Observable. -
materialize(
) → Observable< Event< T> > -
Available on Observable<
Materializes the events of this Observable as Event objects.T> , provided by the MaterializeOperator extension -
mergeAll(
{int concurrent = maxInteger}) → Observable< T> -
Available on Observable<
For each observable of this Observable, subscribe to at mostObservable< , provided by the MergeAllOperator extensionT> >concurrent
observables and emit all values. -
mergeMap<
R> (Map1< T, Observable< project, {int concurrent = maxInteger}) → Observable<R> >R> -
Available on Observable<
For each value of this Observable, transform that value to a higher-order observable with the providedT> , provided by the MergeMapOperator extensionproject
function and merge its emitted values. Subscribe to at mostconcurrent
sources. -
mergeMapTo<
R> (Observable< R> observable, {int concurrent = maxInteger}) → Observable<R> -
Available on Observable<
For each value of this Observable, merge all values from the single higher-orderT> , provided by the MergeMapOperator extensionobservable
. Subscribe to at mostconcurrent
sources. -
multicast(
{Subject< T> ? subject, Map0<Subject< ? factory}) → ConnectableObservable<T> >T> -
Available on Observable<
Returns an multicast observable that shares the underlying stream.T> , provided by the MulticastOperator extension -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
observeOn(
Scheduler scheduler, {Duration? delay}) → Observable< T> -
Available on Observable<
Re-emits all notifications from this Observable with a custom scheduler.T> , provided by the ObserveOnOperator extension -
pairwise(
) → Observable< (T, T)> -
Available on Observable<
Groups the items emitted by an Observable into a record type that represent the latest pair of items emitted by the source Observable.T> , provided by the PairwiseOperator extension -
publishBehavior(
T value) → ConnectableObservable< T> -
Available on Observable<
Creates a ConnectableObservable that emits its initial or last seen value to its subscribers.T> , provided by the PublishOperator extension -
publishLast(
) → ConnectableObservable< T> -
Available on Observable<
Creates a ConnectableObservable that emits its last value to all its subscribers on completion.T> , provided by the PublishOperator extension -
publishReplay(
{int? bufferSize}) → ConnectableObservable< T> -
Available on Observable<
Creates a ConnectableObservable that replays all its previous values to new subscribers.T> , provided by the PublishOperator extension -
reduce(
Map2< T, T, T> transform) → Observable<T> -
Available on Observable<
Combines a sequence of values by repeatedly applyingT> , provided by the ReduceOperator extensiontransform
. -
repeat(
[int count = maxInteger]) → Observable< T> -
Available on Observable<
Resubscribes on this observableT> , provided by the RepeatOperator extensioncount
times. -
sample<
R> (Observable< R> trigger) → Observable<T> -
Available on Observable<
Emits the most recently emitted value from this Observable whenever theT> , provided by the SampleOperator extensiontrigger
emits. -
sampleTime(
Duration duration, {Scheduler? scheduler}) → Observable< T> -
Available on Observable<
Emits the most recently emitted value from this Observable within periodic time intervals.T> , provided by the SampleOperator extension -
single(
) → Observable< T> -
Available on Observable<
Emits the single element of this Observable, or emits TooFewError if there was no element, or emits TooManyError if there was more than 1 element.T> , provided by the SingleOperator extension -
singleOrDefault(
{required T tooFew, required T tooMany}) → Observable< T> -
Available on Observable<
Emits the single element of this Observable, or emitsT> , provided by the SingleOperator extensiontooFew
if there was no element, or emitstooMany
if there was more than 1 element. -
singleOrElse(
{required Map0< T> tooFew, required Map0<T> tooMany}) → Observable<T> -
Available on Observable<
Emits the single element of this Observable, or evaluates theT> , provided by the SingleOperator extensiontooFew
callback if there was no element, or evaluates thetooMany
callback if there was more than 1 element. -
skip(
[int count = 1]) → Observable< T> -
Available on Observable<
Skips over the firstT> , provided by the SkipOperator extensioncount
values before starting to emit. -
skipUntil<
R> (Observable< R> trigger) → Observable<T> -
Available on Observable<
Skips over all values until an Observable emits a first value.T> , provided by the SkipUntilOperator extension -
skipWhile(
Predicate1< T> predicate) → Observable<T> -
Available on Observable<
Skips over the values while theT> , provided by the SkipWhileOperator extensionpredicate
istrue
. -
subscribe(
Observer< S> observer) → Disposable -
Subscribes with the provided
observer
.inherited -
switchAll(
) → Observable< T> -
Available on Observable<
Emits values only from the most recently received higher-order Observable.Observable< , provided by the SwitchAllOperator extensionT> > -
switchMap<
R> (Map1< T, Observable< project) → Observable<R> >R> -
Available on Observable<
Emits values from the most recent higher-order Observable retrieved by projecting the values of the source to higher-order Observables.T> , provided by the SwitchMapOperator extension -
switchMapTo<
R> (Observable< R> observable) → Observable<R> -
Available on Observable<
Emits all values from the most recent higher-orderT> , provided by the SwitchMapOperator extensionobservable
. -
take(
[int count = 1]) → Observable< T> -
Available on Observable<
Emits the firstT> , provided by the TakeOperator extensioncount
values before completing. -
takeLast(
[int count = 1]) → Observable< T> -
Available on Observable<
Emits the lastT> , provided by the TakeLastOperator extensioncount
values emitted by the source. -
takeUntil<
R> (Observable< R> trigger) → Observable<T> -
Available on Observable<
Emits values until an Observable emits a first value.T> , provided by the TakeUntilOperator extension -
takeWhile(
Predicate1< T> predicate, {bool inclusive = false}) → Observable<T> -
Available on Observable<
Emits values while theT> , provided by the TakeWhileOperator extensionpredicate
returnstrue
. -
tap(
Observer< T> handler) → Observable<T> -
Available on Observable<
Perform a side effect for every emission on the source.T> , provided by the TapOperator extension -
throttle<
R> (DurationSelector< T, R> durationSelector, {bool leading = true, bool trailing = true}) → Observable<T> -
Available on Observable<
Emits a value from this Observable, then ignores values for the duration until the Observable returned byT> , provided by the ThrottleOperator extensiondurationSelector
triggers a value or completes. -
throttleTime(
Duration duration, {bool leading = true, bool trailing = true, Scheduler? scheduler}) → Observable< T> -
Available on Observable<
Emits a value from this Observable, then ignores values forT> , provided by the ThrottleOperator extensionduration
. -
timeout(
{Duration? first, Duration? between, Duration? total, Scheduler? scheduler}) → Observable< T> -
Available on Observable<
totals with a TimeoutError, if the observable fails to emit a value in the given time span.T> , provided by the TimeoutOperator extension -
toFuture(
) → Future< T> -
Available on Observable<
Returns a Future that completes with the first value of this Observable.T> , provided by the ObservableToFuture extension -
toList(
[Map0< List< ? constructor]) → Observable<T> >List< T> > -
Available on Observable<
Returns a List from an observable sequence.T> , provided by the ToListOperator extension -
toListMultimap<
K, V> ({Map0< ListMultimap< ? constructor, Map1<K, V> >T, K> ? keySelector, Map1<T, V> ? valueSelector}) → Observable<ListMultimap< K, V> > -
Available on Observable<
Returns aT> , provided by the ToMapOperator extensionListMultimap
from an observable sequence. -
toMap<
K, V> ({Map0< Map< ? constructor, Map1<K, V> >T, K> ? keySelector, Map1<T, V> ? valueSelector}) → Observable<Map< K, V> > -
Available on Observable<
Returns a Map from an observable sequence.T> , provided by the ToMapOperator extension -
toSet(
[Map0< Set< ? constructor]) → Observable<T> >Set< T> > -
Available on Observable<
Returns a Set from an observable sequence.T> , provided by the ToSetOperator extension -
toSetMultimap<
K, V> ({Map0< SetMultimap< ? constructor, Map1<K, V> >T, K> ? keySelector, Map1<T, V> ? valueSelector}) → Observable<SetMultimap< K, V> > -
Available on Observable<
Returns aT> , provided by the ToMapOperator extensionSetMultimap
from an observable sequence. -
toStream(
) → Stream< T> -
Available on Observable<
Returns a Stream that subscribes to and emits the values of this Observable.T> , provided by the ObservableToStream extension -
toString(
) → String -
A string representation of this object.
inherited
-
update(
Updater< S> updater) → S - Updates the current state.
-
where(
Predicate1< T> predicate) → Observable<T> -
Available on Observable<
Filter items emitted by the source Observable by only emitting those that satisfy a specified predicate.T> , provided by the WhereOperator extension -
whereType<
R> () → Observable< R> -
Available on Observable<
Filter items emitted by the source Observable by only emitting those that are of the specified type.T> , provided by the WhereTypeOperator extension
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited