Skip to content

Commit ed66dad

Browse files
committed
fix: invalid param for sendActionToDevTools
1 parent 8391cc7 commit ed66dad

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

lib/Onyx.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import type {Connection} from './OnyxConnectionManager';
3434
import connectionManager from './OnyxConnectionManager';
3535
import * as GlobalSettings from './GlobalSettings';
3636
import decorateWithMetrics from './metrics';
37-
import OnyxMerge from './OnyxMerge.native';
37+
import OnyxMerge from './OnyxMerge/index.native';
3838

3939
/** Initialize the store with actions and listening for storage events */
4040
function init({
@@ -325,7 +325,10 @@ function merge<TKey extends OnyxKey>(key: TKey, changes: OnyxMergeInput<TKey>):
325325
return Promise.resolve();
326326
}
327327

328-
return OnyxMerge.applyMerge(key, existingValue, validChanges);
328+
return OnyxMerge.applyMerge(key, existingValue, validChanges).then(({mergedValue, updatePromise}) => {
329+
OnyxUtils.sendActionToDevTools(OnyxUtils.METHOD.MERGE, key, changes, mergedValue);
330+
return updatePromise;
331+
});
329332
} catch (error) {
330333
Logger.logAlert(`An error occurred while applying merge for key: ${key}, Error: ${error}`);
331334
return Promise.resolve();
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import _ from 'underscore';
2-
import * as Logger from './Logger';
3-
import OnyxUtils from './OnyxUtils';
4-
import type {OnyxKey, OnyxValue} from './types';
5-
import cache from './OnyxCache';
6-
import Storage from './storage';
7-
8-
function applyMerge<TKey extends OnyxKey>(key: TKey, existingValue: OnyxValue<TKey>, validChanges: unknown[]): Promise<void> {
2+
import * as Logger from '../Logger';
3+
import OnyxUtils from '../OnyxUtils';
4+
import type {OnyxKey, OnyxValue} from '../types';
5+
import cache from '../OnyxCache';
6+
import Storage from '../storage';
7+
import type {ApplyMerge, ApplyMergeResult} from './types';
8+
9+
const applyMerge: ApplyMerge = <TKey extends OnyxKey>(key: TKey, existingValue: OnyxValue<TKey>, validChanges: unknown[]): Promise<ApplyMergeResult> => {
910
// If any of the changes is null, we need to discard the existing value.
1011
const baseValue = validChanges.includes(null) ? undefined : existingValue;
1112

@@ -27,14 +28,14 @@ function applyMerge<TKey extends OnyxKey>(key: TKey, existingValue: OnyxValue<TK
2728

2829
// If the value has not changed, calling Storage.setItem() would be redundant and a waste of performance, so return early instead.
2930
if (!hasChanged) {
30-
return updatePromise;
31+
return Promise.resolve({mergedValue, updatePromise});
3132
}
3233

33-
return Storage.mergeItem(key, batchedChanges as OnyxValue<TKey>, replaceNullPatches).then(() => {
34-
OnyxUtils.sendActionToDevTools(OnyxUtils.METHOD.MERGE, key, validChanges, mergedValue);
35-
return updatePromise;
36-
});
37-
}
34+
return Storage.mergeItem(key, batchedChanges as OnyxValue<TKey>, replaceNullPatches).then(() => ({
35+
mergedValue,
36+
updatePromise,
37+
}));
38+
};
3839

3940
const OnyxMerge = {
4041
applyMerge,
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import _ from 'underscore';
2-
import * as Logger from './Logger';
3-
import OnyxUtils from './OnyxUtils';
4-
import type {OnyxKey, OnyxValue} from './types';
5-
import cache from './OnyxCache';
6-
import Storage from './storage';
7-
8-
function applyMerge<TKey extends OnyxKey>(key: TKey, existingValue: OnyxValue<TKey>, validChanges: unknown[]): Promise<void> {
2+
import * as Logger from '../Logger';
3+
import OnyxUtils from '../OnyxUtils';
4+
import type {OnyxKey, OnyxValue} from '../types';
5+
import cache from '../OnyxCache';
6+
import Storage from '../storage';
7+
import type {ApplyMerge, ApplyMergeResult} from './types';
8+
9+
const applyMerge: ApplyMerge = <TKey extends OnyxKey>(key: TKey, existingValue: OnyxValue<TKey>, validChanges: unknown[]): Promise<ApplyMergeResult> => {
910
const {result: mergedValue} = OnyxUtils.mergeChanges(validChanges, existingValue);
1011

1112
// In cache, we don't want to remove the key if it's null to improve performance and speed up the next merge.
@@ -19,14 +20,14 @@ function applyMerge<TKey extends OnyxKey>(key: TKey, existingValue: OnyxValue<TK
1920

2021
// If the value has not changed, calling Storage.setItem() would be redundant and a waste of performance, so return early instead.
2122
if (!hasChanged) {
22-
return updatePromise;
23+
return Promise.resolve({mergedValue, updatePromise});
2324
}
2425

25-
return Storage.setItem(key, mergedValue as OnyxValue<TKey>).then(() => {
26-
OnyxUtils.sendActionToDevTools(OnyxUtils.METHOD.MERGE, key, validChanges, mergedValue);
27-
return updatePromise;
28-
});
29-
}
26+
return Storage.setItem(key, mergedValue as OnyxValue<TKey>).then(() => ({
27+
mergedValue,
28+
updatePromise,
29+
}));
30+
};
3031

3132
const OnyxMerge = {
3233
applyMerge,

lib/OnyxMerge/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type {OnyxKey, OnyxValue} from '../types';
2+
3+
type ApplyMergeResult = {
4+
mergedValue: OnyxValue<OnyxKey>;
5+
updatePromise: Promise<void>;
6+
};
7+
8+
type ApplyMerge = <TKey extends OnyxKey>(key: TKey, existingValue: OnyxValue<TKey>, validChanges: unknown[]) => Promise<ApplyMergeResult>;
9+
10+
export type {ApplyMerge, ApplyMergeResult};

0 commit comments

Comments
 (0)