Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,8 @@ function mergeCollection(collectionKey, collection) {
* @param {Boolean} [options.captureMetrics] Enables Onyx benchmarking and exposes the get/print/reset functions
* @param {Boolean} [options.shouldSyncMultipleInstances] Auto synchronize storage events between multiple instances
* of Onyx running in different tabs/windows. Defaults to true for platforms that support local storage (web/desktop)
*
* @param {String[]} [option.keysToDisableSyncEvents=[]] Contains keys for which
* we want to disable sync event across tabs.
* @example
* Onyx.init({
* keys: ONYXKEYS,
Expand All @@ -812,6 +813,7 @@ function init({
maxCachedKeysCount = 1000,
captureMetrics = false,
shouldSyncMultipleInstances = Boolean(global.localStorage),
keysToDisableSyncEvents = [],
} = {}) {
if (captureMetrics) {
// The code here is only bundled and applied when the captureMetrics is set
Expand Down Expand Up @@ -840,7 +842,7 @@ function init({
.then(deferredInitTask.resolve);

if (shouldSyncMultipleInstances && _.isFunction(Storage.keepInstancesSync)) {
Storage.keepInstancesSync((key, value) => {
Storage.keepInstancesSync(keysToDisableSyncEvents, (key, value) => {
cache.set(key, value);
keyChanged(key, value);
});
Expand Down
8 changes: 7 additions & 1 deletion lib/storage/WebStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ const webStorage = {
...Storage,

/**
* Contains keys for which we want to disable sync event across tabs.
* @param {String[]} keysToDisableSyncEvents
* Storage synchronization mechanism keeping all opened tabs in sync
* @param {function(key: String, data: *)} onStorageKeyChanged
*/
keepInstancesSync(onStorageKeyChanged) {
keepInstancesSync(keysToDisableSyncEvents, onStorageKeyChanged) {
// Override set, remove and clear to raise storage events that we intercept in other tabs
this.setItem = (key, value) => Storage.setItem(key, value)
.then(() => raiseStorageSyncEvent(key));
Expand All @@ -41,6 +43,10 @@ const webStorage = {
}

const onyxKey = event.newValue;
if (_.contains(keysToDisableSyncEvents, onyxKey)) {
return;
}

Storage.getItem(onyxKey)
.then(value => onStorageKeyChanged(onyxKey, value));
});
Expand Down