getIdentity
Get a unique primitive representing an object.
getIdentity( object [,schema] )
This uses the object's schema, or the provided schema to return a unique string or number that represents the object.
import canReflect from "can-reflect";
canReflect.getIdentity({id: 5}, {identity: ["id"]}) //-> 5
If the schema has multiple identity keys, the identity keys and values are return stringified (and sorted):
canReflect.getIdentity(
{z: "Z", a: "A", foo: "bar"},
{identity: ["a","b"]}) //-> '{"a":"A","b":"B"}'
Parameters
- object
{Object|function}
:A map-like object.
- schema
{Object}
:A schema object with an
identity
array of the unique keys of the object like:{identity: ["id"]}
Returns
{Number|String}
:
A value that uniquely represents the object.