Skip to content

Commit

Permalink
samples: add boilerplate for clones samples
Browse files Browse the repository at this point in the history
  • Loading branch information
thesephist committed May 11, 2019
1 parent 22694dc commit f497592
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
10 changes: 10 additions & 0 deletions samples/clones/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Torus Clones</title>
</head>
<body>
<script src='/dist/index.min.js'></script>
<script src="main.js"></script>
</body>
</html>
77 changes: 77 additions & 0 deletions samples/clones/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//> Clones of popular complex web applications to test rendering
// fidelity.

//> Task: Build a complex UI (FB5, Twitter, Trello clone) in Torus
// and actually measure perf in depe trees, using function components
// liberally to be conservative and not cut Torus any corners.

//> Bootstrap the required globals from Torus, since we're not bundling
for (const exportedName in Torus) {
window[exportedName] = Torus[exportedName];
}

const CLONES = {};

//> ## Facebook Clone
CLONES.Facebook = class extends StyledComponent {

compose() {
return jdom`Facebook`;
}

}

//> ## GitHub Clone
CLONES.GitHub = class extends StyledComponent {

compose() {
return jdom`GH`;
}

}

//> ## Twitter Clone
CLONES.Twitter = class extends StyledComponent {

compose() {
return jdom`Twitter`;
}

}

class App extends StyledComponent {

init() {
this.activeClone = CLONES.Facebook;
}

switchView(cloneName) {
this.activeClone = CLONES[cloneName];
this.render();
}

styles() {
return css`
font-family: system-ui, sans-serif;
`;
}

compose() {
return jdom`<main>
<h1>Clones</h1>
<nav>
<button onclick="${this.switchView.bind(this, 'Facebook')}">Facebook</button>
<button onclick="${this.switchView.bind(this, 'GitHub')}">GitHub</button>
<button onclick="${this.switchView.bind(this, 'Twitter')}">Twitter</button>
</nav>
<div id="cloneContainer">
${new this.activeClone().node}
</div>
</main>`;
}

}

//> Create an instance of the app, and append to the DOM.
const app = new App();
document.body.appendChild(app.node);

0 comments on commit f497592

Please sign in to comment.