vue#ComponentPropsOptions TypeScript Examples
The following examples show how to use
vue#ComponentPropsOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Geometry.ts From trois with MIT License | 6 votes |
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function geometryComponent<P extends Readonly<ComponentPropsOptions>>(
name: string,
props: P,
createGeometry: {(c: any): BufferGeometry}
) {
return defineComponent({
name,
extends: Geometry,
props,
methods: {
createGeometry() {
this.geometry = createGeometry(this)
this.geometry.userData.component = this
this.$emit('created', this.geometry)
},
},
})
}
Example #2
Source File: Material.ts From trois with MIT License | 6 votes |
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function materialComponent<P extends Readonly<ComponentPropsOptions>>(
name: string,
props: P,
createMaterial: {(opts: any): Material}
) {
return defineComponent({
name,
extends: BaseMaterial,
props,
methods: {
createMaterial() {
return createMaterial(this.getMaterialParams())
},
},
})
}
Example #3
Source File: Mesh.ts From trois with MIT License | 6 votes |
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export function meshComponent<P extends Readonly<ComponentPropsOptions>>(
name: string,
props: P,
createGeometry: {(c: any): BufferGeometry}
) {
return defineComponent({
name,
extends: Mesh,
props,
created() {
this.createGeometry()
this.addGeometryWatchers(props)
},
methods: {
createGeometry() {
this.geometry = createGeometry(this)
},
},
})
}
Example #4
Source File: Mesh.ts From trois with MIT License | 5 votes |
Mesh = defineComponent({
name: 'Mesh',
extends: Object3D,
props: {
castShadow: Boolean,
receiveShadow: Boolean,
},
setup(): MeshSetupInterface {
return {}
},
provide() {
return {
[MeshInjectionKey as symbol]: this,
}
},
mounted() {
// TODO : proper ?
if (!this.mesh && !this.loading) this.initMesh()
},
methods: {
initMesh() {
const mesh = new TMesh(this.geometry, this.material)
bindProp(this, 'castShadow', mesh)
bindProp(this, 'receiveShadow', mesh)
this.mesh = mesh
this.initObject3D(mesh)
},
createGeometry() {},
addGeometryWatchers(props: Readonly<ComponentPropsOptions>) {
Object.keys(props).forEach(prop => {
// @ts-ignore
watch(() => this[prop], () => {
this.refreshGeometry()
})
})
},
setGeometry(geometry: BufferGeometry) {
this.geometry = geometry
if (this.mesh) this.mesh.geometry = geometry
},
setMaterial(material: Material) {
this.material = material
if (this.mesh) this.mesh.material = material
},
refreshGeometry() {
const oldGeo = this.geometry
this.createGeometry()
if (this.mesh && this.geometry) this.mesh.geometry = this.geometry
oldGeo?.dispose()
},
},
unmounted() {
// for predefined mesh (geometry/material are not unmounted)
if (this.geometry) this.geometry.dispose()
if (this.material) this.material.dispose()
},
__hmrId: 'Mesh',
})