-
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.
* chore: cleanup build * feat: render components * fix: single app builder * fix: live demo * refactor: const out of each loop * chore: rebuild
- Loading branch information
1 parent
cc98f6a
commit 428cfeb
Showing
13 changed files
with
918 additions
and
591 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,74 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<title>Debug KasperJs</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<script src="../dist/kasper.js"></script> | ||
</head> | ||
<body> | ||
<template id="kasper-app"> | ||
<h1 class="title" data-title="{{attr}}-something-{{appTitle}}"> | ||
{{appTitle}} | ||
</h1> | ||
<app-menu>{{menuTitle}}</app-menu> | ||
<app-content @:title="hello"> | ||
<app-template-only></app-template-only> | ||
</app-content> | ||
</template> | ||
<template id="app-menu"> app menu </template> | ||
<template id="app-content"> | ||
<h2>{{args.title}}</h2> | ||
<div>{{"app-content"}}</div> | ||
<button @on:click="onClick()">click me</button><span>{{counter}}</span> | ||
</template> | ||
<template id="app-template-only"> | ||
<div>template only</div> | ||
template only no class {{22 + 33}} | ||
</template> | ||
<script> | ||
class AppMain extends Component { | ||
appTitle = "Title of the App"; | ||
attr = "attrib"; | ||
} | ||
|
||
class AppMenu extends Component { | ||
menuTitle = "Title of the Menu"; | ||
} | ||
|
||
class AppContent extends Component { | ||
counter = $state(1); | ||
constructor({ args, ref }) { | ||
super({ args, ref }); | ||
console.log(args, ref); | ||
} | ||
onClick = () => { | ||
this.counter.set(this.counter.value + 1); | ||
}; | ||
} | ||
|
||
const registry = { | ||
"kasper-app": { | ||
selector: "template#kasper-app", | ||
component: AppMain, | ||
}, | ||
"app-menu": { | ||
selector: "template#app-menu", | ||
component: AppMenu, | ||
}, | ||
"app-content": { | ||
selector: "template#app-content", | ||
component: AppContent, | ||
}, | ||
"app-template-only": { | ||
selector: "template#app-template-only", | ||
}, | ||
}; | ||
kasper.App({ | ||
registry, | ||
root: "body", | ||
}); | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,3 +136,7 @@ text + list[0] * dict.value; | |
``` | ||
console.log('something'); | ||
``` | ||
|
||
## Todo | ||
|
||
- fix state re-render |
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,53 @@ | ||
import { Transpiler } from "./transpiler"; | ||
import { KNode } from "./types/nodes"; | ||
|
||
interface ComponentArgs { | ||
args: Record<string, any>; | ||
ref?: Node; | ||
transpiler?: Transpiler; | ||
} | ||
|
||
export class Component { | ||
args: Record<string, any> = {}; | ||
ref?: Node; | ||
transpiler?: Transpiler; | ||
$onInit = () => {}; | ||
$onRender = () => {}; | ||
$onChanges = () => {}; | ||
$onDestroy = () => {}; | ||
|
||
constructor(props?: ComponentArgs) { | ||
if (!props) { | ||
this.args = {}; | ||
return; | ||
} | ||
if (props.args) { | ||
this.args = props.args || {}; | ||
} | ||
if (props.ref) { | ||
this.ref = props.ref; | ||
} | ||
if (props.transpiler) { | ||
this.transpiler = props.transpiler; | ||
} | ||
} | ||
|
||
$doRender() { | ||
if (!this.transpiler) { | ||
return; | ||
} | ||
//this.transpiler?.createComponent(this); | ||
} | ||
} | ||
|
||
export type KasperEntity = Component | Record<string, any> | null | undefined; | ||
|
||
export type ComponentClass = { new (args?: ComponentArgs): Component }; | ||
export interface ComponentRegistry { | ||
[tagName: string]: { | ||
selector: string; | ||
component: ComponentClass; | ||
template: Element; | ||
nodes: KNode[]; | ||
}; | ||
} |
Oops, something went wrong.