ViewModelStore
interface
Interface represeting a store for managing ViewModels
TIP
Not required entity for targeted usage of this package, but can be helpful for accessing ViewModels from everywhere by ViewModel id or ViewModel class name.
Method and properties
getIds(vmLookup)
Retrieves ids ViewModels based on vmLookup.
Example
vmStore.getIds(MyVM) // ["id"]
vmStore.getIds(ViewComponentOfMyVM) // ["id"]
getId(vmLookup)
Retrieves the id
of the last ViewModel based on vmLookup.
Example
vmStore.getId(MyVM) // "id"
vmStore.getId(ViewComponentOfMyVM) // "id"
mountedViewsCount
The total number of views that are currently mounted.
has(vmLookup)
Checks whether a ViewModel instance exists in the store.
Requires vmLookup.
get(vmLookup)
Retrieves the last ViewModel instance from the store based on vmLookup.
TIP
If you node more than one VM use getAll(vmLookup) method
Example
import { mobx-view-model } from "mobx-view-model";
class UserSelectVM extends ViewModelBase {
selectedUser = {
id: '1',
name: 'John Doe'
}
}
vmStore.get(UserSelectVM)?.selectedUser.id; // '1'
getAll(vmLookup)
Retrieves all ViewModel instances from the store based on vmLookup.
attach(viewModel)
Attaches a ViewModel to the store.
dettach(viewModelId)
Detaches a ViewModel from the store using its ID.
isAbleToRenderView(viewModelId)
Determines if a ViewModel is able to render based on its ID.
createViewModel(config)
Creates a new ViewModel instance based on the provided configuration.
processCreateConfig(config)
Process the configuration for creating a ViewModel.
This method is called just before creating a new ViewModel instance.
It's useful for initializing the configuration, like linking components to the ViewModel class.
linkComponents()
Link React components with ViewModel class.
unlinkComponents()
Unlink React components with ViewModel class.
generateViewModelId(config)
Generates a unique ID for a ViewModel based on the provided configuration.
clean()
Clean up resources associated with the ViewModel store.
Clean all inner data structures.