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
Argument | Type | Description |
---|---|---|
viewInstanceId* | string | The 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>
Argument | Type | Description |
---|---|---|
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
Argument | Type | Description |
---|---|---|
viewId* | string | The 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
Argument | Type | Description |
---|---|---|
viewInstanceId* | string | The 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>
Argument | Type | Description |
---|---|---|
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
Argument | Type | Description |
---|---|---|
core* | Core | A 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
viewId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
data* | CreateViewInstanceData | The view instance data. See the below for details. |
CreateViewInstanceData
Property | Type | Description |
---|---|---|
view* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
viewInstanceId* | string | The 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.
Property | Type | Description |
---|---|---|
view | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
viewInstanceId* | string | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A 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
Argument | Type | Description |
---|---|---|
core* | Core | A 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
event* | ViewEvent | The event type to listen for. See the view events section below for available events. |
callback* | EventListenerCallback | The 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
Argument | Type | Description |
---|---|---|
core* | Core | A MindDrop core instance. |
event* | ViewEvent | The event type for which to remove the event listener. |
callback* | EventListenerCallback | The 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.
Name | Data | Description |
---|---|---|
views:register | View | Dispatched when a view is registered. |
views:unregister | View | Dispatched when a view is unregistered. |
views:create-instance | ViewInstance | Dispatched when a view instance is created. |
views:update-instance | UpdateViewInstanceEventData | Dispatched when a view instance is updated. |
views:delete-instance | ViewInstance | Dispatched when a view instance is deleted. |
views:load-instances | ViewInstance[] | Dispatched when view instances are loaded into the store. |
views:clear | Dispatched when the views store is cleared. |
View events are dispatched with one of the following types of data.
See the View interface page.
See the ViewInstance interface page.
Property | Type | Description |
---|---|---|
before* | ViewInstance | ViewInstance data before it was changed. |
after* | ViewInstance | Updated view instance data. |
changes* | ViewInstanceChanges | The changes made to the view instance. See below for details. |
ViewInstanceChanges
Property | Type | Description |
---|---|---|
updatedAt* | Date | The timestamp at which the view instance was updated. |
view | string | The 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.