From b39b7b64f252aaa0f90bf8d53ef3afdd914c1190 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 20 May 2022 17:23:35 -0600 Subject: [PATCH 01/14] create initial method --- lib/Onyx.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/Onyx.js b/lib/Onyx.js index 0c49e3270..14dc01548 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -555,6 +555,42 @@ function set(key, value) { .catch(error => evictStorageAndRetry(error, set, key, value)); } +/** + * Insert API responses and lifecycle data into Onyx + * + * @param {Object} data An object + */ + function update(data) { + // First, validate the Onyx object is in the format we expect + const isValidDataObject = _.every(data, ({onyxMethod, key, value}) => { + if (onyxMethod !== 'set' || onyxMethod !== 'merge') { + return false; + } + if (!_.isString(key)) { + return false; + } + if (!value) { + return false; + } + return true; + }); + + if (!isValidDataObject) { + // Throw error + } + + _.each(data, ({onyxMethod, key, value}) => { + if (onyxMethod === 'set') { + Onyx.set(key, value); + return; + } + if (onyxMethod === 'merge') { + Onyx.merge(key, value); + return; + } + }); +} + /** * Storage expects array like: [["@MyApp_user", value_1], ["@MyApp_key", value_2]] * This method transforms an object like {'@MyApp_user': myUserValue, '@MyApp_key': myKeyValue} From 090fd9b5648d66b0eeddd2ba9100026a43a02731 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 09:51:03 -0600 Subject: [PATCH 02/14] create Onyx update --- lib/Onyx.js | 71 ++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index 14dc01548..281fef9e3 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -555,42 +555,6 @@ function set(key, value) { .catch(error => evictStorageAndRetry(error, set, key, value)); } -/** - * Insert API responses and lifecycle data into Onyx - * - * @param {Object} data An object - */ - function update(data) { - // First, validate the Onyx object is in the format we expect - const isValidDataObject = _.every(data, ({onyxMethod, key, value}) => { - if (onyxMethod !== 'set' || onyxMethod !== 'merge') { - return false; - } - if (!_.isString(key)) { - return false; - } - if (!value) { - return false; - } - return true; - }); - - if (!isValidDataObject) { - // Throw error - } - - _.each(data, ({onyxMethod, key, value}) => { - if (onyxMethod === 'set') { - Onyx.set(key, value); - return; - } - if (onyxMethod === 'merge') { - Onyx.merge(key, value); - return; - } - }); -} - /** * Storage expects array like: [["@MyApp_user", value_1], ["@MyApp_key", value_2]] * This method transforms an object like {'@MyApp_user': myUserValue, '@MyApp_key': myKeyValue} @@ -816,6 +780,40 @@ function mergeCollection(collectionKey, collection) { }); } +/** + * Insert API responses and lifecycle data into Onyx + * + * @param {Object} data An object containing the Onyx data to set + * @param {String} data.onyxMethod One of [set, merge] Onyx methods + * @param {String} data.key ONYXKEY to set + * @param {*} data.value Value to store in ONYXKEY + */ + function update(data) { + // First, validate the Onyx object is in the format we expect + _.each(data, ({onyxMethod, key, value}) => { + if (!_.inArray(onyxMethod, ['set', 'merge'])) { + throw new Error (`Invalid method ${onyxMethod} in Onyx update.`); + } + if (!_.isString(key)) { + throw new Error (`Invalid data type for key provided in Onyx update.`); + } + if (typeof value === 'undefined') { + throw new Error (`Undefined value passed to key ${key} in Onyx update.`); + } + }); + + _.each(data, ({onyxMethod, key, value}) => { + if (onyxMethod === 'set') { + Onyx.set(key, value); + return; + } + if (onyxMethod === 'merge') { + Onyx.merge(key, value); + return; + } + }); +} + /** * Initialize the store with actions and listening for storage events * @@ -892,6 +890,7 @@ const Onyx = { multiSet, merge, mergeCollection, + update, clear, init, registerLogger, From 7e3661b80b5abbf80ef712f4213d6c97b4ca4211 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 10:13:57 -0600 Subject: [PATCH 03/14] fix lint errors --- lib/Onyx.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index 281fef9e3..7ebff2971 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -783,33 +783,32 @@ function mergeCollection(collectionKey, collection) { /** * Insert API responses and lifecycle data into Onyx * - * @param {Object} data An object containing the Onyx data to set + * @param {Object} data An object containing the Onyx data to set * @param {String} data.onyxMethod One of [set, merge] Onyx methods * @param {String} data.key ONYXKEY to set * @param {*} data.value Value to store in ONYXKEY */ - function update(data) { +function update(data) { // First, validate the Onyx object is in the format we expect _.each(data, ({onyxMethod, key, value}) => { if (!_.inArray(onyxMethod, ['set', 'merge'])) { - throw new Error (`Invalid method ${onyxMethod} in Onyx update.`); + throw new Error(`Invalid method ${onyxMethod} in Onyx update.`); } if (!_.isString(key)) { - throw new Error (`Invalid data type for key provided in Onyx update.`); + throw new Error(`Invalid ${key} key provided in Onyx update. Onyx key must be of type string.`); } if (typeof value === 'undefined') { - throw new Error (`Undefined value passed to key ${key} in Onyx update.`); + throw new Error(`Undefined value passed to key ${key} in Onyx update.`); } }); _.each(data, ({onyxMethod, key, value}) => { if (onyxMethod === 'set') { - Onyx.set(key, value); + set(key, value); return; } if (onyxMethod === 'merge') { - Onyx.merge(key, value); - return; + merge(key, value); } }); } From c73e3eff2ca418bf7aa713499611dbad0fef0923 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 10:42:09 -0600 Subject: [PATCH 04/14] add onyx tests --- lib/Onyx.js | 4 +- tests/unit/onyxTest.js | 106 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index 7ebff2971..c6b9a533d 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -791,8 +791,8 @@ function mergeCollection(collectionKey, collection) { function update(data) { // First, validate the Onyx object is in the format we expect _.each(data, ({onyxMethod, key, value}) => { - if (!_.inArray(onyxMethod, ['set', 'merge'])) { - throw new Error(`Invalid method ${onyxMethod} in Onyx update.`); + if (!_.contains(['set', 'merge'], onyxMethod)) { + throw new Error(`Invalid onyxMethod ${onyxMethod} in Onyx update.`); } if (!_.isString(key)) { throw new Error(`Invalid ${key} key provided in Onyx update. Onyx key must be of type string.`); diff --git a/tests/unit/onyxTest.js b/tests/unit/onyxTest.js index d57c066d2..0db17b7be 100644 --- a/tests/unit/onyxTest.js +++ b/tests/unit/onyxTest.js @@ -306,4 +306,110 @@ describe('Onyx', () => { }); }); }); + + it('should use update data object to set/merge keys', () => { + let testKeyValue; + connectionID = Onyx.connect({ + key: ONYX_KEYS.TEST_KEY, + initWithStoredValues: false, + callback: (value) => { + testKeyValue = value; + }, + }); + + let anotherTestKeyValue; + connectionID = Onyx.connect({ + key: ONYX_KEYS.ANOTHER_TEST, + initWithStoredValues: false, + callback: (value) => { + anotherTestKeyValue = value; + }, + }); + + return waitForPromisesToResolve() + .then(() => { + Onyx.set(ONYX_KEYS.TEST_KEY, true); + Onyx.set(ONYX_KEYS.ANOTHER_TEST, {test1: 'test1'}); + return waitForPromisesToResolve(); + }) + .then(() => { + expect(testKeyValue).toBe(true); + expect(anotherTestKeyValue).toEqual({test1: 'test1'}); + Onyx.update([ + { + onyxMethod: 'set', + key: ONYX_KEYS.TEST_KEY, + value: 'four', + }, + { + onyxMethod: 'merge', + key: ONYX_KEYS.ANOTHER_TEST, + value: {test2: 'test2'}, + }, + ]); + return waitForPromisesToResolve(); + }) + .then(() => { + expect(testKeyValue).toBe('four'); + expect(anotherTestKeyValue).toEqual({test1: 'test1', test2: 'test2'}); + }); + }); + + it('should throw error when onyxMethod is incorrect in update method', () => { + try { + Onyx.update([ + { + onyxMethod: 'set', + key: ONYX_KEYS.TEST_KEY, + value: 'four', + }, + { + onyxMethod: 'multiSet', + key: ONYX_KEYS.ANOTHER_TEST, + value: {test2: 'test2'}, + }, + ]); + } catch (error) { + // eslint-disable-next-line max-len + expect(error.message).toEqual(`Invalid onyxMethod multiSet in Onyx update.`); + } + }); + + it('should throw error when key is missing in update method', () => { + try { + Onyx.update([ + { + onyxMethod: 'set', + key: ONYX_KEYS.TEST_KEY, + value: 'four', + }, + { + onyxMethod: 'merge', + value: {test2: 'test2'}, + }, + ]); + } catch (error) { + // eslint-disable-next-line max-len + expect(error.message).toEqual(`Invalid undefined key provided in Onyx update. Onyx key must be of type string.`); + } + }); + + it('should throw error when value is undefined in update method', () => { + try { + Onyx.update([ + { + onyxMethod: 'set', + key: ONYX_KEYS.TEST_KEY, + value: 'four', + }, + { + onyxMethod: 'merge', + key: ONYX_KEYS.ANOTHER_TEST, + }, + ]); + } catch (error) { + // eslint-disable-next-line max-len + expect(error.message).toEqual(`Undefined value passed to key anotherTest in Onyx update.`); + } + }); }); From 78473166c733be16332f0f420c18792699dd9136 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 10:43:02 -0600 Subject: [PATCH 05/14] fix test lint errors --- tests/unit/onyxTest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/onyxTest.js b/tests/unit/onyxTest.js index 0db17b7be..91b265390 100644 --- a/tests/unit/onyxTest.js +++ b/tests/unit/onyxTest.js @@ -371,7 +371,7 @@ describe('Onyx', () => { ]); } catch (error) { // eslint-disable-next-line max-len - expect(error.message).toEqual(`Invalid onyxMethod multiSet in Onyx update.`); + expect(error.message).toEqual('Invalid onyxMethod multiSet in Onyx update.'); } }); @@ -390,7 +390,7 @@ describe('Onyx', () => { ]); } catch (error) { // eslint-disable-next-line max-len - expect(error.message).toEqual(`Invalid undefined key provided in Onyx update. Onyx key must be of type string.`); + expect(error.message).toEqual('Invalid undefined key provided in Onyx update. Onyx key must be of type string.'); } }); @@ -409,7 +409,7 @@ describe('Onyx', () => { ]); } catch (error) { // eslint-disable-next-line max-len - expect(error.message).toEqual(`Undefined value passed to key anotherTest in Onyx update.`); + expect(error.message).toEqual('Undefined value passed to key anotherTest in Onyx update.'); } }); }); From 668ef20f1eb9cf3adf5b21119f15e2615f1c6ae8 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 10:53:50 -0600 Subject: [PATCH 06/14] clean up failure tests --- lib/Onyx.js | 2 +- tests/unit/onyxTest.js | 52 ++++++++++-------------------------------- 2 files changed, 13 insertions(+), 41 deletions(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index c6b9a533d..b84645b18 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -795,7 +795,7 @@ function update(data) { throw new Error(`Invalid onyxMethod ${onyxMethod} in Onyx update.`); } if (!_.isString(key)) { - throw new Error(`Invalid ${key} key provided in Onyx update. Onyx key must be of type string.`); + throw new Error(`Invalid ${typeof key} key provided in Onyx update. Onyx key must be of type string.`); } if (typeof value === 'undefined') { throw new Error(`Undefined value passed to key ${key} in Onyx update.`); diff --git a/tests/unit/onyxTest.js b/tests/unit/onyxTest.js index 91b265390..8c58691cb 100644 --- a/tests/unit/onyxTest.js +++ b/tests/unit/onyxTest.js @@ -355,58 +355,30 @@ describe('Onyx', () => { }); }); - it('should throw error when onyxMethod is incorrect in update method', () => { + it('should throw an error when the data object is incorrect in Onyx.update', () => { + const data = [ + {onyxMethod: 'set', key: ONYX_KEYS.TEST_KEY, value: 'four'}, + {onyxMethod: 'multiSet', key: ONYX_KEYS.ANOTHER_TEST, value: {test2: 'test2'}} + ]; + try { - Onyx.update([ - { - onyxMethod: 'set', - key: ONYX_KEYS.TEST_KEY, - value: 'four', - }, - { - onyxMethod: 'multiSet', - key: ONYX_KEYS.ANOTHER_TEST, - value: {test2: 'test2'}, - }, - ]); + Onyx.update(data); } catch (error) { // eslint-disable-next-line max-len expect(error.message).toEqual('Invalid onyxMethod multiSet in Onyx update.'); } - }); - it('should throw error when key is missing in update method', () => { try { - Onyx.update([ - { - onyxMethod: 'set', - key: ONYX_KEYS.TEST_KEY, - value: 'four', - }, - { - onyxMethod: 'merge', - value: {test2: 'test2'}, - }, - ]); + data[1] = {onyxMethod: 'merge', key: true, value: {test2: 'test2'}}; + Onyx.update(data); } catch (error) { // eslint-disable-next-line max-len - expect(error.message).toEqual('Invalid undefined key provided in Onyx update. Onyx key must be of type string.'); + expect(error.message).toEqual('Invalid boolean key provided in Onyx update. Onyx key must be of type string.'); } - }); - it('should throw error when value is undefined in update method', () => { try { - Onyx.update([ - { - onyxMethod: 'set', - key: ONYX_KEYS.TEST_KEY, - value: 'four', - }, - { - onyxMethod: 'merge', - key: ONYX_KEYS.ANOTHER_TEST, - }, - ]); + data[1] = {onyxMethod: 'merge', key: ONYX_KEYS.ANOTHER_TEST}; + Onyx.update(data); } catch (error) { // eslint-disable-next-line max-len expect(error.message).toEqual('Undefined value passed to key anotherTest in Onyx update.'); From a52c9442749cac2fa560453d50f7939ece0d9834 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 10:54:17 -0600 Subject: [PATCH 07/14] remove unecessary comments --- tests/unit/onyxTest.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/unit/onyxTest.js b/tests/unit/onyxTest.js index 8c58691cb..acf8cd819 100644 --- a/tests/unit/onyxTest.js +++ b/tests/unit/onyxTest.js @@ -364,7 +364,6 @@ describe('Onyx', () => { try { Onyx.update(data); } catch (error) { - // eslint-disable-next-line max-len expect(error.message).toEqual('Invalid onyxMethod multiSet in Onyx update.'); } @@ -372,7 +371,6 @@ describe('Onyx', () => { data[1] = {onyxMethod: 'merge', key: true, value: {test2: 'test2'}}; Onyx.update(data); } catch (error) { - // eslint-disable-next-line max-len expect(error.message).toEqual('Invalid boolean key provided in Onyx update. Onyx key must be of type string.'); } @@ -380,7 +378,6 @@ describe('Onyx', () => { data[1] = {onyxMethod: 'merge', key: ONYX_KEYS.ANOTHER_TEST}; Onyx.update(data); } catch (error) { - // eslint-disable-next-line max-len expect(error.message).toEqual('Undefined value passed to key anotherTest in Onyx update.'); } }); From 8772195796b9a0c9c6fec5a3feeeb214f2b6a5ca Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 11:32:07 -0600 Subject: [PATCH 08/14] disable lint warning --- tests/unit/onyxTest.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/onyxTest.js b/tests/unit/onyxTest.js index acf8cd819..37e9369ee 100644 --- a/tests/unit/onyxTest.js +++ b/tests/unit/onyxTest.js @@ -371,6 +371,7 @@ describe('Onyx', () => { data[1] = {onyxMethod: 'merge', key: true, value: {test2: 'test2'}}; Onyx.update(data); } catch (error) { + // eslint-disable-next-line max-len expect(error.message).toEqual('Invalid boolean key provided in Onyx update. Onyx key must be of type string.'); } From 1c97a1d90ba53e33e12eb98d289738aaad2b3594 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 13:33:37 -0600 Subject: [PATCH 09/14] address comments --- lib/Onyx.js | 20 ++++++++++---------- tests/unit/onyxTest.js | 22 +++++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index b84645b18..5d0a00736 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -790,25 +790,25 @@ function mergeCollection(collectionKey, collection) { */ function update(data) { // First, validate the Onyx object is in the format we expect - _.each(data, ({onyxMethod, key, value}) => { + _.each(data, ({onyxMethod, key}) => { if (!_.contains(['set', 'merge'], onyxMethod)) { throw new Error(`Invalid onyxMethod ${onyxMethod} in Onyx update.`); } if (!_.isString(key)) { throw new Error(`Invalid ${typeof key} key provided in Onyx update. Onyx key must be of type string.`); } - if (typeof value === 'undefined') { - throw new Error(`Undefined value passed to key ${key} in Onyx update.`); - } }); _.each(data, ({onyxMethod, key, value}) => { - if (onyxMethod === 'set') { - set(key, value); - return; - } - if (onyxMethod === 'merge') { - merge(key, value); + switch (onyxMethod) { + case 'set': + set(key, value); + break; + case 'merge': + merge(key, value); + break; + default: + throw new Error(`Invalid onyxMethod ${onyxMethod} in Onyx update.`); } }); } diff --git a/tests/unit/onyxTest.js b/tests/unit/onyxTest.js index 37e9369ee..ac7cd4c51 100644 --- a/tests/unit/onyxTest.js +++ b/tests/unit/onyxTest.js @@ -328,6 +328,7 @@ describe('Onyx', () => { return waitForPromisesToResolve() .then(() => { + // GIVEN the initial Onyx state: {test: true, anotherTest: {test1: 'test1'}} Onyx.set(ONYX_KEYS.TEST_KEY, true); Onyx.set(ONYX_KEYS.ANOTHER_TEST, {test1: 'test1'}); return waitForPromisesToResolve(); @@ -335,11 +336,13 @@ describe('Onyx', () => { .then(() => { expect(testKeyValue).toBe(true); expect(anotherTestKeyValue).toEqual({test1: 'test1'}); + + // WHEN we pass a data object to Onyx.update Onyx.update([ { onyxMethod: 'set', key: ONYX_KEYS.TEST_KEY, - value: 'four', + value: 'one', }, { onyxMethod: 'merge', @@ -350,36 +353,37 @@ describe('Onyx', () => { return waitForPromisesToResolve(); }) .then(() => { - expect(testKeyValue).toBe('four'); + // THEN the final Onyx state should be {test: 'one', anotherTest: {test1: 'test1', test2: 'test2'}} + expect(testKeyValue).toBe('one'); expect(anotherTestKeyValue).toEqual({test1: 'test1', test2: 'test2'}); }); }); it('should throw an error when the data object is incorrect in Onyx.update', () => { + // GIVEN the invalid data object with onyxMethod='multiSet' const data = [ {onyxMethod: 'set', key: ONYX_KEYS.TEST_KEY, value: 'four'}, {onyxMethod: 'multiSet', key: ONYX_KEYS.ANOTHER_TEST, value: {test2: 'test2'}} ]; try { + // WHEN we pass it to Onyx.update Onyx.update(data); } catch (error) { + // THEN we should expect the error message below expect(error.message).toEqual('Invalid onyxMethod multiSet in Onyx update.'); } try { + // GIVEN the invalid data object with key=true data[1] = {onyxMethod: 'merge', key: true, value: {test2: 'test2'}}; + + // WHEN we pass it to Onyx.update Onyx.update(data); } catch (error) { + // THEN we should expect the error message below // eslint-disable-next-line max-len expect(error.message).toEqual('Invalid boolean key provided in Onyx update. Onyx key must be of type string.'); } - - try { - data[1] = {onyxMethod: 'merge', key: ONYX_KEYS.ANOTHER_TEST}; - Onyx.update(data); - } catch (error) { - expect(error.message).toEqual('Undefined value passed to key anotherTest in Onyx update.'); - } }); }); From 215f429285796e93d1b1b132d9dc89f30afe942e Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 13:37:18 -0600 Subject: [PATCH 10/14] address comments --- tests/unit/onyxTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/onyxTest.js b/tests/unit/onyxTest.js index ac7cd4c51..c2607b2ed 100644 --- a/tests/unit/onyxTest.js +++ b/tests/unit/onyxTest.js @@ -342,7 +342,7 @@ describe('Onyx', () => { { onyxMethod: 'set', key: ONYX_KEYS.TEST_KEY, - value: 'one', + value: undefined, }, { onyxMethod: 'merge', From df2293460264cd6a13e747fd00872048c0d0580f Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 13:45:40 -0600 Subject: [PATCH 11/14] revert test change --- tests/unit/onyxTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/onyxTest.js b/tests/unit/onyxTest.js index c2607b2ed..ac7cd4c51 100644 --- a/tests/unit/onyxTest.js +++ b/tests/unit/onyxTest.js @@ -342,7 +342,7 @@ describe('Onyx', () => { { onyxMethod: 'set', key: ONYX_KEYS.TEST_KEY, - value: undefined, + value: 'one', }, { onyxMethod: 'merge', From 0e3f941755c4222c70ae64d5fa58b14b73c1d97a Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 13:52:35 -0600 Subject: [PATCH 12/14] change type of data --- lib/Onyx.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index 5d0a00736..aee09cf4c 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -783,10 +783,7 @@ function mergeCollection(collectionKey, collection) { /** * Insert API responses and lifecycle data into Onyx * - * @param {Object} data An object containing the Onyx data to set - * @param {String} data.onyxMethod One of [set, merge] Onyx methods - * @param {String} data.key ONYXKEY to set - * @param {*} data.value Value to store in ONYXKEY + * @param {Array} data An array of objects with shape {onyxMethod: oneOf('set', 'merge'), key: string, value: *} */ function update(data) { // First, validate the Onyx object is in the format we expect From e3de27476244b1e64e10ecfb5c732255324acb6f Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 14:41:32 -0600 Subject: [PATCH 13/14] rm default error in switch --- lib/Onyx.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index aee09cf4c..77ad7b1aa 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -805,7 +805,7 @@ function update(data) { merge(key, value); break; default: - throw new Error(`Invalid onyxMethod ${onyxMethod} in Onyx update.`); + break; } }); } From 971a825cbd4fe91964413f62d470e37b264ff1f4 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 23 May 2022 14:43:44 -0600 Subject: [PATCH 14/14] add update to decorators --- lib/Onyx.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Onyx.js b/lib/Onyx.js index 77ad7b1aa..c7dd4e3f0 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -914,6 +914,7 @@ function applyDecorators() { mergeCollection = decorate.decorateWithMetrics(mergeCollection, 'Onyx:mergeCollection'); getAllKeys = decorate.decorateWithMetrics(getAllKeys, 'Onyx:getAllKeys'); initializeWithDefaultKeyStates = decorate.decorateWithMetrics(initializeWithDefaultKeyStates, 'Onyx:defaults'); + update = decorate.decorateWithMetrics(update, 'Onyx:update'); /* eslint-enable */ // Re-expose decorated methods @@ -922,6 +923,7 @@ function applyDecorators() { Onyx.clear = clear; Onyx.merge = merge; Onyx.mergeCollection = mergeCollection; + Onyx.update = update; // Expose stats methods on Onyx Onyx.getMetrics = decorate.getMetrics;