API Docs for: v3.16.0-alpha.2
Show:

IdentityMap Class

IdentityMap is a custom storage map for records by modelName used by Store.

Methods

clear

()

Clears the contents of all known RecordMaps, but does not remove the InternalModelMap instances.

errorsArrayToHash

(
  • errors
)
Object public

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 Array

    array of errors in JSON-API format

Returns:

Object:

errorsHashToArray

(
  • errors
)
Array public

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 Object

    hash 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

(
  • modelName
)
InternalModelMap

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 Object

    a previously normalized modelName

Returns:

InternalModelMap:

the InternalModelMap for the given modelName