toggle between "show me" and "reset"

pull/2179/head
Richard Harris 7 years ago
parent 5fd077507b
commit 4a53da3cd6

@ -1,5 +1,5 @@
<script> <script>
import { onMount, setContext } from 'svelte'; import { onMount, setContext, createEventDispatcher } from 'svelte';
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import SplitPane from './SplitPane.svelte'; import SplitPane from './SplitPane.svelte';
import CodeMirror from './CodeMirror.svelte'; import CodeMirror from './CodeMirror.svelte';
@ -54,6 +54,8 @@
} }
} }
const dispatch = createEventDispatcher();
const components = writable([]); const components = writable([]);
const values = writable({}); const values = writable({});
const selected = writable(null); const selected = writable(null);
@ -99,6 +101,10 @@
// regenerate bundle (TODO do this in a separate worker?) // regenerate bundle (TODO do this in a separate worker?)
workers.bundler.postMessage({ type: 'bundle', components: $components }); workers.bundler.postMessage({ type: 'bundle', components: $components });
dispatch('change', {
components: $components
});
}, },
register_module_editor(editor) { register_module_editor(editor) {

@ -66,12 +66,32 @@
}); });
} }
function reset() {
repl.update({
components: chapter.app_a.map(clone),
values: {}
});
}
function complete() { function complete() {
repl.update({ repl.update({
components: chapter.app_b.map(clone), components: chapter.app_b.map(clone),
values: {} values: {}
}); });
} }
let completed = false;
function handle_change(event) {
completed = event.detail.components.every((file, i) => {
const expected = chapter.app_b[i];
return (
file.name === expected.name &&
file.type === expected.type &&
file.source === expected.source
);
});
}
</script> </script>
<style> <style>
@ -213,8 +233,8 @@
{#if chapter.app_b} {#if chapter.app_b}
<!-- TODO disable this button when the contents of the REPL <!-- TODO disable this button when the contents of the REPL
matches the expected end result --> matches the expected end result -->
<button class="show" on:click={complete}> <button class="show" on:click="{() => completed ? reset() : complete()}">
Show me {completed ? 'Reset' : 'Show me'}
</button> </button>
{/if} {/if}
@ -230,6 +250,6 @@
</div> </div>
<div class="tutorial-repl"> <div class="tutorial-repl">
<Repl bind:this={repl} orientation="rows" show_props={false}/> <Repl bind:this={repl} orientation="rows" show_props={false} on:change={handle_change}/>
</div> </div>
</div> </div>

Loading…
Cancel
Save