Skip to content

Commit a39c0dd

Browse files
committed
Fix multi instance debounce issue
The debounce function is shared between the instances so that can create issues where Codemirror instances doesn't update because the check function was debounced until it was run for another instance.
1 parent a08fb55 commit a39c0dd

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

dist/react-codemirror.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9449,6 +9449,9 @@ var CodeMirror = React.createClass({
94499449
isFocused: false
94509450
};
94519451
},
9452+
componentWillMount: function componentWillMount() {
9453+
this.componentWillReceiveProps = debounce(this.componentWillReceiveProps, 0);
9454+
},
94529455
componentDidMount: function componentDidMount() {
94539456
var textareaNode = findDOMNode(this.refs.textarea);
94549457
var codeMirrorInstance = this.getCodeMirrorInstance();
@@ -9465,7 +9468,7 @@ var CodeMirror = React.createClass({
94659468
this.codeMirror.toTextArea();
94669469
}
94679470
},
9468-
componentWillReceiveProps: debounce(function (nextProps) {
9471+
componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
94699472
if (this.codeMirror && nextProps.value !== undefined && this.codeMirror.getValue() !== nextProps.value) {
94709473
this.codeMirror.setValue(nextProps.value);
94719474
}
@@ -9476,7 +9479,7 @@ var CodeMirror = React.createClass({
94769479
}
94779480
}
94789481
}
9479-
}, 0),
9482+
},
94809483
getCodeMirror: function getCodeMirror() {
94819484
return this.codeMirror;
94829485
},

dist/react-codemirror.min.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Codemirror.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ var CodeMirror = React.createClass({
2828
isFocused: false
2929
};
3030
},
31+
componentWillMount: function componentWillMount() {
32+
this.componentWillReceiveProps = debounce(this.componentWillReceiveProps, 0);
33+
},
3134
componentDidMount: function componentDidMount() {
3235
var textareaNode = findDOMNode(this.refs.textarea);
3336
var codeMirrorInstance = this.getCodeMirrorInstance();
@@ -44,7 +47,7 @@ var CodeMirror = React.createClass({
4447
this.codeMirror.toTextArea();
4548
}
4649
},
47-
componentWillReceiveProps: debounce(function (nextProps) {
50+
componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
4851
if (this.codeMirror && nextProps.value !== undefined && this.codeMirror.getValue() !== nextProps.value) {
4952
this.codeMirror.setValue(nextProps.value);
5053
}
@@ -55,7 +58,7 @@ var CodeMirror = React.createClass({
5558
}
5659
}
5760
}
58-
}, 0),
61+
},
5962
getCodeMirror: function getCodeMirror() {
6063
return this.codeMirror;
6164
},

src/Codemirror.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const CodeMirror = React.createClass({
2424
isFocused: false,
2525
};
2626
},
27+
componentWillMount () {
28+
this.componentWillReceiveProps = debounce(this.componentWillReceiveProps, 0);
29+
},
2730
componentDidMount () {
2831
const textareaNode = findDOMNode(this.refs.textarea);
2932
const codeMirrorInstance = this.getCodeMirrorInstance();
@@ -40,7 +43,7 @@ const CodeMirror = React.createClass({
4043
this.codeMirror.toTextArea();
4144
}
4245
},
43-
componentWillReceiveProps: debounce(function (nextProps) {
46+
componentWillReceiveProps: function (nextProps) {
4447
if (this.codeMirror && nextProps.value !== undefined && this.codeMirror.getValue() !== nextProps.value) {
4548
this.codeMirror.setValue(nextProps.value);
4649
}
@@ -51,7 +54,7 @@ const CodeMirror = React.createClass({
5154
}
5255
}
5356
}
54-
}, 0),
57+
},
5558
getCodeMirror () {
5659
return this.codeMirror;
5760
},

0 commit comments

Comments
 (0)