Table of Contents

Class QueryViewModelExtensions

Namespace
DotNetQuery.Mvvm
Assembly
DotNetQuery.Mvvm.dll

Extension methods that wrap DotNetQuery.Core types in view models, and marshal arbitrary observables onto the UI thread.

public static class QueryViewModelExtensions
Inheritance
QueryViewModelExtensions
Inherited Members

Methods

ObserveOnUi<T>(IObservable<T>, IUiDispatcher?)

Marshals every emission of source onto the UI thread via dispatcher — one dispatcher post per emission. Unlike the coalescing state binding the view models use internally, nothing here is dropped or collapsed: use this for event streams — Success, Failure, Success, Settled, and the like — where missing an emission would be a bug, unlike a snapshot of the latest state.

dispatcher is captured when this method is called, not when the returned observable is subscribed. Call it on the UI thread, or pass a dispatcher explicitly, no matter where the eventual subscription happens.

A callback already posted when the subscription is disposed, but not yet run, becomes a no-op instead of calling into the observer.

public static IObservable<T> ObserveOnUi<T>(this IObservable<T> source, IUiDispatcher? dispatcher = null)

Parameters

source IObservable<T>

The source observable.

dispatcher IUiDispatcher

The UI-thread dispatcher. When null, Current is captured at the moment this method is called.

Returns

IObservable<T>

Type Parameters

T

The element type.

ToViewModel<TArgs, TData>(IMutation<TArgs, TData>, CompositeDisposable?, IUiDispatcher?)

Wraps mutation in a MutationViewModel<TArgs, TData>. The returned view model does not take ownership: disposing it releases only its own state subscription, and the caller remains responsible for disposing mutation.

public static MutationViewModel<TArgs, TData> ToViewModel<TArgs, TData>(this IMutation<TArgs, TData> mutation, CompositeDisposable? disposeWith = null, IUiDispatcher? dispatcher = null)

Parameters

mutation IMutation<TArgs, TData>

The mutation to wrap.

disposeWith CompositeDisposable

When not null, the returned view model is added to this container, so disposing the container disposes the view model — releasing its subscription, never mutation. If the container is already disposed, the view model is disposed immediately.

dispatcher IUiDispatcher

The UI-thread dispatcher. When null, Current is captured; call this on the UI thread or pass a dispatcher explicitly.

Returns

MutationViewModel<TArgs, TData>

Type Parameters

TArgs
TData

ToViewModel<TArgs, TData>(IQuery<TArgs, TData>, CompositeDisposable?, IUiDispatcher?)

Wraps query in a QueryViewModel<TArgs, TData>. The returned view model does not take ownership: disposing it releases only its own state subscription, and the caller remains responsible for disposing query.

public static QueryViewModel<TArgs, TData> ToViewModel<TArgs, TData>(this IQuery<TArgs, TData> query, CompositeDisposable? disposeWith = null, IUiDispatcher? dispatcher = null) where TData : class

Parameters

query IQuery<TArgs, TData>

The query to wrap.

disposeWith CompositeDisposable

When not null, the returned view model is added to this container, so disposing the container disposes the view model — releasing its subscription, never query. If the container is already disposed, the view model is disposed immediately.

dispatcher IUiDispatcher

The UI-thread dispatcher. When null, Current is captured; call this on the UI thread or pass a dispatcher explicitly.

Returns

QueryViewModel<TArgs, TData>

Type Parameters

TArgs
TData

ToViewModel<TArgs, TData, TPageParam>(IInfiniteQuery<TArgs, TData, TPageParam>, CompositeDisposable?, IUiDispatcher?)

Wraps query in an InfiniteQueryViewModel<TArgs, TData, TPageParam>. The returned view model does not take ownership: disposing it releases only its own state subscription, and the caller remains responsible for disposing query.

public static InfiniteQueryViewModel<TArgs, TData, TPageParam> ToViewModel<TArgs, TData, TPageParam>(this IInfiniteQuery<TArgs, TData, TPageParam> query, CompositeDisposable? disposeWith = null, IUiDispatcher? dispatcher = null) where TData : class

Parameters

query IInfiniteQuery<TArgs, TData, TPageParam>

The infinite query to wrap.

disposeWith CompositeDisposable

When not null, the returned view model is added to this container, so disposing the container disposes the view model — releasing its subscription, never query. If the container is already disposed, the view model is disposed immediately.

dispatcher IUiDispatcher

The UI-thread dispatcher. When null, Current is captured; call this on the UI thread or pass a dispatcher explicitly.

Returns

InfiniteQueryViewModel<TArgs, TData, TPageParam>

Type Parameters

TArgs
TData
TPageParam