Skip to content

Commit

Permalink
Added better typescript defs and fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianFun123 committed Mar 6, 2024
1 parent 1572092 commit 75f7afd
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 3,588 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ import {CustomElement, State, Attribute} from "jdomjs/decorator.ts";
@CustomElement('example-component')
class ExampleComponent extends JDOMComponent {
@State()
private name: Hook<String> = 'John'
private name = new Hook<String>('John')

@State()
@Attribute({ name: 'last-name' })
private lastName: Hook<String> = 'default'
private lastName = new Hook<String>('default')

@Computed(s => [s.name])
private greetings() {
Expand Down
2 changes: 1 addition & 1 deletion dist/jdom.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/jdom.js.LICENSE.txt

This file was deleted.

53 changes: 53 additions & 0 deletions examples/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,55 @@
import Hook from "../src/Hook.js";
import { ForEach, Awaiting } from "../src/template/helper/components.js";

const a = state(['asc', 'asd'])

watch([a], () => console.log(a.value))

html`
<button @click=${()=> a.value = typeof a.value === 'string' ? ['a', 'b', 'c'] : 'Hallo'}>Toggle</button>
${a}
`.appendTo(document)

/*
const paste = fetch(`https://pastefy.app/api/v2/paste/9XH0KD7g`)
.then(r => r.json())
.then(r => JSON.parse(r.content))
function a({name, contents}) {
console.log(name, contents)
return html`
<h1 ${{name}}>${name}</h1>
<pre ${{name}}>${contents}</pre>
`
}
html`
<h1>Test</h1>
${computed(() => [
[
$n('h2').text('yo'),
$n('h2').text('yo2')
],
$n('h2').text('yo3'),
$n('h2').text('yo4')
])}
<${Awaiting}
promise=${paste}
finished=${r => html`<${ForEach}
value=${r}
content=${a}}
>`}
error=${e => `Error while loading: ${e}`}
/>
`.appendTo(document)
function showDialog() {
// language = css
const dialog = html`
Expand Down Expand Up @@ -52,6 +101,8 @@ <h2>Yee</h2>
},
]);
watch([elements], v => console.log(v))
function waitforme() {
return new Promise((res) => {
setTimeout(() => {
Expand All @@ -70,6 +121,7 @@ <h2>Yee</h2>
const prom = waitforme();
html`
<${ForEach}
:bind=${list}
content=${(value, index) => {
Expand Down Expand Up @@ -165,6 +217,7 @@ <h2>Yee</h2>
>
Add Element
</button>
`;
console.log(myHTML);
Expand Down
12 changes: 6 additions & 6 deletions examples/ts-components/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ interface Task {
@CustomElement('todo-app')
class ToDoApp extends JDOMComponent {
@State()
private tasks: Hook<Task> = [];
private tasks = new Hook<Task[]>([]);

@State()
private newTaskText: Hook<String> = '';
private newTaskText = new Hook<String>('');

constructor() {
super();
}

addTask() {
if (this.newTaskText.value.trim()) {
this.tasks = [...this.tasks.value, { text: this.newTaskText.value.trim(), done: false }];
this.newTaskText = ''; // Clear input field
this.tasks.value = [...this.tasks.value, { text: this.newTaskText.value.trim(), done: false }];
this.newTaskText.value = ''; // Clear input field
}
}

toggleDone(index: number) {
this.tasks = this.tasks.value.map((task, i) =>
this.tasks.value = this.tasks.value.map((task, i) =>
index === i ? { ...task, done: !task.done } : task
);
}

removeTask(index: number) {
this.tasks = this.tasks.value.filter((_, i) => i !== index);
this.tasks.value = this.tasks.value.filter((_, i) => i !== index);
}

@Computed(s => [s.tasks])
Expand Down
Loading

0 comments on commit 75f7afd

Please sign in to comment.