Simplify project config
This commit is contained in:
parent
c72647c1e5
commit
39a2645d65
27 changed files with 79 additions and 87 deletions
|
@ -14,7 +14,7 @@ export default class CoreBundle {
|
|||
}
|
||||
|
||||
get version() {
|
||||
return $env.version
|
||||
return process.env.version
|
||||
}
|
||||
|
||||
getBitsForStudio(studio: Studio, callback: (bits: CoreBits) => void) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import type {
|
|||
IProjectConfig,
|
||||
} from '@theatre/core/projects/TheatreProject'
|
||||
import TheatreProject from '@theatre/core/projects/TheatreProject'
|
||||
import globals from '@theatre/shared/globals'
|
||||
import * as types from '@theatre/shared/propTypes'
|
||||
import {InvalidArgumentError} from '@theatre/shared/utils/errors'
|
||||
import {validateName} from '@theatre/shared/utils/sanitizers'
|
||||
|
@ -17,13 +18,13 @@ export function getProject(id: string, config: IProjectConfig = {}): IProject {
|
|||
return projectsSingleton.get(id)!.publicApi
|
||||
}
|
||||
|
||||
if ($env.NODE_ENV === 'development') {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
validateName(id, 'projectName in Theatre.getProject(projectName)', true)
|
||||
validateProjectIdOrThrow(id)
|
||||
}
|
||||
|
||||
if (config.state) {
|
||||
if ($env.NODE_ENV === 'development') {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
shallowValidateOnDiskState(id, config.state)
|
||||
} else {
|
||||
deepValidateOnDiskState(id, config.state)
|
||||
|
@ -41,7 +42,7 @@ const shallowValidateOnDiskState = (projectId: string, s: OnDiskState) => {
|
|||
if (
|
||||
Array.isArray(s) ||
|
||||
s == null ||
|
||||
s.definitionVersion !== $env.currentProjectStateDefinitionVersion
|
||||
s.definitionVersion !== globals.currentProjectStateDefinitionVersion
|
||||
) {
|
||||
throw new InvalidArgumentError(
|
||||
`Error validating conf.state in Theatre.getProject(${JSON.stringify(
|
||||
|
|
|
@ -12,6 +12,7 @@ import projectsSingleton from './projectsSingleton'
|
|||
import type {ProjectState} from './store/storeTypes'
|
||||
import type {Deferred} from '@theatre/shared/utils/defer'
|
||||
import {defer} from '@theatre/shared/utils/defer'
|
||||
import globals from '@theatre/shared/globals'
|
||||
|
||||
export type Conf = Partial<{
|
||||
state: OnDiskState
|
||||
|
@ -55,7 +56,7 @@ export default class Project {
|
|||
},
|
||||
historic: config.state ?? {
|
||||
sheetsById: {},
|
||||
definitionVersion: $env.currentProjectStateDefinitionVersion,
|
||||
definitionVersion: globals.currentProjectStateDefinitionVersion,
|
||||
},
|
||||
ephemeral: {
|
||||
loadingState: {
|
||||
|
|
|
@ -52,7 +52,7 @@ export default class TheatreProject implements IProject {
|
|||
'project.sheet',
|
||||
)
|
||||
|
||||
if (!$env.isCore) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
validateName(
|
||||
instanceId,
|
||||
'instanceId in project.sheet(sheetId, instanceId)',
|
||||
|
|
|
@ -3,6 +3,7 @@ import delay from '@theatre/shared/utils/delay'
|
|||
import {original} from 'immer'
|
||||
import type Project from './Project'
|
||||
import type {OnDiskState} from './store/storeTypes'
|
||||
import globals from '@theatre/shared/globals'
|
||||
|
||||
/**
|
||||
* @todo this could be turned into a simple derivation, like:
|
||||
|
@ -40,7 +41,7 @@ export default async function initialiseProjectState(
|
|||
|
||||
drafts.historic.coreByProject[projectId] = {
|
||||
sheetsById: {},
|
||||
definitionVersion: $env.currentProjectStateDefinitionVersion,
|
||||
definitionVersion: globals.currentProjectStateDefinitionVersion,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ export default class Sequence {
|
|||
set position(requestedPosition: number) {
|
||||
let position = requestedPosition
|
||||
this.pause()
|
||||
if (!$env.isCore) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (typeof position !== 'number') {
|
||||
logger.error(
|
||||
`value t in sequence.position = t must be a number. ${typeof position} given`,
|
||||
|
@ -164,7 +164,7 @@ export default class Sequence {
|
|||
end: sequenceDuration,
|
||||
}
|
||||
|
||||
if (!$env.isCore) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (typeof range.start !== 'number' || range.start < 0) {
|
||||
throw new InvalidArgumentError(
|
||||
`Argument conf.range.start in sequence.play(conf) must be a positive number. ${JSON.stringify(
|
||||
|
@ -207,7 +207,7 @@ export default class Sequence {
|
|||
|
||||
const iterationCount =
|
||||
conf && typeof conf.iterationCount === 'number' ? conf.iterationCount : 1
|
||||
if (!$env.isCore) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (
|
||||
!(Number.isInteger(iterationCount) && iterationCount > 0) &&
|
||||
iterationCount !== Infinity
|
||||
|
@ -222,7 +222,7 @@ export default class Sequence {
|
|||
|
||||
const rate = conf && typeof conf.rate !== 'undefined' ? conf.rate : 1
|
||||
|
||||
if (!$env.isCore) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (typeof rate !== 'number' || rate === 0) {
|
||||
throw new InvalidArgumentError(
|
||||
`Argument conf.rate in sequence.play(conf) must be a number larger than 0. ${JSON.stringify(
|
||||
|
@ -242,7 +242,7 @@ export default class Sequence {
|
|||
|
||||
const direction = conf && conf.direction ? conf.direction : 'normal'
|
||||
|
||||
if (!$env.isCore) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (possibleDirections.indexOf(direction) === -1) {
|
||||
throw new InvalidArgumentError(
|
||||
`Argument conf.direction in sequence.play(conf) must be one of ${JSON.stringify(
|
||||
|
|
|
@ -43,7 +43,7 @@ export default class TheatreSequence {
|
|||
if (privateAPI(this)._project.isReady()) {
|
||||
return privateAPI(this).play(conf)
|
||||
} else {
|
||||
if (!$env.isCore) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
logger.warn(
|
||||
`You seem to have called sequence.play() before the project has finished loading.\n` +
|
||||
`This would **not** a problem in production when using '@theatre/core', since Theatre loads instantly in core mode. ` +
|
||||
|
|
|
@ -81,7 +81,7 @@ const pp = (
|
|||
const currentKeyframe = track.keyframes[currentKeyframeIndex]
|
||||
|
||||
if (!currentKeyframe) {
|
||||
if ($env.NODE_ENV === 'development') {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
logger.error(`Bug here`)
|
||||
}
|
||||
return states.error
|
||||
|
@ -93,7 +93,7 @@ const pp = (
|
|||
if (currentKeyframeIndex === 0) {
|
||||
return states.beforeFirstKeyframe(currentKeyframe)
|
||||
} else {
|
||||
if ($env.NODE_ENV === 'development') {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
logger.error(`Bug here`)
|
||||
}
|
||||
return states.error
|
||||
|
|
|
@ -180,7 +180,7 @@ export default class SheetObjectTemplate {
|
|||
* Not available in core.
|
||||
*/
|
||||
getMapOfValidSequenceTracks_forStudio(): IDerivation<IPropPathToTrackIdTree> {
|
||||
if (!$env.isCore) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
return this._cache.get('getMapOfValidSequenceTracks_forStudio', () =>
|
||||
this.getArrayOfValidSequenceTracks().map((arr) => {
|
||||
let map = {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue