Skip to content

Commit

Permalink
remove guts of Component
Browse files Browse the repository at this point in the history
  • Loading branch information
ramseyball authored Oct 10, 2023
1 parent b99acd9 commit 924a291
Showing 1 changed file with 1 addition and 43 deletions.
44 changes: 1 addition & 43 deletions component.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,10 @@
namespace microcode {
let id_sequence = 0

export type ComponentHandler = (comp: Component) => void

export interface IKindable {
kind: string
}

export abstract class Component implements IKindable {
private id_: number
private data_: any
private _destroyHandlers: ComponentHandler[]
private _destroyed = false

//% blockCombine block="id" callInDebugger
get id() {
return this.id_
}
get data(): any {
if (!this.data_) {
this.data_ = {}
}
return this.data_
}
get destroyed(): boolean {
return this._destroyed
}

constructor(public kind: string) {
this.id_ = id_sequence++
}

onDestroy(handler: ComponentHandler) {
this._destroyHandlers = this._destroyHandlers || []
this._destroyHandlers.push(handler)
}

/* virtual */ destroy() {
if (this._destroyed) console.warn(`double destroy on ${this.id}`)
this._destroyed = true
const handlers = this._destroyHandlers || []
this._destroyHandlers = undefined
for (const handler of handlers) {
handler(this)
}
this.data_ = undefined
}

/* abstract */ destroy() { }
/* abstract */ update() {}
/* abstract */ draw() {}
}
Expand Down

0 comments on commit 924a291

Please sign in to comment.