From 7b39d4feaac1c97bdbe99411401e598d2d72c46e Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Fri, 4 Aug 2023 13:01:16 +0200 Subject: [PATCH] force reconfigure if called by user --- theatre/core/src/sheets/TheatreSheet.ts | 26 ++++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/theatre/core/src/sheets/TheatreSheet.ts b/theatre/core/src/sheets/TheatreSheet.ts index 09ac383..79fb5c3 100644 --- a/theatre/core/src/sheets/TheatreSheet.ts +++ b/theatre/core/src/sheets/TheatreSheet.ts @@ -166,20 +166,18 @@ export default class TheatreSheet implements ISheet { if (process.env.NODE_ENV !== 'production') { const prevConfig = weakMapOfUnsanitizedProps.get(existingObject) if (prevConfig) { - if (!deepEqual(config, prevConfig)) { - if (opts?.reconfigure === true) { - const sanitizedConfig = compound(config) - existingObject.template.reconfigure(sanitizedConfig) - weakMapOfUnsanitizedProps.set(existingObject, config) - return existingObject.publicApi as $IntentionalAny - } else { - throw new Error( - `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` + - `You can fix this by either re-using the existing object, or calling sheet.object("${key}", config) with the same config.\n\n` + - `If you mean to reconfigure the object's config, set \`{reconfigure: true}\` in sheet.object("${key}", config, {reconfigure: true})`, - ) - } + if (opts?.reconfigure === true) { + const sanitizedConfig = compound(config) + existingObject.template.reconfigure(sanitizedConfig) + weakMapOfUnsanitizedProps.set(existingObject, config) + return existingObject.publicApi as $IntentionalAny + } else if (!deepEqual(config, prevConfig)) { + throw new Error( + `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` + + `You can fix this by either re-using the existing object, or calling sheet.object("${key}", config) with the same config.\n\n` + + `If you mean to reconfigure the object's config, set \`{reconfigure: true}\` in sheet.object("${key}", config, {reconfigure: true})`, + ) } } }