Skip to content
This repository was archived by the owner on Oct 24, 2019. It is now read-only.

Commit 95c7d47

Browse files
committed
Merge branch 'master' into production
2 parents 459d934 + 3363c9f commit 95c7d47

File tree

4 files changed

+63
-62
lines changed

4 files changed

+63
-62
lines changed

package-lock.json

Lines changed: 35 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@toast-ui/react-grid",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "TOAST UI Grid for React",
55
"main": "dist/toastui-react-grid.js",
66
"files": [
@@ -47,12 +47,11 @@
4747
"react-dom": "^16.7.0",
4848
"storybook": "^1.0.0",
4949
"style-loader": "^0.23.1",
50+
"tui-grid": "^4.5.0",
5051
"webpack": "^4.29.0",
5152
"webpack-cli": "^3.2.1",
5253
"webpack-dev-server": "^3.1.14",
5354
"xhr-mock": "^2.4.1"
5455
},
55-
"dependencies": {
56-
"tui-grid": "^4.3.0"
57-
}
56+
"dependencies": {}
5857
}

src/index.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const reactivePropSetterMap = {
55
data: 'resetData',
66
columns: 'setColumns',
77
bodyHeight: 'setBodyHeight',
8-
frozenColumnCount: 'setFrozenColumnCount'
8+
frozenColumnCount: 'setFrozenColumnCount',
9+
columnOptions: 'setFrozenColumnCount'
910
};
1011

1112
export default class Grid extends React.Component {
@@ -35,15 +36,15 @@ export default class Grid extends React.Component {
3536
}
3637

3738
componentDidMount() {
38-
const {
39-
frozenColumnCount: frozenCount = 0,
40-
columnOptions: columnOptionsProp = {}
41-
} = this.props;
39+
const { frozenColumnCount: frozenCount, columnOptions: columnOptionsProp = {} } = this.props;
4240

43-
const columnOptions = {
44-
...columnOptionsProp,
45-
frozenCount
46-
};
41+
const columnOptions =
42+
typeof frozenCount === 'number'
43+
? {
44+
...columnOptionsProp,
45+
frozenCount
46+
}
47+
: { ...columnOptionsProp };
4748

4849
this.gridInst = new TuiGrid({
4950
el: this.rootEl.current,
@@ -53,15 +54,26 @@ export default class Grid extends React.Component {
5354
this.bindEventHandlers(this.props);
5455
}
5556

57+
componentWillUnmount() {
58+
this.gridInst.destroy();
59+
}
60+
5661
shouldComponentUpdate(nextProps) {
5762
const { oneTimeBindingProps = [] } = this.props;
5863
const reactiveProps = Object.keys(reactivePropSetterMap).filter(
5964
propName => oneTimeBindingProps.indexOf(propName) === -1
6065
);
6166

6267
reactiveProps.forEach(propName => {
63-
const currentValue = this.props[propName];
64-
const nextValue = nextProps[propName];
68+
let currentValue, nextValue;
69+
if (propName === 'columnOptions' && this.props.columnOptions) {
70+
currentValue = this.props.columnOptions.frozenCount;
71+
nextValue = nextProps.columnOptions.frozenCount;
72+
} else {
73+
currentValue = this.props[propName];
74+
nextValue = nextProps[propName];
75+
}
76+
6577
if (currentValue !== nextValue) {
6678
const setterName = reactivePropSetterMap[propName];
6779
this.gridInst[setterName](nextValue);

stories/index.stories.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ stories.add('Events', () => {
120120
stories.add('Reactive Props', () => {
121121
const dataValue = object('data', data.slice(0, 5));
122122
const columnsValue = object('columns', columns);
123+
const columnOptions = object('columnOptions', {frozenCount: 2});
123124
const bodyHeightValue = number('bodyHeight', 300, {
124125
range: true,
125126
min: 100,
@@ -137,6 +138,7 @@ stories.add('Reactive Props', () => {
137138
columns={columnsValue}
138139
data={dataValue}
139140
frozenColumnCount={frozenColumnCountValue}
141+
columnOptions={columnOptions}
140142
pagination={false}
141143
bodyHeight={bodyHeightValue}
142144
oneTimeBindingProps={oneTimeBindingProps}

0 commit comments

Comments
 (0)