Add support for multiple changes in a single ChangeTracker state (#1022)

* wip

* Add tests

* Update package

* remove logs

* nit

* nit

---------

Co-authored-by: huchenlei <huchenlei@proton.me>
This commit is contained in:
pythongosssss
2024-10-03 00:53:54 +09:00
committed by GitHub
parent cc2b64df52
commit 861bcabd66
4 changed files with 237 additions and 25 deletions

View File

@@ -12,6 +12,7 @@ export class ChangeTracker {
activeState = null
isOurLoad = false
workflow: ComfyWorkflow | null
changeCount = 0
ds: { scale: number; offset: [number, number] }
nodeOutputs: any
@@ -46,7 +47,7 @@ export class ChangeTracker {
}
checkState() {
if (!this.app.graph) return
if (!this.app.graph || this.changeCount) return
const currentState = this.app.graph.serialize()
if (!this.activeState) {
@@ -100,6 +101,16 @@ export class ChangeTracker {
}
}
beforeChange() {
this.changeCount++
}
afterChange() {
if (!--this.changeCount) {
this.checkState()
}
}
static init(app: ComfyApp) {
const changeTracker = () =>
app.workflowManager.activeWorkflow?.changeTracker ?? globalTracker
@@ -210,6 +221,15 @@ export class ChangeTracker {
return v
}
// Handle multiple commands as a single transaction
document.addEventListener('litegraph:canvas', (e: CustomEvent) => {
if (e.detail.subType === 'before-change') {
changeTracker().beforeChange()
} else if (e.detail.subType === 'after-change') {
changeTracker().afterChange()
}
})
// Store node outputs
api.addEventListener('executed', ({ detail }) => {
const prompt =