Support the entire getProject config in theatric's initialize() function (#384)
Support the entire getProject config in initialize
This commit is contained in:
parent
aec79bd8c4
commit
8470b67d4b
2 changed files with 8 additions and 8 deletions
|
@ -3,7 +3,7 @@ import {render} from 'react-dom'
|
||||||
import React, {useState} from 'react'
|
import React, {useState} from 'react'
|
||||||
import state from './state.json'
|
import state from './state.json'
|
||||||
|
|
||||||
initialize(state)
|
initialize({state})
|
||||||
|
|
||||||
function SomeComponent({id}: {id: string}) {
|
function SomeComponent({id}: {id: string}) {
|
||||||
const {foo, $get, $set} = useControls(
|
const {foo, $get, $set} = useControls(
|
||||||
|
|
|
@ -31,16 +31,16 @@ const maybeTransaction =
|
||||||
? studio.transaction.bind(studio)
|
? studio.transaction.bind(studio)
|
||||||
: () => {}
|
: () => {}
|
||||||
|
|
||||||
let _state: IProjectConfig['state'] | undefined = undefined
|
let _projectConfig: IProjectConfig['state'] | undefined = undefined
|
||||||
|
|
||||||
export function initialize(state: IProjectConfig['state']) {
|
export function initialize(config: IProjectConfig) {
|
||||||
if (_state !== undefined) {
|
if (_projectConfig !== undefined) {
|
||||||
console.warn(
|
console.warn(
|
||||||
'Theatric has already been initialized, either through another initialize call, or by calling useControls() before calling initialize().',
|
'Theatric has already been initialized, either through another initialize call, or by calling useControls() before calling initialize().',
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_state = state
|
_projectConfig = config
|
||||||
}
|
}
|
||||||
|
|
||||||
const allProps: Record<string, UnknownShorthandCompoundProps[]> = {}
|
const allProps: Record<string, UnknownShorthandCompoundProps[]> = {}
|
||||||
|
@ -81,8 +81,8 @@ export function useControls<Config extends ControlsAndButtons>(
|
||||||
$get: Getter<OmitMatching<Config, {type: 'button'}>>
|
$get: Getter<OmitMatching<Config, {type: 'button'}>>
|
||||||
} {
|
} {
|
||||||
// initialize state to null, if it hasn't been initialized yet
|
// initialize state to null, if it hasn't been initialized yet
|
||||||
if (_state === undefined) {
|
if (_projectConfig === undefined) {
|
||||||
_state = null
|
_projectConfig = null
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -150,7 +150,7 @@ export function useControls<Config extends ControlsAndButtons>(
|
||||||
)
|
)
|
||||||
|
|
||||||
const sheet = useMemo(
|
const sheet = useMemo(
|
||||||
() => getProject('Theatric', {state: _state}).sheet('Panels'),
|
() => getProject('Theatric', _projectConfig ?? undefined).sheet('Panels'),
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
const panel = options.panel ?? 'Default panel'
|
const panel = options.panel ?? 'Default panel'
|
||||||
|
|
Loading…
Reference in a new issue