-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add 'assignFrom' for dynamic assignment to parent properties #114
- Loading branch information
Showing
24 changed files
with
490 additions
and
369 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,32 @@ | ||
import { Scene } from '@babylonjs/core'; | ||
import { CreatedInstance } from '../CreatedInstance'; | ||
import { LifecycleListener } from '../LifecycleListener'; | ||
import { applyInitialPropsToCreatedInstance } from '../UpdateInstance'; | ||
|
||
export default abstract class BaseLifecycleListener<T, U> implements LifecycleListener<T> { | ||
|
||
constructor(protected scene: Scene, protected props: U) {/* empty */} | ||
|
||
onParented(parent: CreatedInstance<any>, child: CreatedInstance<any>): void { | ||
if (child.customProps.assignFrom !== undefined) { | ||
if (parent.hostInstance[child.customProps.assignFrom] === undefined) { | ||
console.error(`Cannot find existing property ${child.customProps.assignFrom} on parent component (check your 'assignFrom')`) | ||
} else { | ||
// TODO: should we try to verify types like we do in 'fromInstance'? | ||
child.hostInstance = parent.hostInstance[child.customProps.assignFrom]; | ||
if (child.deferredCreationProps && child.propsHandlers) { | ||
applyInitialPropsToCreatedInstance(child, child.deferredCreationProps); | ||
} else { | ||
console.warn('cannot assign deferred props. they are lost.'); | ||
} | ||
child.deferredCreationProps = undefined; | ||
} | ||
} | ||
} | ||
|
||
onChildAdded(child: CreatedInstance<any>, parent: CreatedInstance<any>): void { /* empty */}; | ||
|
||
onMount(instance: CreatedInstance<T>): void { /* empty */}; | ||
|
||
onUnmount(): void {/* empty */}; | ||
} |
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.