IdentityMap Class
IdentityMap
is a custom storage map for records by modelName
used by Store
.
Item Index
Methods
clear
()
Clears the contents of all known RecordMaps
, but does
not remove the InternalModelMap instances.
errorsArrayToHash
(
Object
public
-
errors
Convert an array of errors in JSON-API format into an object.
import DS from 'ember-data';
const { errorsArrayToHash } = DS;
let errorsArray = [
{
title: 'Invalid Attribute',
detail: 'Must be present',
source: { pointer: '/data/attributes/name' }
},
{
title: 'Invalid Attribute',
detail: 'Must be present',
source: { pointer: '/data/attributes/age' }
},
{
title: 'Invalid Attribute',
detail: 'Must be a number',
source: { pointer: '/data/attributes/age' }
}
];
let errors = errorsArrayToHash(errorsArray);
// {
// "name": ["Must be present"],
// "age": ["Must be present", "must be a number"]
// }
Parameters:
-
errors
Arrayarray of errors in JSON-API format
Returns:
Object:
errorsHashToArray
(
Array
public
-
errors
Convert an hash of errors into an array with errors in JSON-API format.
import DS from 'ember-data';
const { errorsHashToArray } = DS;
let errors = {
base: 'Invalid attributes on saving this record',
name: 'Must be present',
age: ['Must be present', 'Must be a number']
};
let errorsArray = errorsHashToArray(errors);
// [
// {
// title: "Invalid Document",
// detail: "Invalid attributes on saving this record",
// source: { pointer: "/data" }
// },
// {
// title: "Invalid Attribute",
// detail: "Must be present",
// source: { pointer: "/data/attributes/name" }
// },
// {
// title: "Invalid Attribute",
// detail: "Must be present",
// source: { pointer: "/data/attributes/age" }
// },
// {
// title: "Invalid Attribute",
// detail: "Must be a number",
// source: { pointer: "/data/attributes/age" }
// }
// ]
Parameters:
-
errors
Objecthash with errors as properties
Returns:
Array:
array of errors in JSON-API format
flushPendingSave
()
private
This method is called at the end of the run loop, and
flushes any records passed into scheduleSave
retrieve
(
InternalModelMap
-
modelName
Retrieves the InternalModelMap
for a given modelName,
creating one if one did not already exist. This is
similar to getWithDefault
or get
on a MapWithDefault
Parameters:
-
modelName
Objecta previously normalized modelName
Returns:
InternalModelMap:
the InternalModelMap for the given modelName