Skip to content

only autorun if no oncreate #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/manifests/bundle.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

{
"bundle.js": "client/dist/bundle.4f94c5b2e0057d3579ce48414878d32914eb084b.js"
"bundle.js": "client/dist/bundle.9b928683a0dcb3e1116edb9e26b2fa645cac78f2.js"
}

2 changes: 1 addition & 1 deletion server/manifests/css.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"main.css":"client/dist/main.db39ee6dfded6099e124b9a3bafbd0b8.css"}
{"main.css":"client/dist/main.668fe1eea5359e2f207cdcb4dc619a1b.css"}
51 changes: 47 additions & 4 deletions universal/routes/Repl/Viewer.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class='iframe-container'>
<iframe ref:child class='{{error || pendingImports ? "greyed-out" : ""}}' srcdoc='
<iframe ref:child class='{{error || pending || pendingImports ? "greyed-out" : ""}}' srcdoc='
<!doctype html>
<html>
<head>
Expand Down Expand Up @@ -28,6 +28,10 @@

{{error.message}}
</p>
{{elseif pending}}
<div class='pending' on:click='run()'>
<span>Click to run</span>
</div>
{{elseif pendingImports}}
<p class='info message'>loading {{pendingImports}} {{pendingImports === 1 ? 'dependency' : 'dependencies'}} from packd.now.sh (this may take a while if the package isn't cached)</p>
{{/if}}
Expand Down Expand Up @@ -66,13 +70,34 @@
position: absolute;
top: 0;
width: 100%;
height: 100%;
padding: 1em;
pointer-events: none;
}

.overlay p {
pointer-events: all;
}

.pending {
position: absolute;
width: 100%;
height: 100%;
text-align: center;
top: 0;
left: 0;
pointer-events: all;
}

.pending span {
position: absolute;
top: calc(50% - 0.5em);
line-height: 1;
left: 0;
text-align: center;
width: 100%;
font-size: 2em;
}
</style>

<script>
Expand Down Expand Up @@ -154,7 +179,18 @@

const missingImports = bundle.imports.filter( x => !importCache[ x ] );

const createComponent = () => {
const ready = () => {
// TODO this is very hacky — would be great if this information
// was exposed by the compiler somehow
if (/[^_]oncreate/.test(bundle.code)) {
this.set({ pending: true });
} else {
this.set({ pending: false });
this.createComponent();
}
};

this.createComponent = () => {
this.set({ error: null });

if ( toDestroy ) {
Expand Down Expand Up @@ -226,14 +262,14 @@
promise
.then( () => {
if ( cancelled ) return;
createComponent();
ready();
})
.catch( error => {
if ( cancelled ) return;
this.set({ error });
});
} else {
createComponent();
ready();
}
}

Expand Down Expand Up @@ -285,6 +321,13 @@
if ( error ) this.set({ error });
});
});
},

methods: {
run () {
this.set({ pending: false });
this.createComponent();
}
}
};
</script>