File tree Expand file tree Collapse file tree
src/components/controllers/repl Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { useState , useEffect } from 'preact/hooks' ;
1+ import { useState } from 'preact/hooks' ;
22import { Splitter } from '../../splitter' ;
33import { EXAMPLES , getExample , loadExample } from './examples' ;
44import { ErrorOverlay } from './error-overlay' ;
@@ -42,18 +42,22 @@ export function Repl({ code, slug }) {
4242 } ) ;
4343 } ;
4444
45- useEffect ( ( ) => {
45+ const onEditorInput = ( value ) => {
46+ setEditorCode ( value ) ;
47+
48+ // Clears the example & code query params when a user
49+ // begins to modify the code
50+ if ( ! exampleSlug || ! location . search ) return ;
4651 const example = getExample ( exampleSlug ) ;
47- ( async function ( ) {
48- if ( example ) {
49- const code = await loadExample ( example . url ) ;
50- if ( location . search && code !== editorCode ) {
52+ if ( example ) {
53+ loadExample ( example . url ) . then ( exampleCode => {
54+ if ( exampleCode !== value ) {
5155 setExampleSlug ( '' ) ;
5256 history . replaceState ( null , null , '/repl' ) ;
5357 }
54- }
55- } ) ( ) ;
56- } , [ editorCode ] ) ;
58+ } ) ;
59+ }
60+ } ;
5761
5862 const share = ( ) => {
5963 if ( ! exampleSlug ) {
@@ -138,7 +142,7 @@ export function Repl({ code, slug }) {
138142 value = { editorCode }
139143 baseExampleSlug = { exampleSlug }
140144 error = { error }
141- onInput = { setEditorCode }
145+ onInput = { onEditorInput }
142146 />
143147 </ Splitter >
144148 </ div >
You can’t perform that action at this time.
0 commit comments