Skip to content

Commit c71bb7d

Browse files
Add possibility to skip option roll back (T1037806) (#625)
* Add possibility to skip option roll back (T1037806) * Fix typo Co-authored-by: volkov.vladislav <[email protected]>
1 parent 09e8a79 commit c71bb7d

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

packages/devextreme-react/src/core/__tests__/props-updating.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,24 @@ describe('option control', () => {
285285
expect(Widget.option.mock.calls[0]).toEqual(['complexOption', { a: 123, b: 234 }]);
286286
});
287287

288+
// T1037806
289+
it('no rolls back option. skipOptionsRollBack = true', () => {
290+
render(
291+
<ControlledComponent complexOption={{ a: 123, b: 234 }} />,
292+
);
293+
294+
try {
295+
Widget.skipOptionsRollBack = true;
296+
297+
fireOptionChange('complexOption', {});
298+
jest.runAllTimers();
299+
300+
expect(Widget.option.mock.calls.length).toBe(0);
301+
} finally {
302+
Widget.skipOptionsRollBack = false;
303+
}
304+
});
305+
288306
it('rolls back complex option controlled field', () => {
289307
render(
290308
<ControlledComponent complexOption={{ a: 123 }} />,

packages/devextreme-react/src/core/__tests__/test-component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Widget = {
1919
eventHandlers[event] = eventHandlers[event].filter((e) => e !== handler);
2020
},
2121
dispose: jest.fn(),
22+
skipOptionsRollBack: false,
2223
};
2324

2425
const WidgetClass = jest.fn(() => Widget);

packages/devextreme-react/src/core/options-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class OptionsManager {
147147
&& e.value instanceof Object
148148
&& shallowEquals(value as Record<string, unknown>, e.value as Record<string, unknown>);
149149

150-
if (valuesAreEqual || valuesAreEqualObjects) {
150+
if (valuesAreEqual || valuesAreEqualObjects || this.instance.skipOptionsRollBack) {
151151
return;
152152
}
153153

0 commit comments

Comments
 (0)