Skip to content

Commit

Permalink
[feat] re-expose folder evm (forgot how much it was used externally)
Browse files Browse the repository at this point in the history
  • Loading branch information
braebo committed May 16, 2024
1 parent de0c122 commit a34b428
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 35 deletions.
7 changes: 0 additions & 7 deletions src/lib/gui/Folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,6 @@ export class Folder {

evm = new EventManager<FolderEvents>(['change', 'refresh', 'toggle'])
on = this.evm.on.bind(this.evm)

/**
* Subscriptions to be disposed of when the folder is destroyed.
*/
private _subs: Array<() => void> = []
private _log: Logger
/**
* Used to disable clicking the header to open/close the folder.
Expand Down Expand Up @@ -869,8 +864,6 @@ export class Folder {
}

dispose() {
this._subs.forEach(unsub => unsub())

this.elements.header.removeEventListener('click', this.toggle)
this.elements.header.addEventListener('pointerdown', this.#handleClick)

Expand Down
7 changes: 1 addition & 6 deletions src/lib/gui/Gui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ export class Gui {
windowManager?: WindowManager
undoManager = new UndoManager()
private _theme: GuiOptions['theme']
private _subs = new Set<() => void>()
private _log: Logger

// Forwarding the Folder API...
Expand Down Expand Up @@ -626,7 +625,7 @@ export class Gui {
finalThemer = themer
}

this._subs.add(
this.folder.evm.add(
finalThemer.mode.subscribe(() => {
if (this.settingsFolder) {
this.applyAltStyle(this.settingsFolder)
Expand Down Expand Up @@ -753,9 +752,5 @@ export class Gui {
this.settingsFolder.dispose()
this.folder.dispose()
this.container.remove()

for (const unsub of this._subs) {
unsub()
}
}
}
22 changes: 11 additions & 11 deletions src/lib/gui/inputs/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export abstract class Input<

private _title = ''
private _index: number
private _log: Logger
private __log: Logger

constructor(
options: TOptions & { __type: T__TYPE },
Expand All @@ -226,11 +226,11 @@ export abstract class Input<
this.opts.presetId ??
`${folder.resolvePresetId()}_${this.opts.title}__${this.opts.__type}`

this._log = new Logger(
this.__log = new Logger(
`Input${this.opts.__type!.replaceAll(/Options|Input/g, '')} ${this.opts.title}`,
{ fg: 'skyblue' },
)
this._log.fn('super constructor').info({ options, this: this })
this.__log.fn('super constructor').info({ options, this: this })

this._title = this.opts.title ?? ''
this._disabled = toFn(this.opts.disabled ?? false)
Expand Down Expand Up @@ -268,7 +268,7 @@ export abstract class Input<
delay: 1000,
},
onclick: () => {
this._log.fn('reset').info('resetting to initial value', this.initialValue)
this.__log.fn('reset').info('resetting to initial value', this.initialValue)
this.set(this.initialValue as TValueType)
},
})
Expand Down Expand Up @@ -379,7 +379,7 @@ export abstract class Input<
this.dirty = this.dirtyCheck()

// if (this.bubble === false) {
// this._log
// this.__log
// .fn('_emit')
// .info('Bubbling disabled. Events will be silent until next update.')

Expand All @@ -402,13 +402,13 @@ export abstract class Input<
protected lock = (from = this.state.value) => {
this.undoLock = true
this.lockCommit.from = from
this._log.fn('lock').info('lockCommit:', this.lockCommit)
this.__log.fn('lock').info('lockCommit:', this.lockCommit)
}
/**
* Unlocks commits and saves the current commit stored in lock.
*/
protected unlock = (commit?: Partial<Commit>) => {
this._log.fn('unlock').debug('commit', { commit, lockCommit: this.lockCommit })
this.__log.fn('unlock').debug('commit', { commit, lockCommit: this.lockCommit })
commit ??= {}
commit.input ??= this as unknown as Input<TValueType>
commit.to ??= this.state.value as TValueType
Expand All @@ -423,10 +423,10 @@ export abstract class Input<
commit(commit: Partial<Commit>) {
commit.from ??= this.state.value
if (this.undoLock) {
this._log.fn('commit').debug('prevented commit while locked')
this.__log.fn('commit').debug('prevented commit while locked')
return
}
this._log.fn('commit').debug('commited', commit)
this.__log.fn('commit').debug('commited', commit)
this.undoManager?.commit<TValueType>({
input: this,
...commit,
Expand Down Expand Up @@ -473,7 +473,7 @@ export abstract class Input<
resettable: this.opts.resettable ?? true,
}

this._log.fn('save').debug(preset)
this.__log.fn('save').debug(preset)

return Object.assign(preset, overrides)
}
Expand All @@ -488,7 +488,7 @@ export abstract class Input<
}

dispose() {
this._log.fn('dispose').debug(this)
this.__log.fn('dispose').debug(this)
this.evm.dispose()

const rm = (elOrObj: any) => {
Expand Down
21 changes: 10 additions & 11 deletions src/lib/themer/Themer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,6 @@ export class ThemeEditor {
gui: Gui
private _log: Logger

/**
* Unsubscribes the theme editor from the theme. Called on dispose.
* @internal
*/
private _unsubscribe?: () => void

get folder() {
return this.gui.folder
}
Expand Down Expand Up @@ -671,11 +665,17 @@ export class ThemeEditor {
// console.log(targetGui.container)
// console.log(this.gui.container)

targetGui.themer?.addTarget(this.gui.wrapper)
if (!this.targetGui.themer) {
throw new Error('Themer not found.')
}

this._unsubscribe = this.targetGui.themer?.theme.subscribe(t => {
this.gui.folder.title = `${opts?.title} · ${t.title}`
})
this.targetGui.themer.addTarget(this.gui.wrapper)

this.folder.evm.add(
this.targetGui.themer.theme.subscribe(t => {
this.gui.folder.title = `${opts?.title} · ${t.title}`
}),
)

this.targetGui.themer!.applyTheme()

Expand All @@ -692,7 +692,6 @@ export class ThemeEditor {
}

dispose() {
this._unsubscribe?.()
this.gui.dispose()
}

Expand Down

0 comments on commit a34b428

Please sign in to comment.