Get

  • get

  • getEdit

get(entityOrUid)

Gets an immutable item from the cache. The item is deeply frozen. No dependent entities inside the object are editable.

Parameters

  • entityOrUid Object | string either the object's unique id or a stale version of the object. The cache retrieves its uid and returns the Cache copy.

Returns

  • *, the cache copy of the object or null if none is present

getEdit(entityOrUid)

Same as get() only retrieves a new deeply editable instance of the item cached. This instance can be edited and put back into the Cache. This creates a new cached version of the entity. The previous version is still available via an undo() operation. Identity comparisons of this entity with previous versions fail.

One.get(uid) !== One.getEdit(uid)

This is valid event if the referenced entity is inside an array. It updates cache wide

let item1 = {uid:1}
let item2 = {uid:2, val:item1}
let item3 = {uid:3, children:[item1]};
One.put([item1, item2]);

let editable = One.getEdit(item2);
editable.val.text = "test";
One.put(editable);

// all item1 references are updated
One.get(1).text === "test" // true

let cached3 = One.get(3)
cached3.children[0].text === "test" // true

*IMPORTANT getEdit() dynamic

Getting an editable object from the cache only clones contained items that have NO UID. This is for performance reasons. Because of that you should always getEdit() the cache item "closest to your uid".

Last updated

Was this helpful?