Skip to content

Commit

Permalink
Add: shallowEqual for setValue method
Browse files Browse the repository at this point in the history
  • Loading branch information
lexich committed Jan 29, 2016
1 parent 091eb98 commit fddad8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions examples/src/components/Tags.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import Select2 from '../../../src/components/Select2';
import '../../../css/select2.css';
import $ from "jquery";

export default class Tags extends Component {
constructor(props) {
Expand All @@ -19,6 +20,9 @@ export default class Tags extends Component {
multiple={true}
data={['bug', 'feature', 'documents', 'discussion']}
value={ value1 }
onChange={(e)=> {
this.setState({ value1: $(e.target).val() });
}}
options={{
placeholder: 'search by tags',
}} />
Expand All @@ -35,6 +39,9 @@ export default class Tags extends Component {
]}
defaultValue={ 1 }
value={ value2 }
onChange={ (e)=> {
this.setState({ value2: +$(e.target).val() });
}}
options={{
placeholder: 'search by tags',
}} />
Expand Down
4 changes: 3 additions & 1 deletion src/components/Select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
import $ from 'jquery';
import 'select2';
import shallowEqual from "react/node_modules/fbjs/lib/shallowEqual";

export default class Select2 extends Component {
static propTypes = {
Expand Down Expand Up @@ -64,7 +65,8 @@ export default class Select2 extends Component {
}

setValue(value) {
if (this.el.val() !== value) {
const elVal = this.el.val();
if (!shallowEqual(elVal, value)) {
this.el.val(value).trigger("change");
}
}
Expand Down

0 comments on commit fddad8e

Please sign in to comment.