-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stagger mounting/unmounting/deleting
- Loading branch information
1 parent
b3b4701
commit 706eee6
Showing
6 changed files
with
256 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
export interface RenderObject { | ||
mounted: boolean | ||
|
||
mount(): this | ||
|
||
unmount(): this | ||
|
||
delete(): void | ||
} | ||
|
||
export class ObjectManager { | ||
|
||
private batchSize: number | ||
|
||
private toMount = new Set<RenderObject>() | ||
|
||
private toUnmount = new Set<RenderObject>() | ||
|
||
private toDelete = new Set<RenderObject>() | ||
|
||
constructor(batchSize: number) { | ||
this.batchSize = batchSize | ||
} | ||
|
||
mount(object: RenderObject) { | ||
this.toUnmount.delete(object) | ||
this.toMount.add(object) | ||
} | ||
|
||
unmount(object: RenderObject) { | ||
this.toMount.delete(object) | ||
this.toUnmount.add(object) | ||
} | ||
|
||
delete(object: RenderObject) { | ||
this.toMount.delete(object) | ||
this.toUnmount.delete(object) | ||
this.toDelete.add(object) | ||
} | ||
|
||
render() { | ||
let toDeleteCount = 0 | ||
let toMountCount = 0 | ||
let toUnmountCount = 0 | ||
|
||
for (const object of this.toDelete) { | ||
if (toMountCount === this.batchSize) { | ||
break | ||
} | ||
|
||
object.delete() | ||
|
||
this.toDelete.delete(object) | ||
|
||
toDeleteCount++ | ||
} | ||
|
||
for (const object of this.toMount) { | ||
if (toMountCount === this.batchSize) { | ||
break | ||
} | ||
|
||
object.mount() | ||
|
||
this.toMount.delete(object) | ||
|
||
toMountCount++ | ||
} | ||
|
||
for (const object of this.toUnmount) { | ||
if (toUnmountCount === this.batchSize) { | ||
break | ||
} | ||
|
||
object.unmount() | ||
|
||
this.toUnmount.delete(object) | ||
|
||
toUnmountCount++ | ||
} | ||
} | ||
} | ||
|
||
// export class ObjectManager { | ||
|
||
// private batchSize: number | ||
|
||
// private toMount = new Set<RenderObject>() | ||
|
||
// private toUnmount = new Set<RenderObject>() | ||
|
||
// private toDelete = new Set<RenderObject>() | ||
|
||
// constructor(batchSize: number) { | ||
// this.batchSize = batchSize | ||
// } | ||
|
||
// mount(object: RenderObject) { | ||
// this.toUnmount.delete(object) | ||
// this.toMount.add(object) | ||
// } | ||
|
||
// unmount(object: RenderObject) { | ||
// this.toMount.delete(object) | ||
// this.toUnmount.add(object) | ||
// } | ||
|
||
// delete(object: RenderObject) { | ||
// this.toDelete.add(object) | ||
// } | ||
|
||
// render() { | ||
// let toDeleteCount = 0 | ||
// let toMountCount = 0 | ||
// let toUnmountCount = 0 | ||
|
||
// for (const object of this.toDelete) { | ||
// if (toMountCount === this.batchSize) { | ||
// break | ||
// } | ||
|
||
// object.delete() | ||
|
||
// this.toMount.delete(object) | ||
// this.toUnmount.delete(object) | ||
// this.toDelete.delete(object) | ||
|
||
// toDeleteCount++ | ||
// } | ||
|
||
// for (const object of this.toMount) { | ||
// if (toMountCount === this.batchSize) { | ||
// break | ||
// } | ||
|
||
// object.mount() | ||
|
||
// this.toMount.delete(object) | ||
|
||
// toMountCount++ | ||
// } | ||
|
||
// for (const object of this.toUnmount) { | ||
// if (toUnmountCount === this.batchSize) { | ||
// break | ||
// } | ||
|
||
// object.unmount() | ||
|
||
// this.toUnmount.delete(object) | ||
|
||
// toUnmountCount++ | ||
// } | ||
// } | ||
// } |
Oops, something went wrong.