mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Performance: suppresses redundant SideBar re-rendering on state.tags (#6451)
This commit is contained in:
parent
fb9e78d6c1
commit
c320d2364e
@ -610,4 +610,26 @@ describe('reducer', function() {
|
||||
expect(state.selectedNoteIds).toBe(expected);
|
||||
}
|
||||
});
|
||||
|
||||
// tests for TAG_UPDATE_ALL about PR #6451
|
||||
it('should not change tags when a new value is deep equal to the old value', async () => {
|
||||
const tags = await createNTestTags(6);
|
||||
const oldTags = tags.slice(0, 5);
|
||||
{
|
||||
// Case 1. The input which is deep equal to the current state.tags doesn't change state.tags.
|
||||
const oldState = initTestState(null, null, null, null, oldTags, [2]);
|
||||
const newTags = oldTags.slice();
|
||||
// test action
|
||||
const newState = reducer(oldState, { type: 'TAG_UPDATE_ALL', items: newTags });
|
||||
expect(newState.tags).toBe(oldState.tags);
|
||||
}
|
||||
{
|
||||
// Case 2. A different input changes state.tags.
|
||||
const oldState = initTestState(null, null, null, null, oldTags, [2]);
|
||||
const newTags = oldTags.slice().splice(3, 1, tags[5]);
|
||||
// test action
|
||||
const newState = reducer(oldState, { type: 'TAG_UPDATE_ALL', items: newTags });
|
||||
expect(newState.tags).not.toBe(oldState.tags);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import produce, { Draft } from 'immer';
|
||||
import produce, { Draft, original } from 'immer';
|
||||
import pluginServiceReducer, { stateRootKey as pluginServiceStateRootKey, defaultState as pluginServiceDefaultState, State as PluginServiceState } from './services/plugins/reducer';
|
||||
import shareServiceReducer, { stateRootKey as shareServiceStateRootKey, defaultState as shareServiceDefaultState, State as ShareServiceState } from './services/share/reducer';
|
||||
import Note from './models/Note';
|
||||
@ -7,6 +7,7 @@ import BaseModel from './BaseModel';
|
||||
import { Store } from 'redux';
|
||||
import { ProfileConfig } from './services/profileConfig/types';
|
||||
import * as ArrayUtils from './ArrayUtils';
|
||||
const fastDeepEqual = require('fast-deep-equal');
|
||||
const { ALL_NOTES_FILTER_ID } = require('./reserved-ids');
|
||||
const { createSelectorCreator, defaultMemoize } = require('reselect');
|
||||
const { createCachedSelector } = require('re-reselect');
|
||||
@ -924,7 +925,9 @@ const reducer = produce((draft: Draft<State> = defaultState, action: any) => {
|
||||
break;
|
||||
|
||||
case 'TAG_UPDATE_ALL':
|
||||
draft.tags = action.items;
|
||||
if (!fastDeepEqual(original(draft.tags), action.items)) {
|
||||
draft.tags = action.items;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'TAG_SELECT':
|
||||
|
Loading…
Reference in New Issue
Block a user