Skip to content

Commit 2f76ba1

Browse files
committed
Fixed an update bug when the sequence changes.
1 parent 86f6b9e commit 2f76ba1

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

demo/src/index.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from 'react'
1+
import React, { Component } from 'react'
22
import {render} from 'react-dom'
33

4-
import Component from '../../src'
4+
import MyComponent from '../../src'
55
import jquery from 'jquery';
66
window.jQuery = jquery;
77

@@ -43,13 +43,27 @@ const exampleLegend = [
4343
{name: "Synthetic peptide",color: "#fff",underscore: true}
4444
];
4545

46-
let Demo = React.createClass({
47-
render() {
48-
return <div>
49-
<h1>react-sequence-viewer Demo</h1>
50-
<Component onSubpartSelected={subPart} onMouseSelection={mouseClick} legend={exampleLegend} coverage={exampleSequenceCoverage} sequence={seq} showLineNumbers={true} toolbar={true} search={true} badge={true} title="My Protein" />
51-
</div>
46+
class Demo extends Component {
47+
constructor(props) {
48+
super(props);
49+
this.state = {
50+
seq: this.props.seq,
51+
};
52+
this.handleOnClick = this.handleOnClick.bind(this);
5253
}
53-
})
5454

55-
render(<Demo/>, document.querySelector('#demo'))
55+
handleOnClick(e) {
56+
console.debug('onclick fired');
57+
this.setState({seq:'CAGTCGTAGTAC'});
58+
}
59+
60+
render() {
61+
return <div>
62+
<h1>react-sequence-viewer Demo</h1>
63+
<button onClick={this.handleOnClick}>Click me</button>
64+
<MyComponent onSubpartSelected={subPart} onMouseSelection={mouseClick} legend={exampleLegend} coverage={exampleSequenceCoverage} sequence={this.state.seq} showLineNumbers={true} toolbar={true} search={true} badge={true} title="My Protein" />
65+
</div>
66+
}
67+
}
68+
69+
render(<Demo seq={seq}/>, document.querySelector('#demo'))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-sequence-viewer",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "A React wrapper around the BioJS sequence-viewer component",
55
"main": "lib/index.js",
66
"jsnext:main": "es/index.js",

src/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ export default class ReactSequenceViewer extends Component {
5151
this._seqObj.onMouseSelection(this.props.onMouseSelection);
5252
}
5353

54+
// Update the sequence-viewer object if we get a new DNA sequence.
55+
componentWillReceiveProps(nextProps) {
56+
if (this.props.sequence !== nextProps.sequence) {
57+
this._seqObj = new Sequence(nextProps.sequence);
58+
}
59+
}
60+
61+
// Re-render if the component has updated.
62+
componentDidUpdate() {
63+
this.callRender();
64+
}
65+
5466
// Remove the event listener when the component is unmounted.
5567
componentWillUnmount() {
5668
document.removeEventListener('change', this.handleChange);

0 commit comments

Comments
 (0)