Skip to content

[WIP] Fix cache #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ class Select extends Component {
this.renderedTreeData = this.renderTreeData(nextProps);
// Detecting whether the object of `onChange`'s argument is old ref.
// Better to do a deep equal later.
this._cacheTreeNodesStates = this._cacheTreeNodesStates !== 'no' &&
this._savedValue &&
nextProps.value === this._savedValue;
if (this.props.treeData !== nextProps.treeData ||
this.props.children !== nextProps.children) {
// refresh this._treeNodesStates cache
Expand Down Expand Up @@ -375,7 +372,8 @@ class Select extends Component {
return;
}
event.stopPropagation();
this._cacheTreeNodesStates = 'no';
this._cacheTreeNodesStates = false;
this._checkedNodes = [];
if (state.inputValue || state.value.length) {
this.fireChange([]);
this.setOpenState(false);
Expand Down Expand Up @@ -640,7 +638,7 @@ class Select extends Component {
if (props.disabled) {
return;
}
this._cacheTreeNodesStates = 'no';
this._cacheTreeNodesStates = false;
if (props.treeCheckable &&
(props.showCheckedStrategy === SHOW_ALL || props.showCheckedStrategy === SHOW_PARENT)
&& !(props.treeCheckStrictly || this.state.inputValue)) {
Expand Down
17 changes: 12 additions & 5 deletions tests/Select.multiple.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-undef */
/* eslint-disable no-undef, no-console */
import React from 'react';
import { mount, render } from 'enzyme';
import KeyCode from 'rc-util/lib/KeyCode';
Expand Down Expand Up @@ -56,6 +56,7 @@ describe('TreeSelect.multiple', () => {
}

handleChange = (value) => {
console.log('onChange', value);
this.setState({ value });
}

Expand All @@ -68,13 +69,19 @@ describe('TreeSelect.multiple', () => {
}
}
const wrapper = mount(<App />);
let choice = wrapper.find('ul .rc-tree-select-selection__choice__content');
expect(choice).toHaveLength(2);
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.BACKSPACE });
choice = wrapper.find('ul .rc-tree-select-selection__choice__content');
expect(choice).toHaveLength(1);
const treeWrapper = mount(wrapper.find('Trigger').node.getComponent());
treeWrapper.find('.rc-tree-select-tree-checkbox').at(1).simulate('click');
wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.BACKSPACE });
const choice = wrapper.find('ul .rc-tree-select-selection__choice__content');
expect(choice).toHaveLength(1);
expect(choice.prop('children')).toBe('label0');
choice = wrapper.find('ul .rc-tree-select-selection__choice__content');
expect(choice).toHaveLength(2);
// wrapper.find('input').simulate('keyDown', { keyCode: KeyCode.BACKSPACE });
// choice = wrapper.find('ul .rc-tree-select-selection__choice__content');
// expect(choice).toHaveLength(1);
// expect(choice.prop('children')).toBe('label0');
});

it('renders clear button', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/__mocks__/rc-trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Trigger = require.requireActual('rc-trigger');

const render = Trigger.prototype.render;

Trigger.prototype.render = function () {
Trigger.prototype.render = function _render() {
const { popupVisible } = this.state;
return (
<div id="TriggerContainer">
Expand Down