-
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 (#46)
* Common interface for async node initialization * Remove console.logs * Add Rotunda equirect * Add rotunda equirect * Improve VR support * Tweak example * Have ready return the element
- Loading branch information
1 parent
ae0aa9d
commit 4a6fe68
Showing
19 changed files
with
182 additions
and
140 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
Binary file not shown.
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 that initialize asynchronously. | ||
*/ | ||
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 { | ||
return this.parentElement?.closest('pc-app') as AppElement; | ||
} | ||
|
||
get closestEntity(): EntityElement { | ||
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 with this element when it's ready. | ||
* @returns A promise that resolves with this element when it's ready. | ||
*/ | ||
ready(): Promise<this> { | ||
return this._readyPromise.then(() => this); | ||
} | ||
} | ||
|
||
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.