, DataContainer>();
+ storeObj = { store };
+ globalObject[GLOBAL_KEY] = storeObj;
+ }
+ return storeObj.store;
+}
+
+const store = getStore();
+
export function attachComponentData(
component: ComponentType
,
type: string,
@@ -37,9 +56,11 @@ export function attachComponentData
(
) {
const dataComponent = component as ComponentWithData
;
- let container = dataComponent[DATA_KEY];
+ let container = store.get(component) || dataComponent[DATA_KEY];
if (!container) {
- container = dataComponent[DATA_KEY] = { map: new Map() };
+ container = { map: new Map() };
+ store.set(component, container);
+ dataComponent[DATA_KEY] = container;
}
if (container.map.has(type)) {
@@ -60,7 +81,12 @@ export function getComponentData(
return undefined;
}
- const container = (node as ReactNodeWithData).type?.[DATA_KEY];
+ const component = (node as MaybeComponentNode).type;
+ if (!component) {
+ return undefined;
+ }
+
+ const container = store.get(component) || component[DATA_KEY];
if (!container) {
return undefined;
}
diff --git a/packages/core-api/src/lib/globalObject.ts b/packages/core-api/src/lib/globalObject.ts
new file mode 100644
index 0000000000..85f16212fe
--- /dev/null
+++ b/packages/core-api/src/lib/globalObject.ts
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2021 Spotify AB
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
+function getGlobal() {
+ if (typeof window !== 'undefined' && window.Math === Math) {
+ return window;
+ }
+ if (typeof self !== 'undefined' && self.Math === Math) {
+ return self;
+ }
+ // eslint-disable-next-line no-new-func
+ return Function('return this')();
+}
+
+export const globalObject = getGlobal();