Chore: Small refactor of r3f's store

This commit is contained in:
Aria Minaei 2021-06-29 15:39:47 +02:00
parent 94261107fb
commit d416da5a2f
3 changed files with 18 additions and 28 deletions

View file

@ -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 {PerspectiveCamera} from '@react-three/drei'
import {getProject} from '@theatre/core' import {getProject} from '@theatre/core'
import * as THREE from 'three' import * as THREE from 'three'
@ -11,8 +11,6 @@ import type {$FixMe} from '../../../plugin-r3f/src/types'
const ECamera = e(PerspectiveCamera, 'perspectiveCamera') const ECamera = e(PerspectiveCamera, 'perspectiveCamera')
const bindToCanvas = configure({})
// Soft shadows are expensive, comment and refresh when it's too slow // Soft shadows are expensive, comment and refresh when it's too slow
softShadows() softShadows()

View file

@ -6,7 +6,7 @@ export {default as EditorHelper} from './components/EditorHelper'
export type {EditorHelperProps} from './components/EditorHelper' export type {EditorHelperProps} from './components/EditorHelper'
export {default as editable} from './components/editable' export {default as editable} from './components/editable'
export {configure} from './store' export {bindToCanvas} from './store'
export type {EditableState, BindFunction} from './store' export type {EditableState, BindFunction} from './store'
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {

View file

@ -208,12 +208,6 @@ export type EditorStore = {
) => void ) => void
} }
interface PersistedState {
canvases: {
[name: string]: EditableState
}
}
const config: StateCreator<EditorStore> = (set, get) => { const config: StateCreator<EditorStore> = (set, get) => {
setTimeout(() => { setTimeout(() => {
const existingHandler = DefaultLoadingManager.onProgress const existingHandler = DefaultLoadingManager.onProgress
@ -408,13 +402,12 @@ export type BindFunction = (options: {
sheet: ISheet sheet: ISheet
}) => (options: {gl: WebGLRenderer; scene: Scene}) => void }) => (options: {gl: WebGLRenderer; scene: Scene}) => void
export const configure = ({} = {}): BindFunction => { export const bindToCanvas: BindFunction = ({
return ({
allowImplicitInstancing = false, allowImplicitInstancing = false,
state, state,
editorCamera = {}, editorCamera = {},
sheet, sheet,
}) => { }) => {
return ({gl, scene}) => { return ({gl, scene}) => {
const init = useEditorStore.getState().init const init = useEditorStore.getState().init
init( init(
@ -426,5 +419,4 @@ export const configure = ({} = {}): BindFunction => {
state, state,
) )
} }
}
} }