File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66export { default as CollapseTransition } from './collapse' ;
77export { default as Transition } from './transition' ;
88export { default as Component } from './component' ;
9+ export { default as PureComponent } from './pureComponent' ;
910export { default as PropTypes } from './props' ;
1011export { default as View } from './view' ;
1112export { 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 22import React from 'react' ;
33import ReactDOM from 'react-dom'
44
5- import { PropTypes , Component } from '../../libs' ;
5+ import { PropTypes , PureComponent } from '../../libs' ;
66import { addResizeListener , removeResizeListener } from '../../libs/utils/resize-event' ;
77
88import { getScrollBarWidth } from './scrollbar-width' ;
99import { Bar } from './Bar'
1010
11- export class Scrollbar extends Component {
11+ export class Scrollbar extends PureComponent {
1212 constructor ( props ) {
1313 super ( props ) ;
1414
@@ -61,7 +61,7 @@ export class Scrollbar extends Component {
6161
6262 _update ( ) {
6363 let heightPercentage , widthPercentage ;
64- const wrap = this . wrap ;
64+ const { wrap, state } = this ;
6565 if ( ! wrap ) return ;
6666
6767 heightPercentage = ( wrap . clientHeight * 100 / wrap . scrollHeight ) ;
@@ -70,7 +70,9 @@ export class Scrollbar extends Component {
7070 let sizeHeight = ( heightPercentage < 100 ) ? ( heightPercentage + '%' ) : '' ;
7171 let sizeWidth = ( widthPercentage < 100 ) ? ( widthPercentage + '%' ) : '' ;
7272
73- this . setState ( { sizeHeight, sizeWidth} )
73+ if ( state . sizeHeight !== sizeHeight || state . sizeWidth !== sizeWidth ) {
74+ this . setState ( { sizeHeight, sizeWidth} )
75+ }
7476 }
7577
7678 render ( ) {
You can’t perform that action at this time.
0 commit comments