File tree Expand file tree Collapse file tree 3 files changed +31
-4
lines changed Expand file tree Collapse file tree 3 files changed +31
-4
lines changed Original file line number Diff line number Diff line change 6
6
export { default as CollapseTransition } from './collapse' ;
7
7
export { default as Transition } from './transition' ;
8
8
export { default as Component } from './component' ;
9
+ export { default as PureComponent } from './pureComponent' ;
9
10
export { default as PropTypes } from './props' ;
10
11
export { default as View } from './view' ;
11
12
export { default as Animate } from './animate' ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import PropTypes from 'prop-types' ;
3
+ import classnames from 'classnames' ;
4
+
5
+ export default class PureComponent extends React . PureComponent {
6
+ classNames ( ...args ) {
7
+ return classnames ( args ) ;
8
+ }
9
+
10
+ className ( ...args ) {
11
+ const { className } = this . props ;
12
+ return this . classNames . apply ( this , args . concat ( [ className ] ) ) ;
13
+ }
14
+
15
+ style ( args ) {
16
+ const { style } = this . props ;
17
+ return Object . assign ( { } , args , style )
18
+ }
19
+ }
20
+
21
+ PureComponent . propTypes = {
22
+ className : PropTypes . string ,
23
+ style : PropTypes . object
24
+ } ;
Original file line number Diff line number Diff line change 2
2
import React from 'react' ;
3
3
import ReactDOM from 'react-dom'
4
4
5
- import { PropTypes , Component } from '../../libs' ;
5
+ import { PropTypes , PureComponent } from '../../libs' ;
6
6
import { addResizeListener , removeResizeListener } from '../../libs/utils/resize-event' ;
7
7
8
8
import { getScrollBarWidth } from './scrollbar-width' ;
9
9
import { Bar } from './Bar'
10
10
11
- export class Scrollbar extends Component {
11
+ export class Scrollbar extends PureComponent {
12
12
constructor ( props ) {
13
13
super ( props ) ;
14
14
@@ -61,7 +61,7 @@ export class Scrollbar extends Component {
61
61
62
62
_update ( ) {
63
63
let heightPercentage , widthPercentage ;
64
- const wrap = this . wrap ;
64
+ const { wrap, state } = this ;
65
65
if ( ! wrap ) return ;
66
66
67
67
heightPercentage = ( wrap . clientHeight * 100 / wrap . scrollHeight ) ;
@@ -70,7 +70,9 @@ export class Scrollbar extends Component {
70
70
let sizeHeight = ( heightPercentage < 100 ) ? ( heightPercentage + '%' ) : '' ;
71
71
let sizeWidth = ( widthPercentage < 100 ) ? ( widthPercentage + '%' ) : '' ;
72
72
73
- this . setState ( { sizeHeight, sizeWidth} )
73
+ if ( state . sizeHeight !== sizeHeight || state . sizeWidth !== sizeWidth ) {
74
+ this . setState ( { sizeHeight, sizeWidth} )
75
+ }
74
76
}
75
77
76
78
render ( ) {
You can’t perform that action at this time.
0 commit comments