Skip to content

Latest commit

 

History

History
401 lines (319 loc) · 15.7 KB

API-INTERNAL.md

File metadata and controls

401 lines (319 loc) · 15.7 KB

Internal API Reference

Functions

getMergeQueue()

Getter - returns the merge queue.

getMergeQueuePromise()

Getter - returns the merge queue promise.

getCallbackToStateMapping()

Getter - returns the callback to state mapping.

getDefaultKeyStates()

Getter - returns the default key states.

initStoreValues(keys, initialKeyStates, safeEvictionKeys)

Sets the initial values for the Onyx store

maybeFlushBatchUpdates()

We are batching together onyx updates. This helps with use cases where we schedule onyx updates after each other. This happens for example in the Onyx.update function, where we process API responses that might contain a lot of update operations. Instead of calling the subscribers for each update operation, we batch them together which will cause react to schedule the updates at once instead of after each other. This is mainly a performance optimization.

reduceCollectionWithSelector()

Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}}) and runs it through a reducer function to return a subset of the data according to a selector. The resulting collection will only contain items that are returned by the selector.

get()

Get some data from the store

getAllKeys()

Returns current key names stored in persisted storage

isCollectionKey()

Checks to see if the a subscriber's supplied key is associated with a collection of keys.

splitCollectionMemberKey(key)

Splits a collection member key into the collection key part and the ID part.

isKeyMatch()

Checks to see if a provided key is the exact configured key of our connected subscriber or if the provided key is a collection member key (in case our configured key is a "collection key")

isSafeEvictionKey()

Checks to see if this key has been flagged as safe for removal.

tryGetCachedValue()

Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined. If the requested key is a collection, it will return an object with all the collection members.

removeLastAccessedKey()

Remove a key from the recently accessed key list.

addLastAccessedKey()

Add a key to the list of recently accessed keys. The least recently accessed key should be at the head and the most recently accessed key at the tail.

removeFromEvictionBlockList()

Removes a key previously added to this list which will enable it to be deleted again.

addToEvictionBlockList()

Keys added to this list can never be deleted.

addAllSafeEvictionKeysToRecentlyAccessedList()

Take all the keys that are safe to evict and add them to the recently accessed list when initializing the app. This enables keys that have not recently been accessed to be removed.

keysChanged()

When a collection of keys change, search for any callbacks matching the collection key and trigger those callbacks

keyChanged()

When a key change happens, search for any callbacks matching the key or collection key and trigger those callbacks

sendDataToConnection()

Sends the data obtained from the keys to the connection. It either: - sets state on the withOnyxInstances - triggers the callback function

addKeyToRecentlyAccessedIfNeeded()

We check to see if this key is flagged as safe for eviction and add it to the recentlyAccessedKeys list so that when we run out of storage the least recently accessed key can be removed.

getCollectionDataAndSendAsObject()

Gets the data for a given an array of matching keys, combines them into an object, and sends the result back to the subscriber.

scheduleSubscriberUpdate()

Schedules an update that will be appended to the macro task queue (so it doesn't update the subscribers immediately).

scheduleNotifyCollectionSubscribers()

This method is similar to notifySubscribersOnNextTick but it is built for working specifically with collections so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the subscriber callbacks receive the data in a different format than they normally expect and it breaks code.

remove()

Remove a key from Onyx and update the subscribers

evictStorageAndRetry()

If we fail to set or merge we must handle this by evicting some data from Onyx and then retrying to do whatever it is we attempted to do.

broadcastUpdate()

Notifies subscribers and writes current value to cache

removeNullValues()

Removes a key from storage if the value is null. Otherwise removes all nested null values in objects, if shouldRemoveNestedNulls is true and returns the object.

prepareKeyValuePairsForStorage()

Storage expects array like: [["@MyApp_user", value_1], ["@MyApp_key", value_2]] This method transforms an object like {'@MyApp_user': myUserValue, '@MyApp_key': myKeyValue} to an array of key-value pairs in the above format and removes key-value pairs that are being set to null

applyMerge(changes)

Merges an array of changes with an existing value

initializeWithDefaultKeyStates()

Merge user provided default key value pairs.

getMergeQueue()

Getter - returns the merge queue.

Kind: global function

getMergeQueuePromise()

Getter - returns the merge queue promise.

Kind: global function

getCallbackToStateMapping()

Getter - returns the callback to state mapping.

Kind: global function

getDefaultKeyStates()

Getter - returns the default key states.

Kind: global function

initStoreValues(keys, initialKeyStates, safeEvictionKeys)

Sets the initial values for the Onyx store

Kind: global function

Param Description
keys ONYXKEYS constants object from Onyx.init()
initialKeyStates initial data to set when init() and clear() are called
safeEvictionKeys This is an array of keys (individual or collection patterns) that when provided to Onyx are flagged as "safe" for removal.

maybeFlushBatchUpdates()

We are batching together onyx updates. This helps with use cases where we schedule onyx updates after each other. This happens for example in the Onyx.update function, where we process API responses that might contain a lot of update operations. Instead of calling the subscribers for each update operation, we batch them together which will cause react to schedule the updates at once instead of after each other. This is mainly a performance optimization.

Kind: global function

reduceCollectionWithSelector()

Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}}) and runs it through a reducer function to return a subset of the data according to a selector. The resulting collection will only contain items that are returned by the selector.

Kind: global function

get()

Get some data from the store

Kind: global function

getAllKeys()

Returns current key names stored in persisted storage

Kind: global function

isCollectionKey()

Checks to see if the a subscriber's supplied key is associated with a collection of keys.

Kind: global function

splitCollectionMemberKey(key) ⇒

Splits a collection member key into the collection key part and the ID part.

Kind: global function
Returns: A tuple where the first element is the collection part and the second element is the ID part.

Param Description
key The collection member key to split.

isKeyMatch()

Checks to see if a provided key is the exact configured key of our connected subscriber or if the provided key is a collection member key (in case our configured key is a "collection key")

Kind: global function

isSafeEvictionKey()

Checks to see if this key has been flagged as safe for removal.

Kind: global function

tryGetCachedValue()

Tries to get a value from the cache. If the value is not present in cache it will return the default value or undefined. If the requested key is a collection, it will return an object with all the collection members.

Kind: global function

removeLastAccessedKey()

Remove a key from the recently accessed key list.

Kind: global function

addLastAccessedKey()

Add a key to the list of recently accessed keys. The least recently accessed key should be at the head and the most recently accessed key at the tail.

Kind: global function

removeFromEvictionBlockList()

Removes a key previously added to this list which will enable it to be deleted again.

Kind: global function

addToEvictionBlockList()

Keys added to this list can never be deleted.

Kind: global function

addAllSafeEvictionKeysToRecentlyAccessedList()

Take all the keys that are safe to evict and add them to the recently accessed list when initializing the app. This enables keys that have not recently been accessed to be removed.

Kind: global function

keysChanged()

When a collection of keys change, search for any callbacks matching the collection key and trigger those callbacks

Kind: global function

keysChanged~isSubscribedToCollectionKey

e.g. Onyx.connect({key: ONYXKEYS.COLLECTION.REPORT, callback: ...});

Kind: inner constant of keysChanged

keysChanged~isSubscribedToCollectionMemberKey

e.g. Onyx.connect({key: ${ONYXKEYS.COLLECTION.REPORT}{reportID}, callback: ...});

Kind: inner constant of keysChanged

keyChanged()

When a key change happens, search for any callbacks matching the key or collection key and trigger those callbacks

Kind: global function
Example

keyChanged(key, value, subscriber => subscriber.initWithStoredValues === false)

sendDataToConnection()

Sends the data obtained from the keys to the connection. It either: - sets state on the withOnyxInstances - triggers the callback function

Kind: global function

addKeyToRecentlyAccessedIfNeeded()

We check to see if this key is flagged as safe for eviction and add it to the recentlyAccessedKeys list so that when we run out of storage the least recently accessed key can be removed.

Kind: global function

getCollectionDataAndSendAsObject()

Gets the data for a given an array of matching keys, combines them into an object, and sends the result back to the subscriber.

Kind: global function

scheduleSubscriberUpdate()

Schedules an update that will be appended to the macro task queue (so it doesn't update the subscribers immediately).

Kind: global function
Example

scheduleSubscriberUpdate(key, value, subscriber => subscriber.initWithStoredValues === false)

scheduleNotifyCollectionSubscribers()

This method is similar to notifySubscribersOnNextTick but it is built for working specifically with collections so that keysChanged() is triggered for the collection and not keyChanged(). If this was not done, then the subscriber callbacks receive the data in a different format than they normally expect and it breaks code.

Kind: global function

remove()

Remove a key from Onyx and update the subscribers

Kind: global function

evictStorageAndRetry()

If we fail to set or merge we must handle this by evicting some data from Onyx and then retrying to do whatever it is we attempted to do.

Kind: global function

broadcastUpdate()

Notifies subscribers and writes current value to cache

Kind: global function

removeNullValues() ⇒

Removes a key from storage if the value is null. Otherwise removes all nested null values in objects, if shouldRemoveNestedNulls is true and returns the object.

Kind: global function
Returns: The value without null values and a boolean "wasRemoved", which indicates if the key got removed completely

prepareKeyValuePairsForStorage() ⇒

Storage expects array like: [["@MyApp_user", value_1], ["@MyApp_key", value_2]] This method transforms an object like {'@MyApp_user': myUserValue, '@MyApp_key': myKeyValue} to an array of key-value pairs in the above format and removes key-value pairs that are being set to null

Kind: global function
Returns: an array of key - value pairs <[key, value]>

applyMerge(changes)

Merges an array of changes with an existing value

Kind: global function

Param Description
changes Array of changes that should be applied to the existing value

initializeWithDefaultKeyStates()

Merge user provided default key value pairs.

Kind: global function