Skip to content
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

examples) add the-time example #142

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions examples/the-time/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": "chrome 70"
}
]
],
"plugins": [
[
"@babel/plugin-transform-typescript",
{
"isTSX": true
}
],
[
"transform-runtime",
{
"regenerator": true
}
],
[
"@babel/plugin-transform-react-jsx",
{
"useBuiltIns": true,
"pragma": "ko.jsx.createElement",
"pragmaFrag": "ko.jsx.Fragment",
"throwIfNamespace": false
}
]
],
"parserOpts": {}
}
23 changes: 23 additions & 0 deletions examples/the-time/entry.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import tko from "./tko";

console.log("Entry.");

class TheTime extends tko.Component {
get template() {
const date = new Date().toISOString();
return <div>{date}</div>;
}
}

tko.components.unregister("the-time");
TheTime.register("the-time");

const applyBindings = async () => {
// We usually don't need to cleanNode before
// applying bindings, but it's needed for
// codesandbox.io
await tko.cleanNode(document.body);
tko.applyBindings();
}

applyBindings()
14 changes: 14 additions & 0 deletions examples/the-time/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TKO Example</title>
</head>

<body>
<h1>The time on refresh was:</h1>
<the-time />
<script type="module" src="./entry.tsx"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions examples/the-time/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"dependencies": {
"@babel/core": "7.14.6",
"@babel/plugin-transform-typescript": "7.14.6",
"@tko/build.reference": "4.0.0-alpha9.0"
},
"private": true,
"keywords": [],
"name": "tko-the-time",
"description": ""
}
7 changes: 7 additions & 0 deletions examples/the-time/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"infiniteLoopProtection": true,
"hardReloadOnChange": true,
"view": "browser",
"disableLogging": false,
"template": "parcel"
}
5 changes: 5 additions & 0 deletions examples/the-time/tko.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import tko from "@tko/build.reference/dist/build.reference.es6";

globalThis.ko = tko;

export default tko;
16 changes: 16 additions & 0 deletions examples/the-time/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"jsx": "preserve",
"esModuleInterop": true,
"sourceMap": true,
"allowJs": true,
"lib": [
"es6",
"dom"
],
"rootDir": "src",
"moduleResolution": "node",
"target": "esnext"
}
}