🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
ValueStore Pattern
This page was created by Wikiadmin on 2026-07-29. Last edited by Wikiadmin on 2026-07-29.

You can use the ValueStore pattern to give an un-rooted ViewModel a collection context when you need to show, search, or edit a set of persisted objects.

What the pattern does

A ValueStore is a class in your main model whose instances provide the starting collection for an un-rooted ViewModel. The ViewModel root has no main-model object as its context, so it has no self. A child ViewModel class can instead use ValueStore.allInstances to obtain every persisted ValueStore object.

For example, an un-rooted ViewModel can contain a blue collection ViewModel class named ValueStore. Give that collection the expression:

ValueStore.allInstances

Each item in the resulting collection has a ValueStore object as its context. Within that item ViewModel class, self refers to the current ValueStore object.

When to use it

Use this pattern when the view must start without a selected domain object.

Requirement Use of the ValueStore pattern
Show all objects of a class Use ValueStore.allInstances as the collection source.
Search for a subset of objects Start from the ValueStore collection and use the ViewModel's search input and database search capabilities to find matching objects.
Edit objects in a complete or partial list Bind the collection item ViewModel class to each ValueStore object so that it has a self context.

A common use case is a Seeker: the user enters a search term and the view finds relevant objects. The ViewModel itself remains un-rooted because it does not begin with one selected object.

Rooted and un-rooted ViewModels

A rooted ViewModel has a main-model object as the context of its root ViewModel class. The root therefore has self. Use it to show one object, its attributes, and related information.

For example, if the root context is a Thing, a details collection can navigate from self to that Thing's details. Each detail item then has a Detail object as its context.

An un-rooted ViewModel has no root context and no root self. The ValueStore pattern supplies context at the collection-item level instead.

ViewModel type Root context Example
Rooted A selected main-model object Show one Thing and its details.
Un-rooted with ValueStore No root object; collection items get context from ValueStore.allInstances Show or search a list of ValueStore objects.

Naming the un-rooted root

The class selected for an un-rooted ViewModel root usually does not affect its behavior because the root has no context. Name or select it to communicate the purpose of the view to developers.

For example, use a root name that indicates a seeker or list use case, while the child collection class is named ValueStore and receives its context from ValueStore.allInstances.

See also