@@ -3,8 +3,18 @@ import React from 'react';
33import Template from '../Template.js' ;
44import PriceRangesForm from './PriceRangesForm.js' ;
55import cx from 'classnames' ;
6+ import { isEqual } from 'lodash' ;
67
78class PriceRanges extends React . Component {
9+ componentWillMount ( ) {
10+ this . form = this . getForm ( ) ;
11+ this . refine = this . refine . bind ( this ) ;
12+ }
13+
14+ shouldComponentUpdate ( nextProps ) {
15+ return ! isEqual ( this . props . facetValues , nextProps . facetValues ) ;
16+ }
17+
818 getForm ( ) {
919 let labels = {
1020 currency : this . props . currency ,
@@ -15,24 +25,16 @@ class PriceRanges extends React.Component {
1525 < PriceRangesForm
1626 cssClasses = { this . props . cssClasses }
1727 labels = { labels }
18- refine = { this . refine . bind ( this ) }
28+ refine = { this . refine }
1929 />
2030 ) ;
2131 }
2232
23- getURLFromFacetValue ( facetValue ) {
24- if ( ! this . props . createURL ) {
25- return '#' ;
26- }
27- return this . props . createURL ( facetValue . from , facetValue . to , facetValue . isRefined ) ;
28- }
29-
3033 getItemFromFacetValue ( facetValue ) {
3134 let cssClassItem = cx (
3235 this . props . cssClasses . item ,
3336 { [ this . props . cssClasses . active ] : facetValue . isRefined }
3437 ) ;
35- let url = this . getURLFromFacetValue ( facetValue ) ;
3638 let key = facetValue . from + '_' + facetValue . to ;
3739 let handleClick = this . refine . bind ( this , facetValue . from , facetValue . to ) ;
3840 let data = {
@@ -43,7 +45,7 @@ class PriceRanges extends React.Component {
4345 < div className = { cssClassItem } key = { key } >
4446 < a
4547 className = { this . props . cssClasses . link }
46- href = { url }
48+ href = { facetValue . url }
4749 onClick = { handleClick }
4850 >
4951 < Template data = { data } templateKey = "item" { ...this . props . templateProps } />
@@ -62,22 +64,20 @@ class PriceRanges extends React.Component {
6264 }
6365
6466 render ( ) {
65- let form = this . getForm ( ) ;
6667 return (
6768 < div >
6869 < div className = { this . props . cssClasses . list } >
6970 { this . props . facetValues . map ( facetValue => {
7071 return this . getItemFromFacetValue ( facetValue ) ;
7172 } ) }
7273 </ div >
73- { form }
74+ { this . form }
7475 </ div >
7576 ) ;
7677 }
7778}
7879
7980PriceRanges . propTypes = {
80- createURL : React . PropTypes . func . isRequired ,
8181 cssClasses : React . PropTypes . shape ( {
8282 active : React . PropTypes . string ,
8383 button : React . PropTypes . string ,
0 commit comments