From 7d09556e4cd3f40e1f3cf459f378d07157e684f1 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sat, 9 Apr 2022 02:53:44 +0200 Subject: [PATCH] [Dev] TeactN: Assert when setting global asynchronously (follow-up) --- src/global/init.ts | 7 ++----- src/lib/teact/teactn.tsx | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/global/init.ts b/src/global/init.ts index d717295c..cad5c209 100644 --- a/src/global/init.ts +++ b/src/global/init.ts @@ -6,10 +6,7 @@ import { cloneDeep } from '../util/iteratees'; initCache(); -addActionHandler('init', (global) => { +addActionHandler('init', () => { const initial = cloneDeep(INITIAL_STATE); - return { - ...global, - ...(loadCache(initial) || initial), - }; + return loadCache(initial) || initial; }); diff --git a/src/lib/teact/teactn.tsx b/src/lib/teact/teactn.tsx index b2c976a8..5fbd6202 100644 --- a/src/lib/teact/teactn.tsx +++ b/src/lib/teact/teactn.tsx @@ -71,7 +71,7 @@ function runCallbacks(forceOnHeavyAnimation = false) { export function setGlobal(newGlobal?: GlobalState, options?: ActionOptions) { if (typeof newGlobal === 'object' && newGlobal !== currentGlobal) { if (DEBUG) { - if (newGlobal.DEBUG_id !== DEBUG_currentGlobalId) { + if (newGlobal.DEBUG_id && newGlobal.DEBUG_id !== DEBUG_currentGlobalId) { throw new Error('[TeactN.setGlobal] Attempt to set an outdated global'); } }