Clear Up
SharpKit Reference

IdGenerator Class


Base Types



Name Description
IdGenerator(object) Initializes a new instance. @param {Object} config (optional) Configuration object to be applied to the new instance.


Name Description
getRecId(object) @cfg {String} id The id by which to register a new instance. This instance can be found using the {@link} static method.


Name Description
isGenerator @author Don Griffin * This class is a base for all id generators. It also provides lookup of id generators by their id. Generally, id generators are used to generate a primary key for new model instances. There are different approaches to solving this problem, so this mechanism has both simple use cases and is open to custom implementations. A {@link} requests id generation using the {@link} property. * # Identity, Type and Shared IdGenerators * It is often desirable to share IdGenerators to ensure uniqueness or common configuration. This is done by giving IdGenerator instances an id property by which they can be looked up using the {@link #get} method. To configure two {@link Model} classes to share one {@link sequential} id generator, you simply assign them the same id: * Ext.define('', { extend: '', idgen: { type: 'sequential', id: 'foo' } }); * Ext.define('', { extend: '', idgen: { type: 'sequential', id: 'foo' } }); * To make this as simple as possible for generator types that are shared by many (or all) Models, the IdGenerator types (such as 'sequential' or 'uuid') are also reserved as generator id's. This is used by the {@link} which has an id equal to its type ('uuid'). In other words, the following Models share the same generator: * Ext.define('', { extend: '', idgen: 'uuid' }); * Ext.define('', { extend: '', idgen: 'uuid' }); * This can be overridden (by specifying the id explicitly), but there is no particularly good reason to do so for this generator type. * # Creating Custom Generators An id generator should derive from this class and implement the {@link #generate} method. The constructor will apply config properties on new instances, so a constructor is often not necessary. * To register an id generator type, a derived class should provide an `alias` like so: * Ext.define('', { extend: '', alias: 'idgen.custom', * configProp: 42, // some config property w/default value * generate: function () { return ... // a new id } }); * Using the custom id generator is then straightforward: * Ext.define('', { extend: '', idgen: 'custom' }); // or... * Ext.define('', { extend: '', idgen: { type: 'custom', configProp: value } }); * It is not recommended to mix shared generators with generator configuration. This leads to unpredictable results unless all configurations match (which is also redundant). In such cases, a custom generator with a default id is the best approach. * Ext.define('', { extend: '', alias: 'idgen.custom', * id: 'custom', // shared by default * prefix: 'ID_', seed: 1000 }); * Ext.define('', { extend: '', idgen: 'custom' }); * Ext.define('', { extend: '', idgen: 'custom' }); * // the above models share a generator that produces ID_1000, ID_1001, etc.. *
© Copyright 2005-2011 SharpKit. All rights reserved.