Getting started with JSON & Binary in the JS client
April 17, 2017 | Philip Aston
JSON and Binary topics introduce the notion of datatypes. These are fully explained here, but in essence provide consistent guarantees around data and operations that can be performed on that data, such as creating deltas.
Datatypes are used in the API to derive values for use in updating topics, and also to create value streams for a particular set of topics. The API exposes these as part of the top-level diffusion namespace.
To subscribe to a topic and receive datatype values, one creates a stream as normal, and then specialises it by providing the datatype to
Stream#asType. Listeners for
unsubscribe events can then be bound. It’s important to note that only events for topics that are of the same datatype will be emitted.