Skip to content

Commit

Permalink
refactor into function
Browse files Browse the repository at this point in the history
  • Loading branch information
mishig25 committed Nov 9, 2023
1 parent 3050cbe commit d767a3d
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@
if (exampleOutput) {
output = exampleOutput.text;
outputJson = "";
// if output doesn't start with space, add space in front of output
const prefix = /^\s/.test(output) ? "" : " ";
renderTypingEffect(prefix + output);
renderExampleOutput(output);
return;
}
Expand Down Expand Up @@ -164,15 +162,19 @@
throw new TypeError("Invalid output: output must be of type Array & non-empty");
}
function renderExampleOutput(output: string) {
// if output doesn't start with space, add space in front of output
const prefix = /^\s/.test(output) ? "" : " ";
renderTypingEffect(prefix + output);
}
function applyInputSample(sample: WidgetExampleTextInput<WidgetExampleOutputText>, opts: ExampleRunOpts = {}) {
setTextAreaValue(sample.text);
if (opts.isPreview) {
if (sample.output) {
outputJson = "";
output = sample.output.text;
// if output doesn't start with space, add space in front of output
const prefix = /^\s/.test(output) ? "" : " ";
renderTypingEffect(prefix + output);
renderExampleOutput(output);
} else {
output = "";
outputJson = "";
Expand Down

0 comments on commit d767a3d

Please sign in to comment.