From d416da5a2fa3973b0a69ca0c0a8706fcd0cf843a Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Tue, 29 Jun 2021 15:39:47 +0200 Subject: [PATCH] Chore: Small refactor of r3f's store --- packages/playground/src/r3f/App.tsx | 4 +-- packages/plugin-r3f/src/index.tsx | 2 +- packages/plugin-r3f/src/store.ts | 40 ++++++++++++----------------- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/packages/playground/src/r3f/App.tsx b/packages/playground/src/r3f/App.tsx index 4c15347..bdb19b6 100644 --- a/packages/playground/src/r3f/App.tsx +++ b/packages/playground/src/r3f/App.tsx @@ -1,4 +1,4 @@ -import {editable as e, configure} from '@theatre/plugin-r3f' +import {editable as e, bindToCanvas} from '@theatre/plugin-r3f' import {PerspectiveCamera} from '@react-three/drei' import {getProject} from '@theatre/core' import * as THREE from 'three' @@ -11,8 +11,6 @@ import type {$FixMe} from '../../../plugin-r3f/src/types' const ECamera = e(PerspectiveCamera, 'perspectiveCamera') -const bindToCanvas = configure({}) - // Soft shadows are expensive, comment and refresh when it's too slow softShadows() diff --git a/packages/plugin-r3f/src/index.tsx b/packages/plugin-r3f/src/index.tsx index bf288f8..05ca203 100644 --- a/packages/plugin-r3f/src/index.tsx +++ b/packages/plugin-r3f/src/index.tsx @@ -6,7 +6,7 @@ export {default as EditorHelper} from './components/EditorHelper' export type {EditorHelperProps} from './components/EditorHelper' export {default as editable} from './components/editable' -export {configure} from './store' +export {bindToCanvas} from './store' export type {EditableState, BindFunction} from './store' if (process.env.NODE_ENV === 'development') { diff --git a/packages/plugin-r3f/src/store.ts b/packages/plugin-r3f/src/store.ts index 8f486fe..a25beb5 100644 --- a/packages/plugin-r3f/src/store.ts +++ b/packages/plugin-r3f/src/store.ts @@ -208,12 +208,6 @@ export type EditorStore = { ) => void } -interface PersistedState { - canvases: { - [name: string]: EditableState - } -} - const config: StateCreator = (set, get) => { setTimeout(() => { const existingHandler = DefaultLoadingManager.onProgress @@ -408,23 +402,21 @@ export type BindFunction = (options: { sheet: ISheet }) => (options: {gl: WebGLRenderer; scene: Scene}) => void -export const configure = ({} = {}): BindFunction => { - return ({ - allowImplicitInstancing = false, - state, - editorCamera = {}, - sheet, - }) => { - return ({gl, scene}) => { - const init = useEditorStore.getState().init - init( - scene, - gl, - allowImplicitInstancing, - {...{position: [20, 20, 20]}, ...editorCamera}, - sheet, - state, - ) - } +export const bindToCanvas: BindFunction = ({ + allowImplicitInstancing = false, + state, + editorCamera = {}, + sheet, +}) => { + return ({gl, scene}) => { + const init = useEditorStore.getState().init + init( + scene, + gl, + allowImplicitInstancing, + {...{position: [20, 20, 20]}, ...editorCamera}, + sheet, + state, + ) } }