IObservableMap | Matterport SDK
Usage of the SDK constitutes your agreement with the Matterport SDK Agreement. Email developers@matterport.com with any questions.

A map that can have its changes observed via subscribing an IMapObserver or that can be waited on for a specific condition to be met.

Type parameters

  • ItemT

    The type of the items in the map being observed.

Hierarchy

  • IObservableMap

Index

Methods

subscribe

  • Subscribe to changes in this map.

    When this observable detects a change, the observer provided will have its onAdded, onRemoved, and/or onUpdated called.

    • observer.onAdded will be called when an item is added to the collection
    • observer.onRemoved will be called when an item is removed from the collection
    • observer.onUpdated will be called when an item has some of its properties changed
    • observer.onCollectionUpdated will be called after some set of the above events have occured (item added/removed/updated)

    When first subscribing, the observers' onAdded will be called for each item in the collection. The same is true for onCollectionUpdated which provides the latest view of the entire collection onCollectionUpdated and onAdded continue to fire as changes to the collection occur.

    const subscription = sdk.Tag.data.subscribe({
      onAdded: (index, item, collection) => {
        console.log(`Tag added at index ${index}:`, item);
      },
      onRemoved: (index, item, collection) => {
        console.log(`Tag removed from index ${index}:`, item);
      },
      onUpdated: (index, item, collection) => {
        console.log(`Tag updated at index ${index}:`, item);
      },
      onCollectionUpdated: (collection) => {
        console.log('Current collection of tags:', collection);
      }
    });
    

    Parameters

    Returns ISubscription

    A subscription that can be used to remove the subscribed observer.

waitUntil

  • Wait for a specific condition on this map to be met. When this observable detects a change, the condition provided will be called. When the condition returns true, the returned Promise will be resolved.

    // Get the tag collection to use in your application
    const tags: MpSdk.Dictionary<MpSdk.Tag.TagData> = await props.sdk.Tag.data.waitUntil( () => true );
    

    Parameters

    Returns Promise<Dictionary<ItemT>>

    A promise that is resolved when condition returns true.