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

Commit 6d88154

Browse files
author
한정
authored
Merge pull request #9 from nhn/feat/reactive-columnOptions
feat: add reactive options
2 parents f71c4a7 + 2e3cf5b commit 6d88154

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
"xhr-mock": "^2.4.1"
5454
},
5555
"dependencies": {
56-
"tui-grid": "^4.3.0"
56+
"tui-grid": "^4.4.1"
5757
}
5858
}

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)