From 17e334444d385a0b4f98af1b7434d51c3ec399a5 Mon Sep 17 00:00:00 2001 From: Kevin Levron Date: Sat, 19 Sep 2020 16:40:58 +0200 Subject: [PATCH] improve hmr with __hmrId --- src/core/PerspectiveCamera.js | 1 + src/lights/AmbientLight.js | 1 + src/lights/DirectionalLight.js | 1 + src/lights/Light.js | 1 + src/lights/PointLight.js | 1 + src/lights/SpotLight.js | 1 + src/meshes/Box.js | 1 + src/meshes/Image.js | 1 + src/meshes/InstancedMesh.js | 1 + src/meshes/Mesh.js | 1 + src/meshes/Plane.js | 1 + src/meshes/Sphere.js | 1 + src/use/useBindProp.js | 10 ++++++---- 13 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core/PerspectiveCamera.js b/src/core/PerspectiveCamera.js index 752085a..085a4bb 100644 --- a/src/core/PerspectiveCamera.js +++ b/src/core/PerspectiveCamera.js @@ -32,4 +32,5 @@ export default { render() { return []; }, + __hmrId: 'PerspectiveCamera', }; diff --git a/src/lights/AmbientLight.js b/src/lights/AmbientLight.js index 2e55579..982fa42 100644 --- a/src/lights/AmbientLight.js +++ b/src/lights/AmbientLight.js @@ -6,4 +6,5 @@ export default { created() { this.light = new AmbientLight(this.color, this.intensity); }, + __hmrId: 'AmbientLight', }; diff --git a/src/lights/DirectionalLight.js b/src/lights/DirectionalLight.js index 64c92d7..ddb4632 100644 --- a/src/lights/DirectionalLight.js +++ b/src/lights/DirectionalLight.js @@ -6,4 +6,5 @@ export default { created() { this.light = new DirectionalLight(this.color, this.intensity); }, + __hmrId: 'DirectionalLight', }; diff --git a/src/lights/Light.js b/src/lights/Light.js index 430b34b..6e3a4c2 100644 --- a/src/lights/Light.js +++ b/src/lights/Light.js @@ -33,4 +33,5 @@ export default { render() { return []; }, + __hmrId: 'Light', }; diff --git a/src/lights/PointLight.js b/src/lights/PointLight.js index 7165330..e00e98f 100644 --- a/src/lights/PointLight.js +++ b/src/lights/PointLight.js @@ -16,4 +16,5 @@ export default { created() { this.light = new PointLight(this.color, this.intensity, this.distance, this.decay); }, + __hmrId: 'PointLight', }; diff --git a/src/lights/SpotLight.js b/src/lights/SpotLight.js index cdca565..f1953b5 100644 --- a/src/lights/SpotLight.js +++ b/src/lights/SpotLight.js @@ -24,4 +24,5 @@ export default { created() { this.light = new SpotLight(this.color, this.intensity, this.distance, this.angle, this.penumbra, this.decay); }, + __hmrId: 'SpotLight', }; diff --git a/src/meshes/Box.js b/src/meshes/Box.js index e3182df..8bc0f78 100644 --- a/src/meshes/Box.js +++ b/src/meshes/Box.js @@ -27,4 +27,5 @@ export default { this.geometry = new BoxBufferGeometry(this.width, this.height, this.depth); } }, + __hmrId: 'Box', }; diff --git a/src/meshes/Image.js b/src/meshes/Image.js index 513f71a..1d37113 100644 --- a/src/meshes/Image.js +++ b/src/meshes/Image.js @@ -22,4 +22,5 @@ export default { // this material is not mounted, it won't be auto dispose this.material.dispose(); }, + __hmrId: 'Image', }; diff --git a/src/meshes/InstancedMesh.js b/src/meshes/InstancedMesh.js index 6b88b0e..60fd382 100644 --- a/src/meshes/InstancedMesh.js +++ b/src/meshes/InstancedMesh.js @@ -41,4 +41,5 @@ export default { render() { return this.$slots.default(); }, + __hmrId: 'InstancedMesh', }; diff --git a/src/meshes/Mesh.js b/src/meshes/Mesh.js index 3704e56..540af03 100644 --- a/src/meshes/Mesh.js +++ b/src/meshes/Mesh.js @@ -45,4 +45,5 @@ export default { render() { return []; }, + __hmrId: 'Mesh', }; diff --git a/src/meshes/Plane.js b/src/meshes/Plane.js index 312fc68..658b63a 100644 --- a/src/meshes/Plane.js +++ b/src/meshes/Plane.js @@ -24,4 +24,5 @@ export default { created() { this.geometry = new PlaneBufferGeometry(this.width, this.height, this.widthSegments, this.heightSegments); }, + __hmrId: 'Plane', }; diff --git a/src/meshes/Sphere.js b/src/meshes/Sphere.js index a2692fc..8e288fc 100644 --- a/src/meshes/Sphere.js +++ b/src/meshes/Sphere.js @@ -17,4 +17,5 @@ export default { created() { this.geometry = new SphereBufferGeometry(this.radius, this.widthSegments, this.heightSegments); }, + __hmrId: 'Sphere', }; diff --git a/src/use/useBindProp.js b/src/use/useBindProp.js index d5972fd..e49154f 100644 --- a/src/use/useBindProp.js +++ b/src/use/useBindProp.js @@ -2,9 +2,11 @@ import { toRef, watch } from 'vue'; import { setFromProp } from '../tools.js'; export default function useBindProp(comp, prop, object) { - const ref = toRef(comp, prop); - setFromProp(object, ref.value); - watch(ref, () => { + if (comp[prop]) { + const ref = toRef(comp, prop); setFromProp(object, ref.value); - }, { deep: true }); + watch(ref, () => { + setFromProp(object, ref.value); + }, { deep: true }); + } };