From be02218d3d6c6dce330bd27b81933a2b890aab2f Mon Sep 17 00:00:00 2001 From: Alex Iglesias Date: Mon, 15 Nov 2021 12:12:30 +0100 Subject: [PATCH] `restartWebflow`: Preserved `ix2` state after re-initting the module. --- package.json | 2 +- types/Webflow.ts | 49 ++++++++++++++++++++++++++++++++------- webflow/restartWebflow.ts | 8 ++++++- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index e91239b..8c09a7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@finsweet/ts-utils", - "version": "0.24.2", + "version": "0.24.3", "description": "Typescript utils for custom Webflow projects.", "main": "index.ts", "module": "index.ts", diff --git a/types/Webflow.ts b/types/Webflow.ts index d4b2627..3dae7e8 100644 --- a/types/Webflow.ts +++ b/types/Webflow.ts @@ -5,6 +5,46 @@ type Callback = () => unknown; export type WebflowModule = 'ix2' | 'commerce' | 'lottie' | 'lightbox'; +interface WebflowCommerce { + destroy: () => void; + init: (params: { siteId: string; apiUrl: string }) => void; +} + +interface WebflowIx2 { + destroy: () => void; + init: () => void; + actions: { + [key: string]: (...params: unknown[]) => unknown; + }; + store: { + dispatch: (param: unknown) => void; + getState: () => { + ixData: { + actionLists: unknown; + eventTypeMap: unknown; + events: unknown; + mediaQueries: unknown; + mediaQueryKeys: unknown; + }; + ixElements: { + [key: string]: unknown; + }; + ixInstances: { + [key: string]: unknown; + }; + ixRequest: { + [key: string]: unknown; + }; + ixSession: { + eventState: { + [key: string]: unknown; + }; + [key: string]: unknown; + }; + }; + }; +} + /** * Includes methods of the Webflow.js object */ @@ -12,14 +52,7 @@ export interface Webflow extends Pick { destroy: () => void; ready: () => void; env: () => boolean; - require: ( - key: Key - ) => - | { - destroy: () => void; - init: Key extends 'commerce' ? (params: { siteId: string; apiUrl: string }) => void : () => void; - } - | undefined; + require: (key: Key) => (Key extends 'commerce' ? WebflowCommerce : WebflowIx2) | undefined; } /** diff --git a/webflow/restartWebflow.ts b/webflow/restartWebflow.ts index 88b43e6..cdbbfd9 100644 --- a/webflow/restartWebflow.ts +++ b/webflow/restartWebflow.ts @@ -26,8 +26,14 @@ export const restartWebflow = async (modules?: WebflowModule[]): Promise