Skip to content

Commit

Permalink
componentDidUpdate to componentWillReceiveProps
Browse files Browse the repository at this point in the history
  • Loading branch information
fongandrew committed Jan 31, 2020
1 parent 247dc0a commit 6d57fe0
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -551,28 +551,28 @@ export class Controlled extends React.Component<IControlledCodeMirror, any> {
}

/** @internal */
public componentWillReceiveProps(nextProps) {
public componentDidUpdate(prevProps) {

if (SERVER_RENDERED) return;

let preserved: IPreservedOptions = {cursor: null};

if (nextProps.value !== this.props.value) {
if (this.props.value !== prevProps.value) {
this.hydrated = false;
}

if (!this.props.autoCursor && this.props.autoCursor !== undefined) {
preserved.cursor = this.editor.getDoc().getCursor();
}

this.hydrate(nextProps);
this.hydrate(this.props);

if (!this.appliedNext) {
this.shared.applyNext(this.props, nextProps, preserved);
this.shared.applyNext(prevProps, this.props, preserved);
this.appliedNext = true;
}

this.shared.applyUserDefined(this.props, preserved);
this.shared.applyUserDefined(prevProps, preserved);
this.appliedUserDefined = true;
}

Expand Down Expand Up @@ -736,45 +736,44 @@ export class UnControlled extends React.Component<IUnControlledCodeMirror, any>
}

/** @internal */
public componentWillReceiveProps(nextProps) {

if (this.detached && (nextProps.detach === false)) {
public componentDidUpdate(prevProps) {
if (this.detached && (this.props.detach === false)) {
this.detached = false;
if (this.props.editorDidAttach) {
this.props.editorDidAttach(this.editor);
if (prevProps.editorDidAttach) {
prevProps.editorDidAttach(this.editor);
}
}

if (!this.detached && (nextProps.detach === true)) {
if (!this.detached && (this.props.detach === true)) {
this.detached = true;
if (this.props.editorDidDetach) {
this.props.editorDidDetach(this.editor);
if (prevProps.editorDidDetach) {
prevProps.editorDidDetach(this.editor);
}
}

if (SERVER_RENDERED || this.detached) return;

let preserved: IPreservedOptions = {cursor: null};

if (nextProps.value !== this.props.value) {
if (this.props.value !== prevProps.value) {
this.hydrated = false;
this.applied = false;
this.appliedUserDefined = false;
}

if (!this.props.autoCursor && this.props.autoCursor !== undefined) {
if (!prevProps.autoCursor && prevProps.autoCursor !== undefined) {
preserved.cursor = this.editor.getDoc().getCursor();
}

this.hydrate(nextProps);
this.hydrate(this.props);

if (!this.applied) {
this.shared.apply(this.props);
this.shared.apply(prevProps);
this.applied = true;
}

if (!this.appliedUserDefined) {
this.shared.applyUserDefined(this.props, preserved);
this.shared.applyUserDefined(prevProps, preserved);
this.appliedUserDefined = true;
}
}
Expand All @@ -795,7 +794,7 @@ export class UnControlled extends React.Component<IUnControlledCodeMirror, any>
let update = true;

if (SERVER_RENDERED) update = false;
if (this.detached) update = false;
if (this.detached && nextProps.detach) update = false;

return update;
}
Expand Down

0 comments on commit 6d57fe0

Please sign in to comment.