Skip to content

Subscribe

With data.subscribe, you can subscribe to changes in the dataset. Every time the dataset you subscribed to changes, the callback will be called with the new data. An individual dataset is referenced by an ID. The data handling guide explains how to find available datasets.

data.subscribe()

subscribe() listens for dataset changes and calls your callback every time Shopware publishes a new value for the given dataset id.

Usage

ts
import { data } from "@shopware-ag/meteor-admin-sdk";

data.subscribe(
  "sw-product-detail__product",
  ({ id, data }) => {
    console.log(data);
  },
  {
    selectors: ["name", "manufacturer.name"],
  },
);

Parameters

NameRequiredDescription
idtrueThe unique id of the dataset you want to receive
callbacktrueA callback function which will be called every time the Shopware Administration publishes the dataset
optionsfalseAllows to specify selectors. Read more about selectors here

Return value

Returns an unsubscribe function. Call it to stop listening for dataset updates.

For example:

json
{
  "name": "Ergonomic Copper Mr. Frenzy",
  "manufacturer": {
    "name": "Turcotte, Rempel and Padberg"
  }
}
Was this page helpful?
UnsatisfiedSatisfied
Be the first to vote!
0.0 / 5  (0 votes)