From 385fbb4730639b5520c6d932f00dbb3af7677583 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sun, 7 Apr 2024 13:03:23 +0200 Subject: [PATCH 1/3] add test for SQLite changes --- src/Expensify.tsx | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 6a57d6fdcc10..1ef1324ece83 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -200,6 +200,57 @@ function Expensify({ // eslint-disable-next-line react-hooks/exhaustive-deps -- we don't want this effect to run again }, []); + useEffect(() => { + let connectId: number | undefined; + + const initialData = { + a: 'a', + b: 'b', + c: { + d: 'd', + e: 'e', + }, + }; + const change1 = { + b: null, + }; + const change2 = null; + const change3 = { + f: 'f', + c: { + g: 'g', + h: 'h', + }, + }; + const change4 = { + c: { + g: null, + }, + }; + + // eslint-disable-next-line @typescript-eslint/no-misused-promises, @lwc/lwc/no-async-await + setTimeout(async () => { + const testKey = 'test_key_1'; + + connectId = Onyx.connect({ + key: testKey, + callback: (value) => console.log({value: JSON.stringify(value, null, 2)}), + }); + + await Onyx.set(testKey, initialData); + Onyx.merge(testKey, change1); + Onyx.merge(testKey, change2); + Onyx.merge(testKey, change3); + Onyx.merge(testKey, change4); + }, 10000); + + return () => { + if (connectId) { + Onyx.disconnect(connectId); + } + }; + }, []); + // Display a blank page until the onyx migration completes if (!isOnyxMigrated) { return null; From 943a72272fe3b53a77d4fa822e1aba7f97aba554 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sun, 7 Apr 2024 13:17:00 +0200 Subject: [PATCH 2/3] add logs and use Storage directly --- src/Expensify.tsx | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 1ef1324ece83..628665f86630 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -2,7 +2,7 @@ import React, {useCallback, useEffect, useLayoutEffect, useMemo, useRef, useStat import type {NativeEventSubscription} from 'react-native'; import {AppState, Linking} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import Onyx, {withOnyx} from 'react-native-onyx'; +import Onyx, {Storage as OnyxStorage, withOnyx} from 'react-native-onyx'; import ConfirmModal from './components/ConfirmModal'; import DeeplinkWrapper from './components/DeeplinkWrapper'; import EmojiPicker from './components/EmojiPicker/EmojiPicker'; @@ -232,16 +232,28 @@ function Expensify({ setTimeout(async () => { const testKey = 'test_key_1'; - connectId = Onyx.connect({ - key: testKey, - callback: (value) => console.log({value: JSON.stringify(value, null, 2)}), - }); + const printValueInSqlite = async () => { + const value = await OnyxStorage.getItem(testKey); + + console.log(value); + }; await Onyx.set(testKey, initialData); + printValueInSqlite(); + console.log('after set'); Onyx.merge(testKey, change1); + console.log('after merge 1'); Onyx.merge(testKey, change2); + console.log('after merge 2'); Onyx.merge(testKey, change3); - Onyx.merge(testKey, change4); + console.log('after merge 3'); + const promise = Onyx.merge(testKey, change4); + console.log('after merge 4'); + + await promise; + printValueInSqlite(); + + console.log('after await merge 4'); }, 10000); return () => { From 80c10dd96187bde7786709453ea2f351b485f9c1 Mon Sep 17 00:00:00 2001 From: Christoph Pader Date: Sun, 7 Apr 2024 13:33:51 +0200 Subject: [PATCH 3/3] update logs --- src/Expensify.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 628665f86630..15927d07d409 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -236,11 +236,13 @@ function Expensify({ const value = await OnyxStorage.getItem(testKey); console.log(value); + + return Promise.resolve(); }; await Onyx.set(testKey, initialData); - printValueInSqlite(); console.log('after set'); + await printValueInSqlite(); Onyx.merge(testKey, change1); console.log('after merge 1'); Onyx.merge(testKey, change2); @@ -251,9 +253,8 @@ function Expensify({ console.log('after merge 4'); await promise; - printValueInSqlite(); - console.log('after await merge 4'); + await printValueInSqlite(); }, 10000); return () => {