Topics

An interface for retrieving and managing topics.

Hooks provide access to topics 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 topic by ID or null if no topic was found.

useTopic(topicId: string): Topic | null
ArgumentTypeDescription
topicId*stringThe ID of the topic to retrieve.

Returns a TopicMap of topics matching the provided IDs. Returned topics can be filtered by passing in TopicFilters.

useTopics(topicIds: string[], filters?: TopicFilters): TopicMap
ArgumentTypeDescription
topicIdsstring[]The IDs of the topics to retrieve.
filtersTopicFilters Allows filtering of returned topics. See the TopicFilters section for more details.

Returns a TopicMap map of all topics. Returned topics can be filtered by passing in TopicFilters.

useAllTopics(filters?: TopicFilters): TopicMap
ArgumentTypeDescription
filtersTopicFilters Allows filtering of returned topics. See the TopicFilters section for more details.

Returns an { [id]: Topic } map of a given topic's parents. The results can be filtered by passing in `TopicFilters``.

useTopicParents(topicId: string, filters?: TopicFilters): TopicMap
ArgumentTypeDescription
topicId*stringThe ID of the topic for which to retrieve the parents.
filtersTopicFilters Allows filtering of returned topics. See the TopicFilters section for more details.

Retrieves topics by ID. If provided a single ID string, returns the topic. If provided an array of IDs, returns a TopicMap of the corresponding topics. Returned topics can be filtered by passing in TopicFilters. Filtering is not supported when getting a single topic.

Throws a TopicNotFoundError if one or more of the requested topics does not exist.

Topics.get(topicId: string | string[], filters?: TopicFilters): Topic | TopicMap
ArgumentTypeDescription
topicId*string | string[]The ID(s) of the topic(s) to retrieve.
filtersTopicFilters Allows filtering of returned topics. See the TopicFilters section for more details.

Retrieves all topics, returning a TopicMap. Returned topics can be filtered by passing in TopicFilters.

Topics.getAll(filters?: TopicFilters): Topic | TopicMap
ArgumentTypeDescription
filtersTopicFilters Allows filtering of returned topics. See the TopicFilters section for more details.

Retrieves a drop's parent topics returned as a TopicMap. Returned topics can be filtered by passing in TopicFilters.

Topics.getDropParentTopics(topicId: string, filters?: TopicFilters): TopicMap
ArgumentTypeDescription
topicId*stringThe ID of the drop for which to retrieve the parent topics.
filtersTopicFilters Allows filtering of returned topics. See the TopicFilters section for more details.

Filters topics according to provided filters.

Topics.filter(topics: TopicMap, filters: TopicFilters): TopicMap
ArgumentTypeDescription
topicsTopicMapThe topics to filter.
filtersTopicFilters Filtering options. See the TopicFilters section for more details.

Checks whether a topic is a descendant of other topics. A descendant topic can be nested multiple levels deep inside the parent topic.

Topics.isDescendant(descendantTopicId: string, parentTopicIds: string[]): boolean
ArgumentTypeDescription
descendantTopicId*stringThe ID of the topic which may be a descendant.
parentTopicIds*stringThe IDs of the topics which may be a parent.

Creates a new topic and dispatches a topics:create event. Returns the new topic.

Topics.create(core: Core, data?: CreateTopicData): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
dataCreateTopicDataThe default topic property values. See below for details.

CreateTopicData

PropertyTypeDescription
titlestringThe topic title.
hiddentrueIf set, the topic will be created as a hidden topic.

Updates a topic and dispatches a topics:update event. Returns the updated topic.

Topics.update(core: Core, topicId: string, data: UpdateTopicData): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic to update.
data*UpdateTopicDataThe changes to apply to the topic. See below for details.

UpdateTopicData

PropertyTypeDescription
titlestringThe topic title.

Deletes a topic and dispatches a topics:delete event and a topics:update event. Returns the deleted topic.

Deleted topics are not removed from the store but instead marked as deleted using deleted: true and deletedAt: Date properties. Deleted topics can be restored using the Topics.restore method. To permanently delete a topic and remove it from the store, use Topics.deletePermanently.

Topics.delete(core: Core, topicId: string): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic to delete.

Restores a deleted topic and dispatches a topics:restore event and a topics:update event. Returns the restored topic.

Topics.restore(core: Core, topicId: string): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic to restore.

Permanently deletes a topic and all of its view instances and dispatches a topics:delete-permanently event. The topic is also removed as a parent from its drops and subtopics. Returns the deleted topic.

Permanently deleted topics cannot be restored.

Topics.deletePermanently(core: Core, topicId: string): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic to delete.

Adds subtopics into a parent topic. Dispatches an topics:topic:add-subtopics event, as well as topics:topic:update event. Returns the updated topic.

Topics.addSubtopics(
core: Core,
topicId: string,
subtopicIds: string[],
position?: number,
): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the parent topic into which to add the subtopic.
subtopicIds*string[]The IDs of the subtopics.
positionnumberThe index at which to add the subtopics.

Removes subtopics from a topic. Dispatches a topics:remove-subtopics event as well as topics:update event. Returns the updated topic.

Topics.removeSubtopics(core: Core, parentId: string, subtopicIds: string[]): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
parentId*stringThe ID of the parent topic from which to remove the subtopics.
subtopicIds*string[]The IDs of the subtopics to remove.

Moves subtopics from one topic to another and dispaches a topics:topic:move-subtopics event.

Topics.moveSubtopics(
core: Core,
fromTopicId: string,
toTopicId: string,
subtopicIds: string[],
position?: number
): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
fromTopicId*stringThe ID of the parent topic from which to remove the subtopics.
toTopicId*stringThe ID of the parent topic into which to add the subtopics.
subtopicIds*string[]The IDs of the subtopics to move.
positionnumberThe index at which to add the moved subtopics.

Sets a new sort order for a topic's subtopics. The provided subtopic IDs must contain the same IDs as the current value, only in a different order. Dispatches a topics:topic:sort-subtopics event. Returns the updated topic.

  • Throws a InvalidParameterError if the given subtopic IDs differ from the current subtopic IDs in anything but order.

Topics.sortSubtopics(core: Core, topicId: string, subtopicIds: string[]): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe IDs of the topic in which to sort the subtopics.
subtopicIds*string[]The IDs of the subtopics in their new sort order.

Archives subtopics in a topic and dispatches a topics:archive-subtopics event as well as a topics:update event. Returns the updated topic.

Topics.archiveSubtopics(core: Core, topicId: string, subtopicIds: string[]): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic in which to archive the subtopics.
subtopicIds*string[]The IDs of the subtopics to archive.

Unarchives subtopics in a topic and dispatches a topics:unarchive-subtopics event as well as a topics:update event. Returns the updated topic.

Topics.archiveSubtopics(core: Core, topicId: string, subtopicIds: string[]): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic in which to unarchive the subtopics.
subtopicIds*string[]The IDs of the subtopics to unarchive.

Adds drops to a topic, dispaches an topics:add-drops event and a topics:update event. Returns the updated topic.

Topics.addDrops(core: Core, topicId: string, dropIds: string[]): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic to which to add the drop.
dropIds*string[]The IDs of the drops to add.
metadataAddDropsMetadata Optional metadata about the event added by the topic view instance that triggered the event. See the TopicView interface for details.

Moves drops from one topic to another by removing them from the source topic and adding them to the destination topic. Dispatches a topics:move-drops event.

Topics.moveDrops(core: Core, fromTopicId: string, toTopicId: string, dropIds: string[], metadata: AddDropsMetadata): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
fromTopicId*stringThe ID of the source topic from which to move the drops.
toTopicId*stringThe ID of the target topic into which to move the drops.
dropIds*string[]The IDs of the drops to move.
metadataAddDropsMetadata Optional metadata about the event added by the topic view instance that triggered the move. See the TopicView interface for details.

Archives drops in a topic and dispatches a topics:archive-drops event as well as a topics:update event. Returns the updated topic.

Topics.archiveDrops(core: Core, topicId: string, dropIds: string[]): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic in which to archive the drops.
dropIds*string[]The IDs of the drops to archive.

Unarchives drops in a topic and dispatches a topics:unarchive-drops event as well as a topics:update event. Returns the updated topic.

Topics.archiveDrops(core: Core, topicId: string, dropIds: string[]): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic in which to unarchive the drops.
dropIds*string[]The IDs of the drops to unarchive.

Removes drops from a topic and dispatches a topics:remove-drops event as well as a topics:update event. Returns the updated topic.

Topics.removeDrops(core: Core, topicId: string, dropIds: string[]): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic from which to remove the drops.
dropIds*string[]The IDs of the drops to remove.

Adds parent references to a topic and dispatches a topics:add-parents event and a topics:update event. Returns the updated topic.

Topics.addParents(core: Core, topicId: string, parentReferences: TopicParentReference[]): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic to which to add the parents.
parentReferences*TopicParentReference[] The parent references to add to the topic. See the TopicParentReference interface for details.

Remove parent references from a topic and dispatches a topics:remove-parents event and a topics:update event. Returns the updated topic.

Topics.removeParents(core: Core, topicId: string, parentReferences: TopicParentReference[]): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic from which to remove the parents.
parentReferences*TopicParentReference[] The parent references to remove from the topic. See the TopicParentReference interface for details.

Returns an { [id]: Topic } map of a given topic's parents. The results can be filtered by passing in `TopicFilters``.

Topics.getParents(topicId: string, filters?: TopicFilters): TopicMap
ArgumentTypeDescription
topicId*stringThe ID of the topic for which to retrieve the parents.
filtersTopicFilters Allows filtering of returned topics. See the TopicFilters section for more details.

Adds tags to a topic, dispaches an topics:add-tags event and a topics:update event. Returns the updated topic.

Topics.addTags(core: Core, topicId: string, tagIds: string[]): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic to which to add the tags.
tagIds*string[]The IDs of the tags to add.

Removes tags from a topic and dispatches a topics:remove-tags event as well as a topics:update event. Returns the updated topic.

Topics.removesTags(core: Core, topicId: string, tagIds: string[]): Topic
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic from which to remove the tags.
tagIds*string[]The IDs of the tags to remove.

Registers a TopicView and dispaches a topics:register-view event. Registering a topic view allows the user to create instances of the view within topics. This method registers the view with the Views API (using Views.register) internally, so you do not need to do so yourself.

Topics.registerView(core: Core, view: TopicViewConfig): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
view*TopicViewConfig The view to register. See the TopicViewConfig interface for details.

Unregisters a TopicView and dispaches a topics:unregister-view event. This method unregisters the view with the Views API (using Views.unregister) internally, so you do not need to do so yourself.

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

Returns a TopicView by ID. Throws a TopicViewNotRegisteredError if the topic view is not registered.

Topics.getView(topicViewId: string): TopicView
ArgumentTypeDescription
topicViewId*stringThe ID of the topic view to retrieve.

Returns a { [id]: TopicView } map of all registered topic views.

Topics.getView(): TopicViewMap

Creates a new instance of a TopicView and adds it to the topic. The topic view must first be registered using Topics.registerView or else a TopicViewNotRegisteredError will be thrown. Returns the new view instance and dispatches a topics:create-view-instance event.

Topics.createViewInstance(core: Core, topicId: string, topicViewId: string): ViewInstance;
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicId*stringThe ID of the topic into which to add the view.
topicViewId*stringThe ID of the topic view for which to create a new instance.

Deletes a topic view instance and removes it from the topic. Returns the deleted view instance and dispatches a topics:delete-view-instance event.

Topics.deleteViewInstance(core: Core, topicViewId: string): ViewInstance
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topicViewId*stringThe ID of the topic view to delete.

Loads topics into the store and dispatches a topics:load event.

Topics.load(core: Core, topics: Topic[]): void
ArgumentTypeDescription
core*CoreA MindDrop core instance.
topics*Topic[]The topics to load into the store.

Clears the topics store and dispatches a topics:clear event.

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

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

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

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

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

Topic events are prefixed with the namespace topics.

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

NameDataDescription
topics:createTopicDispatched when a topic is created.
topics:updateUpdateTopicEventDataDispatched when a topic is updated.
topics:deleteTopicDispatched when a topic is deleted.
topics:restoreTopicDispatched when a archived/deleted topic is restored.
topics:delete-permanentlyTopicDispatched when a topic is permanently deleted.
topics:add-subtopicsAddSubtopicsEventDataDispatched when subtopics are added to a topic.
topics:remove-subtopicsRemoveSubtopicsEventDataDispatched when subtopics are removed from a topic.
topics:move-subtopicsMoveSubtopicsEventDataDispatched when subtopics are moved from one topic to another.
topics:archive-subtopicsArchiveSubtopicsEventDataDispatched when subtopics are archived inside a topic.
topics:unarchive-subtopicsUnarchiveSubtopicsEventDataDispatched when subtopics are unarchived inside a topic.
topics:add-dropsAddDropsEventDataDispatched when drops are added to a topic.
topics:remove-dropsRemoveDropsEventDataDispatched when drops are removed from a topic.
topics:move-dropsMoveDropsEventDataDispatched when drops are moved from one topic to another.
topics:archive-dropsArchiveDropsEventDataDispatched when drops inside a topic are archived.
topics:unarchive-dropsUnarchiveDropsEventDataDispatched when drops inside a topic are unarchived.
topics:add-parentsAddParentsEventDataDispatched when parents are added to a topic.
topics:remove-parentsRemoveParentsEventDataDispatched when parents are removed from a topic.
topics:add-tagsAddTagsEventDataDispatched when tags are added to a topic.
topics:remove-tagsRemoveTagsEventDataDispatched when tags are removed from a topic.
topics:register-viewTopicViewDispatched when a topic view is registered.
topics:unregister-viewTopicViewDispatched when a topic view is unregistered.
topics:create-view-intanceTopicViewInstanceDispatched when a new topic view instance is created.
topics:delete-view-intanceTopicViewInstanceDispatched when a topic view instance is deleted.
topics:loadTopic[]Dispatched when topics are loaded into the store.
topics:clearNo dataDispatched when the topics store is cleared.

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

Topic

See the Topic interface page.

UpdateTopicEventData

PropertyTypeDescription
before*TopicTopic data before it was changed.
after*TopicUpdated topic data.
changes*TopicChangesThe changes made to the topic. See below for details.

TopicChanges

PropertyTypeDescription
updatedAt*DateThe timestamp at which the topic was updated.
titlestringThe topic title.
parents| TopicParentReference[]
| ArrayUnion
| ArrayFilter
The references of the topic's parents.
subtopicsstring[]The IDs of the topics inside the topic.
dropsstring[]The IDs of the drops inside the topic.
tagsstring[]IDs of the tags belonging to the topic.
deletedboolean | Delete If true the topic is deleted.
deletedAtDate | DeleteTimestamp at which the topic was deleted.
hiddentrue | Delete If true, the topic is hidden.

AddSubtopicsEventData

PropertyTypeDescription
topic*TopicThe topic to which the subtopics were added.
subtopics*TopicMapThe subtopics added to the topic.

RemoveSubtopicsEventData

PropertyTypeDescription
topic*TopicThe topic from which the subtopics were removed.
subtopics*TopicMapThe subtopics which were removed from the topic.

MoveSubtopicsEventData

PropertyTypeDescription
fromTopic*TopicThe topic from which the subtopics were removed.
toTopic*TopicThe topic to which the subtopics were added.
subtopics*TopicMapThe subtopics which were moved.

ArchiveSubtopicsEventData

PropertyTypeDescription
topic*TopicThe topic inside which the subtopics were archived.
subtopics*TopicMapThe archived subtopics.

UnarchiveSubtopicsEventData

PropertyTypeDescription
topic*TopicThe topic inside which the subtopics were unarchived.
subtopics*TopicMapThe unarchived subtopics.

AddDropsEventData

PropertyTypeDescription
topic*TopicThe topic to which the drops were added.
drops*DropMapThe drops which were added to the topic.

ArchiveDropsEventData

PropertyTypeDescription
topic*TopicThe topic in which the drops were archived.
drops*DropMapThe drops which were archived.

UnarchiveDropsEventData

PropertyTypeDescription
topic*TopicThe topic in which the drops were unarchived.
drops*DropMapThe drops which were unarchived.

RemoveDropsEventData

PropertyTypeDescription
topic*TopicThe topic from which the drops were removed.
drops*DropMapThe drops which were removed from the topic.

MoveDropsEventData

PropertyTypeDescription
fromTopic*TopicThe topic from which the drops were removed.
toTopic*TopicThe topic to which the drops were added.
drops*DropMapThe drops which were moved.

AddParentsEventData

PropertyTypeDescription
topic*TopicThe topic to which the parents were added.
parents*TopicParentReference[]The references of the parents which were added to the topic.

RemoveParentsEventData

PropertyTypeDescription
topic*TopicThe topic from which the parents were removed.
parents*TopicParentReference[]The references of the parents which were removed from the topic.

AddTagsEventData

PropertyTypeDescription
topic*TopicThe topic to which the tags were added.
tags*TagMapThe tags which were added to the topic.

RemoveTagsEventData

PropertyTypeDescription
topic*TopicThe topic from which the tags were removed.
tags*TagMapThe tags which were removed from the topic.

Topics can be filtered using one or more of the options below.

By default, deleted topics are filtered out. If deleted is set to true, active topics will be filtered out by default unless active is also set to true.

A topic is considered active if it is not deleted.

PropTypeDefault
activebooleantrue
deletedbooleanfalse