-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Common interface for async node initialization
- Loading branch information
1 parent
ae0aa9d
commit 51763b9
Showing
17 changed files
with
177 additions
and
139 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
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,45 @@ | ||
import { AppElement } from './app'; | ||
import { EntityElement } from './entity'; | ||
|
||
/** | ||
* Base class for all PlayCanvas web components. | ||
*/ | ||
class AsyncElement extends HTMLElement { | ||
private _readyPromise: Promise<void>; | ||
|
||
private _readyResolve!: () => void; | ||
|
||
constructor() { | ||
super(); | ||
this._readyPromise = new Promise<void>((resolve) => { | ||
this._readyResolve = resolve; | ||
}); | ||
} | ||
|
||
get closestApp(): AppElement | undefined { | ||
return this.parentElement?.closest('pc-app') as AppElement; | ||
} | ||
|
||
get closestEntity(): EntityElement | undefined { | ||
return this.parentElement?.closest('pc-entity') as EntityElement; | ||
} | ||
|
||
/** | ||
* Called when the element is fully initialized and ready. | ||
* Subclasses should call this when they're ready. | ||
*/ | ||
protected _onReady() { | ||
this._readyResolve(); | ||
this.dispatchEvent(new CustomEvent('ready')); | ||
} | ||
|
||
/** | ||
* Returns a promise that resolves when the element is ready. | ||
* @returns A promise that resolves when the element is ready. | ||
*/ | ||
ready(): Promise<void> { | ||
return this._readyPromise; | ||
} | ||
} | ||
|
||
export { AsyncElement }; |
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
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
Oops, something went wrong.