Skip to content

Commit

Permalink
batch removeElement, fixes overtake bug, but does not solve it
Browse files Browse the repository at this point in the history
  • Loading branch information
MichiSpebach committed Jul 14, 2024
1 parent 5f9d96f commit 1caec1f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/browserApp/DirectDomAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export class DirectDomAdapter implements DocumentObjectModelAdapter {

case 'innerHTML':
return this.setContentToSync(command.elementId, command.value as string)

case 'removeElement':
return this.removeSync(command.elementId)

case 'setStyleTo':
return this.setStyleToSync(command.elementId, command.value as string|Style)
Expand Down Expand Up @@ -306,6 +309,9 @@ export class DirectDomAdapter implements DocumentObjectModelAdapter {
}

public async remove(id: string): Promise<void> {
this.removeSync(id)
}
public removeSync(id: string): void {
const element: HTMLElement|null = this.getElement(id)
if (!element) {
util.logWarning(`DirectDomAdapter::remove(..) failed to get element with id '${id}'.`)
Expand Down
9 changes: 6 additions & 3 deletions src/core/RenderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ export class RenderManager {
public remove(id: string, priority: RenderPriority = RenderPriority.NORMAL): Promise<void> {
return this.runOrSchedule(new Command({
priority: priority,
command: () => dom.remove(id)
command: () => dom.remove(id),
batchParameters: {elementId: id, method: 'removeElement', value: ''}
}))
}

Expand Down Expand Up @@ -301,7 +302,8 @@ export class RenderManager {
}))
}

public async runOrSchedule<T>(command: Command): Promise<T> { // only public for unit tests
/** only public for unit tests */
public async runOrSchedule<T>(command: Command): Promise<T> {
const combinedCommand: Command|undefined = this.tryToCombineWithQueuedCommands(command)
if (combinedCommand) {
return combinedCommand.promise.get()
Expand Down Expand Up @@ -335,7 +337,8 @@ export class RenderManager {
return command.promise.get()
}

public addCommand(command: Command): void { // only public for unit tests
/** only public for unit tests */
public addCommand(command: Command): void {
let i = 0
for(; i < this.commands.length; i++) {
const queuedCommand: Command = this.commands[i]
Expand Down
2 changes: 1 addition & 1 deletion src/core/domAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type MouseEventResultAdvanced = {
targetPathElementIds: string[]
}

export type BatchMethod = 'appendChildTo'|'addContentTo'|'addElementsTo'|'addElementTo'|'setElementsTo'|'setElementTo'|'innerHTML'|'setStyleTo'|'addStyleTo'|'addClassTo'|'removeClassFrom'
export type BatchMethod = 'appendChildTo'|'addContentTo'|'addElementsTo'|'addElementTo'|'setElementsTo'|'setElementTo'|'innerHTML'|'removeElement'|'setStyleTo'|'addStyleTo'|'addClassTo'|'removeClassFrom'

export let dom: DocumentObjectModelAdapter

Expand Down
3 changes: 3 additions & 0 deletions src/electronApp/ElectronIpcDomAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export class ElectronIpcDomAdapter implements DocumentObjectModelAdapter {

case 'innerHTML':
return `document.getElementById('${command.elementId}').innerHTML='${command.value}';`// TODO: fails if innerHTML includes "'"

case 'removeElement':
return `document.getElementById('${command.elementId}').remove();`

case 'setStyleTo':
if (typeof command.value === 'string') {
Expand Down

0 comments on commit 1caec1f

Please sign in to comment.