Edit in GitHubLog an issue

PerPluginStorage

Kind: interface Since: XD 29

Stores metadata accessible to multiple plugins, separated into silos by plugin ID. Your plugin can read & write the storage for its own plugin ID, but storage for other plugin IDs is read-only.

Each per-plugin storage silo is a collection of key-value pairs. Keys and values must both be strings.

Each scenenode has its own metadata storage, accessed via SceneNode.sharedPluginData. To store general metadata that is not specific to one scenenode, use sharedPluginData on the document's scenegraph root.

Example

Copied to your clipboard
1// This example shows how to save & retrieve rich JSON data in shared metadata storage.
2// See below for simpler examples of using individual APIs.
3const PLUGIN_ID = "<your manifest's plugin ID here>";
4
5let richObject = {
6 list: [2, 4, 6],
7 name: "Hello world",
8};
9node.sharedPluginData.setItem(
10 PLUGIN_ID,
11 "richData",
12 JSON.stringify(richObject)
13);
14
15// Later on...
16// (This could be in a different plugin, if it passes the original plugin's ID here)
17let jsonString = node.sharedPluginData.getItem(PLUGIN_ID, "richData");
18if (jsonString) {
19 // may be undefined
20 let richObjectCopy = JSON.parse(jsonString);
21 console.log(richObjectCopy.list.length); // 3
22}

getAll()

getAll(): Object< string, Object<string, string> >

Returns a map where key is plugin ID and value is a nested map containing all the shared metadata for that plugin ID (i.e. the result of calling getForPluginId() with that ID).

This map is a clone of the stored metadata, so modifying it has no effect.

Example

Copied to your clipboard
1let allSharedMetadata = node.sharedPluginData.getAll();
2console.log(
3 "Plugin A's 'foo' value:",
4 allSharedMetadata["A"] && allSharedMetadata["A"].foo
5);
6console.log(
7 "All of plugin B's shared metadata on this node:",
8 allSharedMetadata["B"]
9);
10console.log(
11 "List of plugins storing shared metadata on this node:",
12 Object.keys(allSharedMetadata)
13);

getForPluginId()

getForPluginId(pluginId): Object<string, string>

Returns a map of key-value string pairs containing all shared metadata stored on this node by the given plugin. May be an empty object (zero keys), but is never null.

This map is a clone of the stored metadata, so modifying it has no effect.

ParamType
pluginId
string

Example

Copied to your clipboard
1const MY_PLUGIN_ID = "<your manifest's plugin ID here>";
2let mySharedMetadata = node.sharedPluginData.getForPluginId(MY_PLUGIN_ID);
3console.log(
4 "My shared 'foo' & 'bar' values:",
5 mySharedMetadata.foo,
6 mySharedMetadata.bar
7);
8
9console.log(
10 "Plugin B's shared 'foo' value:",
11 node.sharedPluginData.getForPluginId("B").foo
12);

keys()

keys(pluginId): Array<string>

Returns a list of all keys stored on this node by the given plugin. May be empty (length zero), but is never null.

ParamType
pluginId
string

Example

Copied to your clipboard
1console.log(
2 "All properties stored by plugin A on this node:",
3 node.sharedPluginData.keys("A")
4);

getItem()

getItem(pluginId, key): ?string

Returns the value stored under the given key on this node by the given plugin, or undefined if the plugin hasn't stored anything under the given key.

Because metadata is stored separately per plugin, two plugins can store two different values under the same key.

ParamType
pluginId
string
key
string

Example

Copied to your clipboard
1// These are two different values, stored independently per plugin
2console.log(
3 "Plugin A's 'foo' value:",
4 node.sharedPluginData.getItem("A", "foo")
5);
6console.log(
7 "Plugin B's 'foo' value:",
8 node.sharedPluginData.getItem("B", "foo")
9);

setItem()

setItem(pluginId, key, value)

Set a metadata key which can be read by any other plugin.

ParamTypeDescription
pluginId
string
Must be equal to your plugin's ID.
key
string
value
string or undefined
If undefined, behaves as if you'd called removeItem() instead.

Example

Copied to your clipboard
1const MY_PLUGIN_ID = "<your manifest's plugin ID here>";
2node.sharedPluginData.setItem(MY_PLUGIN_ID, "foo", "42");
3
4node.sharedPluginData.setItem("other_plugin_id", "foo", "42");
5// ^ ERROR: other plugin's metadata is read-only
6
7console.log(node.sharedPluginData.getItem(MY_PLUGIN_ID, "foo")); // "42"

removeItem()

removeItem(pluginId, key)

Clears a shared metadata key stored by your plugin.

ParamTypeDescription
pluginId
string
Must be equal to your plugin's ID.
key
string
 

Example

Copied to your clipboard
1const MY_PLUGIN_ID = "<your manifest's plugin ID here>";
2node.sharedPluginData.setItem(MY_PLUGIN_ID, "foo", "42");
3console.log(node.sharedPluginData.getItem(MY_PLUGIN_ID, "foo")); // "42"
4
5node.sharedPluginData.removeItem(MY_PLUGIN_ID, "foo");
6console.log(node.sharedPluginData.getItem(MY_PLUGIN_ID, "foo")); // undefined

toString()

toString(): string

Provided for convenience: you can console.log(node.sharedPluginData) to see the value of getAll().

toJSON()

toJSON(): Object

Provided for convenience: you can include a PerPluginStorage object inside data you are going to convert to JSON, even though it is not a plain JavaScript object. Returns the same value as getAll().

Example

Copied to your clipboard
1let myData = {
2 foo: 42,
3 bar: "Some other data",
4 metadata: node.sharedPluginData,
5};
6let jsonString = JSON.stringify(myData);
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2023 Adobe. All rights reserved.