-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08d072b
commit b34b753
Showing
11 changed files
with
675 additions
and
485 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<title>Blog with KasperJs</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<script src="../dist/kasper.min.js"></script> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<script> | ||
tailwind.config = { | ||
theme: { | ||
fontFamily: { | ||
mono: [ | ||
"Share Tech Mono", | ||
"Consolas", | ||
"Liberation Mono", | ||
"Courier New", | ||
], | ||
}, | ||
}, | ||
}; | ||
</script> | ||
</head> | ||
<body> | ||
<template> | ||
<div class="w-dvw h-dvh flex text-gray-50"> | ||
<div class="w-96 flex-none bg-gray-900 p-6 h-full overflow-y-scroll"> | ||
<div class="flex flex-col gap-4"> | ||
<div | ||
@each="const post of posts.value" | ||
class="py-2 rounded border border-gray-100" | ||
> | ||
<button | ||
class="flex flex-col text-left gap-2" | ||
@on:click="onOpenPost(post)" | ||
> | ||
<div class="text-lg px-2 leading-tight">{{post.title}}</div> | ||
<div class="text-xs px-2">{{post.body}}</div> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="flex-grow bg-gray-700 p-6"> | ||
<div @if="post.value && user.value"> | ||
<kvoid @init="u = user.value"> | ||
<div class="text-lg">Author</div> | ||
<div class="flex flex-col pb-4"> | ||
<div class="text-lg font-bold">{{u.name}}</div> | ||
<div class="text-sm text-gray-400">{{u.email}}</div> | ||
</div> | ||
</kvoid> | ||
<kvoid @init="p = post.value"> | ||
<div class="text-2xl font-bold">{{p.title}}</div> | ||
<div class="text-sm text-gray-400">{{p.body}}</div> | ||
</kvoid> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
<script> | ||
async function fetchPosts() { | ||
const response = await fetch( | ||
"https://jsonplaceholder.typicode.com/posts" | ||
); | ||
return (await response.json()).slice(0, 7); | ||
} | ||
|
||
async function fetchPostById(id) { | ||
const response = await fetch( | ||
`https://jsonplaceholder.typicode.com/posts/${id}` | ||
); | ||
return await response.json(); | ||
} | ||
|
||
async function fetchUserById(id) { | ||
const response = await fetch( | ||
`https://jsonplaceholder.typicode.com/users/${id}` | ||
); | ||
return await response.json(); | ||
} | ||
|
||
class MyTodoApp extends KasperApp { | ||
posts = this.$state([]); | ||
user = this.$state(null); | ||
post = this.$state(null); | ||
|
||
$onInit = async () => { | ||
const posts = await fetchPosts(); | ||
this.posts.set(posts); | ||
}; | ||
|
||
onOpenPost = async (post) => { | ||
const user = await fetchUserById(post.userId); | ||
this.post.set(post); | ||
this.user.set(user); | ||
}; | ||
} | ||
Kasper(MyTodoApp); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { KasperApp } from "./kasper"; | ||
|
||
export class State { | ||
_value: any; | ||
entity: KasperApp; | ||
render: (entity: any) => void; | ||
|
||
constructor(initial: any, entity: KasperApp) { | ||
this._value = initial; | ||
this.entity = entity; | ||
} | ||
|
||
get value(): any { | ||
return this._value; | ||
} | ||
|
||
set(value: any) { | ||
this._value = value; | ||
this.entity.$changes += 1; | ||
this.entity.$doRender(); | ||
} | ||
|
||
toString() { | ||
return this._value.toString(); | ||
} | ||
} |
Oops, something went wrong.