Allowed re-calling sheet.object() with shorthand props again
This commit is contained in:
parent
b5e994f597
commit
713c6cacd7
1 changed files with 19 additions and 8 deletions
|
@ -13,6 +13,7 @@ import type {$IntentionalAny} from '@theatre/shared/utils/types'
|
||||||
import userReadableTypeOfValue from '@theatre/shared/utils/userReadableTypeOfValue'
|
import userReadableTypeOfValue from '@theatre/shared/utils/userReadableTypeOfValue'
|
||||||
import deepEqual from 'fast-deep-equal'
|
import deepEqual from 'fast-deep-equal'
|
||||||
import type {IShorthandCompoundProps} from '@theatre/core/propTypes/internals'
|
import type {IShorthandCompoundProps} from '@theatre/core/propTypes/internals'
|
||||||
|
import type SheetObject from '@theatre/core/sheetObjects/SheetObject'
|
||||||
|
|
||||||
export type SheetObjectConfig<
|
export type SheetObjectConfig<
|
||||||
Props extends PropTypeConfig_Compound<$IntentionalAny>,
|
Props extends PropTypeConfig_Compound<$IntentionalAny>,
|
||||||
|
@ -31,7 +32,10 @@ export interface ISheet {
|
||||||
readonly sequence: ISequence
|
readonly sequence: ISequence
|
||||||
}
|
}
|
||||||
|
|
||||||
const weakMapOfUnsanitizedProps = new WeakMap()
|
const weakMapOfUnsanitizedProps = new WeakMap<
|
||||||
|
SheetObject,
|
||||||
|
IShorthandCompoundProps
|
||||||
|
>()
|
||||||
|
|
||||||
export default class TheatreSheet implements ISheet {
|
export default class TheatreSheet implements ISheet {
|
||||||
get type(): 'Theatre_Sheet_PublicAPI' {
|
get type(): 'Theatre_Sheet_PublicAPI' {
|
||||||
|
@ -60,7 +64,9 @@ export default class TheatreSheet implements ISheet {
|
||||||
|
|
||||||
if (existingObject) {
|
if (existingObject) {
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
if (!deepEqual(config, existingObject.template.config)) {
|
const prevConfig = weakMapOfUnsanitizedProps.get(existingObject)
|
||||||
|
if (prevConfig) {
|
||||||
|
if (!deepEqual(config, prevConfig)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`You seem to have called sheet.object("${key}", config) twice, with different values for \`config\`. ` +
|
`You seem to have called sheet.object("${key}", config) twice, with different values for \`config\`. ` +
|
||||||
`This is disallowed because changing the config of an object on the fly would make it difficult to reason about.\n\n` +
|
`This is disallowed because changing the config of an object on the fly would make it difficult to reason about.\n\n` +
|
||||||
|
@ -68,14 +74,19 @@ export default class TheatreSheet implements ISheet {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return existingObject.publicApi as $IntentionalAny
|
return existingObject.publicApi as $IntentionalAny
|
||||||
} else {
|
} else {
|
||||||
|
const sanitizedConfig = compound(config)
|
||||||
const object = internal.createObject(
|
const object = internal.createObject(
|
||||||
sanitizedPath,
|
sanitizedPath,
|
||||||
nativeObject,
|
nativeObject,
|
||||||
compound(config),
|
sanitizedConfig,
|
||||||
)
|
)
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
weakMapOfUnsanitizedProps.set(object, config)
|
||||||
|
}
|
||||||
return object.publicApi as $IntentionalAny
|
return object.publicApi as $IntentionalAny
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue