Skip to content

Commit

Permalink
fix(trigger): fixed output function performance (#106)
Browse files Browse the repository at this point in the history
close #104
  • Loading branch information
jukben authored Nov 25, 2018
1 parent 7aed1ec commit c209192
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Textarea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ReactTextareaAutocomplete extends React.Component<
selectionEnd: 0,
selectionStart: 0,
component: null,
textToReplace: null,
};

componentDidMount() {
Expand Down Expand Up @@ -217,9 +218,14 @@ class ReactTextareaAutocomplete extends React.Component<
);
};

_getTextToReplace = (): ?outputType => {
const { currentTrigger, actualToken } = this.state;
const triggerSettings = this._getCurrentTriggerSettings();
_getTextToReplace = ({
actualToken,
currentTrigger,
}: {|
actualToken: string,
currentTrigger: string,
|}): ?outputType => {
const triggerSettings = this.props.trigger[currentTrigger];

if (!currentTrigger || !triggerSettings) return null;

Expand Down Expand Up @@ -543,6 +549,10 @@ class ReactTextareaAutocomplete extends React.Component<
selectionEnd,
selectionStart,
currentTrigger,
textToReplace: this._getTextToReplace({
actualToken,
currentTrigger,
}),
actualToken,
},
() => {
Expand Down Expand Up @@ -648,10 +658,10 @@ class ReactTextareaAutocomplete extends React.Component<
currentTrigger,
component,
value,
textToReplace,
} = this.state;

const suggestionData = this._getSuggestions();
const textToReplace = this._getTextToReplace();

return (
<div
Expand Down
1 change: 1 addition & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ export type TextareaState = {
selectionEnd: number,
selectionStart: number,
component: ?React$StatelessFunctionalComponent<*>,
textToReplace: ?outputType,
};

0 comments on commit c209192

Please sign in to comment.