Singleton class that acts as a global registry for codecs.
1. Define a default codec with a new instance of the object to be handled.
var codec = new mxObjectCodec(new mxGraphModel());
2. Define the functions required for encoding and decoding objects.
codec.encode = function(enc, obj) { ... }
codec.decode = function(dec, node, into) { ... }
3. Register the codec in the mxCodecRegistry.
mxCodecRegistry.register(codec);
mxObjectCodec.decode may be used to either create a new instance of an object or to configure an existing instance, in which case the into argument points to the existing object. In this case, we say the codec “configures” the object.
Summary
mxCodecRegistry | Singleton class that acts as a global registry for codecs. |
Variables | |
codecs | Maps from constructor names to codecs. |
aliases | Maps from classnames to codecnames. |
Functions | |
register | Registers a new codec and associates the name of the template constructor in the codec with the codec object. |
addAlias | Adds an alias for mapping a classname to a codecname. |
getCodec | Returns a codec that handles objects that are constructed using the given constructor. |