Compare commits

..

4 commits

2 changed files with 12 additions and 9 deletions

View file

@ -1,7 +1,8 @@
<script type="importmap"> <script type="importmap">
{ {
"imports": { "imports": {
"nyooom/render": "./render.js" "nyooom/render": "./render.js",
"nyooom/observable": "./observable.js"
} }
} }
</script> </script>

View file

@ -224,7 +224,7 @@ export class ObservableObject extends Observable {
const handler = () => ref.deref()?.emit(prop, observable, observable, {observable: true}) const handler = () => ref.deref()?.emit(prop, observable, observable, {observable: true})
handlers.set(prop, handler) handlers.set(prop, handler)
observable.addEventListener("change", handler, {signal: this.signal}) observable.addEventListener("changed", handler, {signal: this.signal})
} }
/** Undoes the adoption of a nested observable, cancelling the associated event hook /** Undoes the adoption of a nested observable, cancelling the associated event hook
@ -234,7 +234,7 @@ export class ObservableObject extends Observable {
disown(prop, observable) { disown(prop, observable) {
const handlers = this.#nested.get(observable) const handlers = this.#nested.get(observable)
const handler = handlers.get(prop) const handler = handlers.get(prop)
observable.removeEventListener("change", handler) observable.removeEventListener("changed", handler)
handlers.delete(prop) handlers.delete(prop)
if (handlers.size == 0) { if (handlers.size == 0) {
this.#nested.delete(observable) this.#nested.delete(observable)
@ -264,7 +264,7 @@ export class ObservableValue extends Observable {
/** /**
* @param {(value: any) => any} func * @param {(value: any) => any} func
*/ */
compose(func) { transform(func) {
return new Composition(func, {}, this) return new Composition(func, {}, this)
} }
@ -286,7 +286,7 @@ class ProxiedObservableValue extends ObservableValue {
this.#prop = prop this.#prop = prop
const ref = this.ref const ref = this.ref
backend.addEventListener("synchronous", event => { backend.addEventListener("change", event => {
const {property, from, to, ...rest} = event.change const {property, from, to, ...rest} = event.change
if (property == this.#prop) { if (property == this.#prop) {
ref.deref()?.enqueue({ ref.deref()?.enqueue({
@ -323,7 +323,8 @@ export const component = (name, generator, methods) => {
generator = name generator = name
name = camelToKebab(generator.name) name = camelToKebab(generator.name)
} }
component[kebabToCamel(name)] = class extends HTMLElement{ const jsName = kebabToCamel(name)
component[jsName] = class extends HTMLElement{
/** @type {ObservableObject} */ /** @type {ObservableObject} */
state state
@ -344,11 +345,12 @@ export const component = (name, generator, methods) => {
if (content) this.replaceChildren(content) if (content) this.replaceChildren(content)
} }
} }
const element = component[jsName]
if (methods) { if (methods) {
Object.defineProperties(Element.prototype, Object.getOwnPropertyDescriptors(methods)) Object.defineProperties(element.prototype, Object.getOwnPropertyDescriptors(methods))
} }
customElements.define(name, Element) customElements.define(name, element)
return Element; return element;
} }
class Composition extends ObservableValue { class Composition extends ObservableValue {