Views

An interface for retrieving and managing views.

Hooks provide access to views and related data from inside React components. Unlike data accessed using static methods, hooks will cause the component to rerender when the data changes.

Returns a view instance by ID or null if no view instance was found.

useViewInstance<T extends ViewInstance>(viewInstanceId: string): T | null
ArgumentTypeDescription
viewInstanceId*stringThe ID of the view instance to retrieve.

Returns a { [id]: ViewInstance | null } map of view instances matching the provided IDs (null if the view instance does not exist).

useViewInstances<T extends ViewInstance>(viewInstanceIds: string[]): ViewInstanceMap<T>
ArgumentTypeDescription
viewInstanceIds*string[]The IDs of the view instances to retrieve.

Returns a view by ID. Throws a ViewNotRegisteredError if the requested view is not registered.

Views.get(viewId: string): View
ArgumentTypeDescription
viewId*stringThe ID of the view to retrieve.

Returns a view instance by ID. Throws a ViewInstanceNotFoundError if the view instance does not exist.

Views.getInstance<T extends ViewInstance>(viewInstanceId: string): T
ArgumentTypeDescription
viewInstanceId*stringThe ID of the view instance to retrieve.

Returns a { [id]: ViewInstance | null } map of view instances matching the provided IDs (null if the view instance does not exist).

Views.getInstances<T extends ViewInstance>(viewInstanceIds: string[]): ViewInstanceMap<T>
ArgumentTypeDescription
viewInstanceIds*string[]The IDs of the view instances to retrieve.

Registers a new view and dispatches a views:register event. View need to be registered before they can be opened.

Views.register(core: Core, view: ViewConfig): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
view*ViewConfig The view to register. See the View interface for details.

Unregisters a view and dispaches a views:unregister event.

Views.unregsiter(core: Core, viewId: string): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
viewId*stringThe ID of the view to unregister.

Creates a new view instance and dispatches a views:create-instance event. Returns the new view instance.

Views.createInstance< D extends CreateViewInstanceData, I extends ViewInstance, >(core: Core, data: D): I
ArgumentTypeDescription
core*CoreA MindDrop core instance.
data*CreateViewInstanceDataThe view instance data. See the below for details.

CreateViewInstanceData

PropertyTypeDescription
view*stringThe ID of the view rendered by this view instance. The view in question must first be registered.

Additionally, view instances support adding any custom data fields needed for the view. The only restricted fields are id, createdAt, and updatedAt which are automatically generated by the createInstance method.

Updates a view instance and dispaches a views:update-instance event. Returns the updated view instance.

Views.updateInstance< D extends UpdateViewInstanceData, I extends ViewInstance, >(core: Core, viewInstanceId: string, data: D): I
ArgumentTypeDescription
core*CoreA MindDrop core instance.
viewInstanceId*stringThe ID of the view instance to update.
data*UpdateViewInstanceData The updates to apply to the resouce view. Supports FieldValue mutations. See below for details.

UpdateViewInstanceData

Supports FieldValue mutations.

PropertyTypeDescription
viewstringThe ID of the view rendered by this view instance.

Additionally, view instances support adding/modifying any custom data fields needed for the view. The only restricted fields are id, createdAt, and updatedAt which are automatically generated by the createInstance method.

Deletes a view instance and dispatches a views:delete-instance event. Returns the deleted view instance.

Views.deleteInstance<T extends ViewInstance>(core: Core, viewInstanceId: string): T
ArgumentTypeDescription
core*CoreA MindDrop core instance.
viewInstanceId*stringThe ID of the view instance to delete.

Loads view instances into the store and dispatches a views:load-instances event.

Views.loadInstances(core: Core, viewInstances: ViewInstance[]): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
viewInstances*ViewInstance[]The view instances to load into the store.

Clears all registered views and view instances from the store and dispatches a views:clear event.

Views.clear(core: Core): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.

Adds view specific event listeners. Equivalent to calling addEventListener directly on core, but provides more advanced type definitions.

Views.addEventListener(core: Core, event: ViewEvent, callback: EventListenerCallback): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
event*ViewEventThe event type to listen for. See the view events section below for available events.
callback*EventListenerCallbackThe callback fired when the event occurs. See the view events section below for the data passed to the callback.

Removes view specific event listeners. Equivalent to calling removeEventListener directly on core, but provides more advanced type definitions.

Views.removeEventListener(core: Core, event: ViewEvent, callback: EventListenerCallback): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
event*ViewEventThe event type for which to remove the event listener.
callback*EventListenerCallbackThe callback of the event listener to remove.

View events are prefixed with the namespace views.

See below the table for more details on the data passed by view related events.

NameDataDescription
views:registerViewDispatched when a view is registered.
views:unregisterViewDispatched when a view is unregistered.
views:create-instanceViewInstanceDispatched when a view instance is created.
views:update-instanceUpdateViewInstanceEventDataDispatched when a view instance is updated.
views:delete-instanceViewInstanceDispatched when a view instance is deleted.
views:load-instancesViewInstance[]Dispatched when view instances are loaded into the store.
views:clearNo dataDispatched when the views store is cleared.

View events are dispatched with one of the following types of data.

View

See the View interface page.

ViewInstance

See the ViewInstance interface page.

UpdateViewInstanceEventData

PropertyTypeDescription
before*ViewInstanceViewInstance data before it was changed.
after*ViewInstanceUpdated view instance data.
changes*ViewInstanceChangesThe changes made to the view instance. See below for details.

ViewInstanceChanges

PropertyTypeDescription
updatedAt*DateThe timestamp at which the view instance was updated.
viewstringThe ID of the view rendered by this view instance.

Additionally, view instances support adding/modifying custom data fields which will be included in the ViewInstanceChanges data if changed.