Serialization
Your app is likely to have to save and restore the content of the vwRtx instances it displays. We do that with the directly accessible vwRtx.config
value.
Getting the current value
To get a plain JS object that describes the configuration of a vwRtx instance, get the rtx.config value. This returns an optimised config object of the same type used to instantiate the instance. Store this value and use it later to set up a new instance that will look and behave just like when it was serialized.
// set up instance #1 with shape #1
const rtx1 = new vwRtx({
host: hostShape,
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod..."
})
const config = rtx1.config // get the config
// set up instance #2 with shape #2
const rtx2 = new vwRtx(config) // #2 now appears same as instance #1
Note #1 - in practical use, the config object returned from
vwRtx.config
will more complex than shown in this example. In particular, multi-styled text will include aconfig.textDef
object with style configurations for the text in the various paragraphs of the instance. Regardless, the getting and setting ofvwRtx.config
data is the optimum way to store and re-produce what is seen in a vwRtx instance.
Note #2 - the
vwRrtx.id
will be reset when a stored config is reloaded. This is done to ensure that theid
continues to be unique in its current operational context.