-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from tscircuit/async-effects
Dirty Render Phase Implementation
- Loading branch information
Showing
3 changed files
with
189 additions
and
6 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
50 changes: 50 additions & 0 deletions
50
tests/components/base-components/renderable-dirty-pattern.test.tsx
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,50 @@ | ||
import { test, expect } from "bun:test" | ||
import { Renderable } from "lib/components/base-components/Renderable" | ||
|
||
class TestComponent extends Renderable { | ||
constructor() { | ||
super({}) | ||
} | ||
|
||
doInitialSourceRender() { | ||
// Test async effect | ||
this._queueAsyncEffect(async () => { | ||
await new Promise((resolve) => setTimeout(resolve, 100)) | ||
}) | ||
} | ||
|
||
doInitialSchematicComponentRender() { | ||
// Test marking dirty | ||
this._markDirty("SchematicComponentRender") | ||
} | ||
} | ||
|
||
test("dirty pattern and async effects", async () => { | ||
const component = new TestComponent() | ||
|
||
// Initial state | ||
expect(component.renderPhaseStates.SourceRender.dirty).toBe(false) | ||
expect(component.renderPhaseStates.SchematicComponentRender.dirty).toBe(false) | ||
|
||
// Run initial render phases | ||
component.runRenderPhase("SourceRender") | ||
|
||
// Check async effects | ||
expect(component._hasIncompleteAsyncEffects()).toBe(true) | ||
|
||
// Wait for async effects | ||
await new Promise((resolve) => setTimeout(resolve, 150)) | ||
expect(component._hasIncompleteAsyncEffects()).toBe(false) | ||
|
||
// Test marking phases dirty | ||
component.runRenderPhase("SchematicComponentRender") | ||
|
||
// SchematicComponentRender and subsequent phases should be marked dirty | ||
expect(component.renderPhaseStates.SchematicComponentRender.dirty).toBe(true) | ||
expect(component.renderPhaseStates.SchematicLayout.dirty).toBe(true) | ||
expect(component.renderPhaseStates.SchematicTraceRender.dirty).toBe(true) | ||
|
||
// Previous phases should not be dirty | ||
expect(component.renderPhaseStates.SourceRender.dirty).toBe(false) | ||
expect(component.renderPhaseStates.PortDiscovery.dirty).toBe(false) | ||
}) |