Function
setIdentifierGenerationMethod (method) public
Defined in ../../ember-data-types/q/identifier.ts:116
- method
Configures how unique identifier lid strings are generated by @ember-data/store.
This configuration MUST occur prior to the store instance being created.
Takes a method which can expect to receive various data as its first argument
and the name of a bucket as its second argument. Currently the second
argument will always be record
data should conform to a json-api
Resource
interface, but will be the normalized json data for a single
resource that has been given to the store.
The method must return a unique (to at-least the given bucket) string identifier
for the given data as a string to be used as the lid
of an Identifier
token.
This method will only be called by either getOrCreateRecordIdentifier
or
createIdentifierForNewRecord
when an identifier for the supplied data
is not already known via lid
or type + id
combo and one needs to be
generated or retrieved from a proprietary cache.
data
will be the same data argument provided to getOrCreateRecordIdentifier
and in the createIdentifierForNewRecord
case will be an object with
only type
as a key.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import { setIdentifierGenerationMethod } from '@ember-data/store'; export function initialize(applicationInstance) { // note how `count` here is now scoped to the application instance // for our generation method by being inside the closure provided // by the initialize function let count = 0; setIdentifierGenerationMethod((resource, bucket) => { return resource.lid || `my-key-${count++}`; }); } export default { name: 'configure-ember-data-identifiers', initialize }; |