From 6bef9abbf20a97dfb20f6124776fe90ae19ba654 Mon Sep 17 00:00:00 2001 From: Josh Ellis Date: Fri, 19 Mar 2021 09:21:28 +0000 Subject: [PATCH] chore: move eslint method rule to TS files only --- .eslintrc.json | 4 ++-- .storybook/setup.ts | 11 +++++++++-- .../{BasicScene.stories.tsx => BasicScene.stories.ts} | 8 ++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) rename .storybook/stories/{BasicScene.stories.tsx => BasicScene.stories.ts} (92%) diff --git a/.eslintrc.json b/.eslintrc.json index 2dec70fe..ecfaa349 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -36,7 +36,6 @@ "import/namespace": "off", "import/default": "off", "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/explicit-member-accessibility": ["error", { "overrides": { "constructors": "no-public" } }], "no-unused-vars": ["off"], "no-var": "error", "react/jsx-uses-react": "error", @@ -73,7 +72,8 @@ // enable the rule specifically for TypeScript files "files": ["*.ts", "*.tsx"], "rules": { - "@typescript-eslint/explicit-function-return-type": ["error", { "allowHigherOrderFunctions": true }] + "@typescript-eslint/explicit-function-return-type": ["error", { "allowHigherOrderFunctions": true }], + "@typescript-eslint/explicit-member-accessibility": ["error", { "overrides": { "constructors": "no-public" } }] } } ] diff --git a/.storybook/setup.ts b/.storybook/setup.ts index e14f7d7f..3a6f5000 100644 --- a/.storybook/setup.ts +++ b/.storybook/setup.ts @@ -1,4 +1,6 @@ import { Camera, Scene, PerspectiveCamera, WebGLRenderer, Clock } from 'three' +//@ts-ignore +import { OrbitControls } from '../src' interface useThreeReturn { camera: Camera @@ -42,9 +44,10 @@ export const useThree = ({ useFrame }: useThreeProps = {}): useThreeReturn => { const clock = new Clock() - function animate() { - requestAnimationFrame(animate) + const controls = new OrbitControls(camera, container) + controls.enableDamping = true + function animate() { if (useFrame) { useFrame( { @@ -54,7 +57,11 @@ export const useThree = ({ useFrame }: useThreeProps = {}): useThreeReturn => { ) } + controls.update() + render() + + requestAnimationFrame(animate) } function render() { diff --git a/.storybook/stories/BasicScene.stories.tsx b/.storybook/stories/BasicScene.stories.ts similarity index 92% rename from .storybook/stories/BasicScene.stories.tsx rename to .storybook/stories/BasicScene.stories.ts index 102bc1ff..087bce8f 100644 --- a/.storybook/stories/BasicScene.stories.tsx +++ b/.storybook/stories/BasicScene.stories.ts @@ -31,7 +31,7 @@ export const Default = () => { const spotLight = new SpotLight('white', 2, 35, Math.PI / 4, 2, 3.5) spotLight.position.set(-3, 6, -4) - const { scene } = useThree({ + const { scene, renderer } = useThree({ useFrame: (_, delta) => { mesh.rotation.x += delta mesh.rotation.y += delta @@ -40,7 +40,11 @@ export const Default = () => { scene.background = new Color(0x0000ff).convertSRGBToLinear() scene.add(ambientLight, directionalLight, pointLight1, pointLight2, spotLight, mesh) - }) + + return () => { + renderer.dispose() + } + }, []) return '' }