Skip to content

Commit

Permalink
revert: Walk back on some less-relevant changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Jun 18, 2024
1 parent 6b3e5b2 commit f124238
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 35 deletions.
38 changes: 22 additions & 16 deletions src/components/controllers/repl/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { debounce } from 'decko';
import { ErrorOverlay } from './error-overlay';
import { localStorageGet, localStorageSet } from '../../../lib/localstorage';
import { parseStackTrace } from './errors';
import { Splitter } from '../../splitter';
import CodeEditor from '../../code-editor';
import Runner from './runner';
import style from './style.module.css';
import REPL_CSS from './examples.css?raw';

Expand All @@ -17,6 +14,7 @@ import todoExampleSignal from './examples/todo-list-signal.txt?url';
import repoListExample from './examples/github-repo-list.txt?url';
import contextExample from './examples/context.txt?url';
import spiralExample from './examples/spiral.txt?url';
import { Splitter } from '../../splitter';

const EXAMPLES = [
{
Expand Down Expand Up @@ -113,17 +111,25 @@ export class Repl extends Component {
}

componentDidMount() {
// Load transpiler
Runner.worker.ping().then(() => {
this.setState({ loading: false });
let example = this.state.exampleSlug;
if (this.props.query.code) {
this.receiveCode(this.props.query.code);
} else if (example) {
this.applyExample(example);
} else if (!this.state.code) {
this.applyExample(EXAMPLES[0].slug);
}
Promise.all([
import('../../code-editor'),
import('./runner')
]).then(([CodeEditor, Runner]) => {
this.CodeEditor = CodeEditor.default;
this.Runner = Runner.default;

// Load transpiler
this.Runner.worker.ping().then(() => {
this.setState({ loading: false });
let example = this.state.exampleSlug;
if (this.props.query.code) {
this.receiveCode(this.props.query.code);
} else if (example) {
this.applyExample(example);
} else if (!this.state.code) {
this.applyExample(EXAMPLES[0].slug);
}
});
});
}

Expand Down Expand Up @@ -273,7 +279,7 @@ export class Repl extends Component {
stack={parseStackTrace(error)}
/>
)}
<Runner
<this.Runner
onRealm={this.onRealm}
onError={linkState(this, 'error', 'error')}
onSuccess={this.onSuccess}
Expand All @@ -283,7 +289,7 @@ export class Repl extends Component {
</div>
}
>
<CodeEditor
<this.CodeEditor
class={style.code}
value={code}
baseExampleSlug={exampleSlug}
Expand Down
12 changes: 5 additions & 7 deletions src/components/controllers/repl/runner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import { patchErrorLocation } from './errors';
let cachedFetcher = memoize(fetch);
let cachedFetch = (...args) => cachedFetcher(...args).then(r => r.clone());

const worker = typeof Worker === 'undefined'
? undefined
: Comlink.wrap(
new Worker(new URL('./repl.worker.js', import.meta.url), {
type: 'module'
})
);
const worker = Comlink.wrap(
new Worker(new URL('./repl.worker.js', import.meta.url), {
type: 'module'
})
);

function createRoot(doc) {
const root = doc.createElement('div');
Expand Down
32 changes: 20 additions & 12 deletions src/components/controllers/tutorial/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import { useLanguage } from '../../../lib/i18n';
import { Splitter } from '../../splitter';
import config from '../../../config.json';
import { MarkdownRegion } from '../markdown-region';
import CodeEditor from '../../code-editor';
import Runner from '../repl/runner';

const TUTORIAL_COMPONENTS = {
pre: TutorialCodeBlock,
Expand Down Expand Up @@ -82,10 +80,18 @@ export class Tutorial extends Component {
}

componentDidMount() {
// Load transpiler
Runner.worker.ping().then(() => {
this.setState({
loading: false
Promise.all([
import('../../code-editor'),
import('../repl/runner')
]).then(([CodeEditor, Runner]) => {
this.CodeEditor = CodeEditor.default;
this.Runner = Runner.default;

// Load transpiler
this.Runner.worker.ping().then(() => {
this.setState({
loading: false
});
});
});
}
Expand Down Expand Up @@ -135,7 +141,9 @@ export class Tutorial extends Component {
routerLoading,
tutorialLoading,
code,
error
error,
Runner: this.Runner,
CodeEditor: this.CodeEditor
};
return (
<TutorialContext.Provider value={this}>
Expand All @@ -152,6 +160,8 @@ function TutorialView({
tutorialLoading,
code,
error,
Runner,
CodeEditor,
clearError
}) {
const content = useRef(null);
Expand All @@ -167,7 +177,7 @@ function TutorialView({
const solvable = meta.solvable === true;
const hasCode = meta.code !== false;
const showCode = showCodeOverride && hasCode;
const initialLoad = !html;
const initialLoad = !html || !Runner || !CodeEditor;

// Scroll to the top after loading
useEffect(() => {
Expand Down Expand Up @@ -201,7 +211,7 @@ function TutorialView({
<>
<div class={style.output} key="output">
{!initialLoad && (
<Runner
<this.Runner
key={path}
ref={tutorial.runner}
onSuccess={tutorial.onSuccess}
Expand Down Expand Up @@ -243,7 +253,7 @@ function TutorialView({
>
<div class={style.codeWindow}>
{!initialLoad && code && (
<CodeEditor
<this.CodeEditor
key="editor"
class={style.code}
value={code}
Expand Down Expand Up @@ -345,8 +355,6 @@ function ReplWrapper({
}

/** Handles all code blocks (and <pre>'s) in tutorial markup */
// TODO: Move this into meta data, parse it out AOT. We don't need
// to do this on the client.
function TutorialCodeBlock(props) {
const tutorial = useContext(TutorialContext);
const child = [].concat(props.children)[0];
Expand Down

0 comments on commit f124238

Please sign in to comment.