Created
October 28, 2021 07:05
-
-
Save zonzujiro/5988ce2d8cb3659b68d52a8b191a7120 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: packages/thunderbolt-becky/src/carmi/apis/thunderboltAPIs.carmi.ts | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/packages/thunderbolt-becky/src/carmi/apis/thunderboltAPIs.carmi.ts b/packages/thunderbolt-becky/src/carmi/apis/thunderboltAPIs.carmi.ts | |
--- a/packages/thunderbolt-becky/src/carmi/apis/thunderboltAPIs.carmi.ts (revision 80c27a686047e4655cac96f455607917f77ade6c) | |
+++ b/packages/thunderbolt-becky/src/carmi/apis/thunderboltAPIs.carmi.ts (date 1635402526543) | |
@@ -6,6 +6,7 @@ | |
getNicknameToCompIdMap, | |
hasPlatformOnPage, | |
hasTPAComponentOnPage, | |
+ connections, | |
} from './platformApi.carmi' | |
import * as meshApi from './meshApi.carmi' | |
import * as sospApi from './sospApi.carmi' | |
@@ -19,6 +20,7 @@ | |
getComponentPublicData, | |
getNicknameToCompIdMap, | |
hasTPAComponentOnPage, | |
+ connections, | |
} | |
export { | |
Index: packages/thunderbolt-becky/src/carmi/apis/platformApi.carmi.ts | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/packages/thunderbolt-becky/src/carmi/apis/platformApi.carmi.ts b/packages/thunderbolt-becky/src/carmi/apis/platformApi.carmi.ts | |
--- a/packages/thunderbolt-becky/src/carmi/apis/platformApi.carmi.ts (revision 80c27a686047e4655cac96f455607917f77ade6c) | |
+++ b/packages/thunderbolt-becky/src/carmi/apis/platformApi.carmi.ts (date 1635402703704) | |
@@ -1,11 +1,17 @@ | |
import type { Carmi, Component } from '../../types' | |
import { and, call, chain, or, root, template } from '../root.carmi' | |
-import { isWixCodeOnPage, isWixCodeOnSite, hasTPAWorkerOnSite, pageCompId } from '../beckyModel.carmi' | |
+import { | |
+ isWixCodeOnPage, | |
+ isWixCodeOnSite, | |
+ hasTPAWorkerOnSite, | |
+ pageCompId, | |
+ dataQueryToCompIdMap, | |
+} from '../beckyModel.carmi' | |
import { repeaterApis, structure } from '../thunderbolt.carmi' | |
-import { documentData } from '../data.carmi' | |
+import { connectionsData, documentData } from '../data.carmi' | |
import { getAppStyleProperties } from '@wix/thunderbolt-components' | |
import type { ControllerDataItem } from '@wix/thunderbolt-symbols' | |
-import { MASTER_PAGE_ID, TPA_GALLERIES } from '@wix/thunderbolt-becky-types' | |
+import { ControllerConnectionItem, MASTER_PAGE_ID, TPA_GALLERIES } from '@wix/thunderbolt-becky-types' | |
import { createComponentsApi } from './createComponentsApi.carmi' | |
import { isCompMigratingToOoi } from './envApi.carmi' | |
@@ -185,3 +191,59 @@ | |
.filterBy((comp, id) => componentsApi.getCompNickname(id)) | |
.mapKeys((comp, id) => componentsApi.getCompNickname(id)) | |
.mapValues((compStructure) => compStructure.get('id')) | |
+ | |
+export const componentsConnectionQueries: Carmi< | |
+ Record<string, string> | |
+> = componentsApi | |
+ .getComponentsByPredicate((comp, compId) => and(comp.get('connectionQuery'), call('getFullId', compId).eq(compId))) | |
+ .mapValues('connectionQuery') | |
+ | |
+export const connectionItemsMap = connectionsData | |
+ .mapValues((dataItem) => dataItem.get('items')) | |
+ .filterBy((x) => x.size()) | |
+ .mapValues((dataItem) => | |
+ dataItem.map((item) => | |
+ item.assignIn([ | |
+ { | |
+ controllerCompId: item | |
+ .get('type') | |
+ .eq('WixCodeConnectionItem') | |
+ // @ts-ignore | |
+ .ternary('wixCode', dataQueryToCompIdMap.get(item.get('controllerId'))), | |
+ }, | |
+ ]) | |
+ ) | |
+ ) | |
+ | |
+export const connections = componentsConnectionQueries // component connections query | |
+ .mapValues((connectionQuery, compId) => { | |
+ const connectionList = connectionItemsMap.get(connectionQuery) | |
+ return connectionList.ternary( | |
+ connectionList.map((item, index, compIdContext) => item.assignIn([{ compId: compIdContext }]), compId), | |
+ null | |
+ ) | |
+ }) // get component connection from connectionData | |
+ .filterBy((v) => v) // filter out components without connections data | |
+ .values() // to object | |
+ .flatten() // flatten | |
+ .keyBy((connection, index) => index) // turn into an object keyed by index in order to use the groupBy() method | |
+ .groupBy((connection) => connection.get('controllerCompId')) // group by controllerCompId | |
+ .mapValues( | |
+ (controllerConnections) => | |
+ controllerConnections | |
+ .groupBy((connection) => connection.get('role')) | |
+ .mapValues((connectionsWithSameRole) => | |
+ connectionsWithSameRole | |
+ .values() // remove the grouping by index hack done a couple of lines above | |
+ .map((connection) => | |
+ chain({ | |
+ compId: connection.get('compId'), | |
+ role: connection.get('role'), | |
+ config: call( | |
+ 'parseJSON', | |
+ ((connection as any) as Carmi<ControllerConnectionItem>).get('config') | |
+ ), | |
+ }) | |
+ ) | |
+ ) // pick specific fields | |
+ ) | |
Index: packages/thunderbolt-becky/src/carmi/platformModel.carmi.ts | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/packages/thunderbolt-becky/src/carmi/platformModel.carmi.ts b/packages/thunderbolt-becky/src/carmi/platformModel.carmi.ts | |
--- a/packages/thunderbolt-becky/src/carmi/platformModel.carmi.ts (revision 80c27a686047e4655cac96f455607917f77ade6c) | |
+++ b/packages/thunderbolt-becky/src/carmi/platformModel.carmi.ts (date 1635402723789) | |
@@ -2,14 +2,20 @@ | |
import { propsExtensions, sdkDataExtensions } from '@wix/thunderbolt-components' | |
import type { Carmi, ComponentSdkDataMapper, ThunderboltMapperAPIs } from '../types' | |
import { resolveComponentExtensions } from './componentsResolver.carmi' | |
-import { allControllers, applications, controllers, hasTPAComponentOnPage } from './apis/platformApi.carmi' | |
+import { | |
+ allControllers, | |
+ applications, | |
+ controllers, | |
+ hasTPAComponentOnPage, | |
+ connectionItemsMap, | |
+ componentsConnectionQueries, | |
+ connections, | |
+} from './apis/platformApi.carmi' | |
import { isInSosp, pagesToShowSosp } from './apis/sospApi.carmi' | |
-import { connectionsData } from './data.carmi' | |
import { nativePropsExtensions, nativeSdkDataExtensions } from './nativeExtensions.carmi' | |
-import { dataQueryToCompIdMap, originalStructure } from './beckyModel.carmi' | |
+import { originalStructure } from './beckyModel.carmi' | |
import { getGhosts, getAppWidgetGhosts } from './ghostsUtils.carmi' | |
import { and, call, chain, or } from './root.carmi' | |
-import type { ControllerConnectionItem } from '@wix/thunderbolt-becky-types' | |
import { createComponentsApi } from './apis/createComponentsApi.carmi' | |
export const createPlatformModel = (apis: ThunderboltMapperAPIs) => { | |
@@ -19,22 +25,6 @@ | |
...apis, | |
componentsApi: createComponentsApi(ghostsStructure), | |
}) | |
- const connectionItemsMap = connectionsData | |
- .mapValues((dataItem) => dataItem.get('items')) | |
- .filterBy((x) => x.size()) | |
- .mapValues((dataItem) => | |
- dataItem.map((item) => | |
- item.assignIn([ | |
- { | |
- controllerCompId: item | |
- .get('type') | |
- .eq('WixCodeConnectionItem') | |
- // @ts-ignore | |
- .ternary('wixCode', dataQueryToCompIdMap.get(item.get('controllerId'))), | |
- }, | |
- ]) | |
- ) | |
- ) | |
const ghostComponentsParentUpdates = getAppWidgetGhosts(componentsApi) | |
.keys() | |
@@ -42,47 +32,6 @@ | |
.keyBy('id') | |
.mapValues('components') | |
- const componentsConnectionQueries: Carmi< | |
- Record<string, string> | |
- > = componentsApi | |
- .getComponentsByPredicate((comp, compId) => | |
- and(comp.get('connectionQuery'), call('getFullId', compId).eq(compId)) | |
- ) | |
- .mapValues('connectionQuery') | |
- | |
- const connections = componentsConnectionQueries // component connections query | |
- .mapValues((connectionQuery, compId) => { | |
- const connectionList = connectionItemsMap.get(connectionQuery) | |
- return connectionList.ternary( | |
- connectionList.map((item, index, compIdContext) => item.assignIn([{ compId: compIdContext }]), compId), | |
- null | |
- ) | |
- }) // get component connection from connectionData | |
- .filterBy((v) => v) // filter out components without connections data | |
- .values() // to object | |
- .flatten() // flatten | |
- .keyBy((connection, index) => index) // turn into an object keyed by index in order to use the groupBy() method | |
- .groupBy((connection) => connection.get('controllerCompId')) // group by controllerCompId | |
- .mapValues( | |
- (controllerConnections) => | |
- controllerConnections | |
- .groupBy((connection) => connection.get('role')) | |
- .mapValues((connectionsWithSameRole) => | |
- connectionsWithSameRole | |
- .values() // remove the grouping by index hack done a couple of lines above | |
- .map((connection) => | |
- chain({ | |
- compId: connection.get('compId'), | |
- role: connection.get('role'), | |
- config: call( | |
- 'parseJSON', | |
- ((connection as any) as Carmi<ControllerConnectionItem>).get('config') | |
- ), | |
- }) | |
- ) | |
- ) // pick specific fields | |
- ) | |
- | |
const compIdConnections = componentsConnectionQueries.mapValues((connectionQuery) => | |
or(connectionItemsMap.get(connectionQuery), []).keyBy((item) => item.get('controllerCompId')) | |
) | |
Index: packages/feature-test-api/src/types.ts | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/packages/feature-test-api/src/types.ts b/packages/feature-test-api/src/types.ts | |
--- a/packages/feature-test-api/src/types.ts (revision 80c27a686047e4655cac96f455607917f77ade6c) | |
+++ b/packages/feature-test-api/src/types.ts (date 1635402749981) | |
@@ -15,5 +15,5 @@ | |
} | |
export type TestApiPageConfig = { | |
- compIdToNickname: Record<string, string> | |
+ connections: Record<string, string> // fix | |
} | |
Index: packages/feature-test-api/src/testApi.ts | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/packages/feature-test-api/src/testApi.ts b/packages/feature-test-api/src/testApi.ts | |
--- a/packages/feature-test-api/src/testApi.ts (revision 80c27a686047e4655cac96f455607917f77ade6c) | |
+++ b/packages/feature-test-api/src/testApi.ts (date 1635402438309) | |
@@ -28,22 +28,54 @@ | |
return | |
} | |
- const compIdToNickname = { ...pageConfig.compIdToNickname, ...masterPageConfig.compIdToNickname } | |
+ /* connections = { | |
+ wixCode: { | |
+ button1: [ | |
+ { | |
+ compId: 'comp-k84uhgin', | |
+ role: 'button1', | |
+ }, | |
+ ], | |
+ dataset1: [ | |
+ { | |
+ compId: 'comp-k84ulkxt', | |
+ role: 'dataset1', | |
+ }, | |
+ ], | |
+ page1: [ | |
+ { | |
+ compId: 'c1dmp', | |
+ role: 'page1', | |
+ }, | |
+ ], | |
+ }, | |
+ }*/ | |
+ const connections = { ...pageConfig.connections, ...masterPageConfig.connections } | |
+ | |
+ // testApi.getCompIdByRole('widget1', 'button1') | |
+ const getCompIdByRole = (controllerNickname: string, innerRole: string) => { | |
+ const compId = connections[controllerNickname]?.[innerRole]?.[0]?.compId | |
+ if (compId) { | |
+ return compId | |
+ } | |
+ throw new Error(`No component with nickname: ${nickname}`) | |
+ } | |
+ | |
window.testApi = { | |
domSelectors: { | |
getCompNicknameById: (compId: string) => { | |
- if (compIdToNickname[compId]) { | |
- return compIdToNickname[compId] | |
+ // const controllerId = | |
+ // controllerNickname === 'wixCode' ? 'wixCode' : connections.wixCode?.controllerNickname?.[0].compId | |
+ const id = connections.wixCode.bla.bla | |
+ if (id) { | |
+ return id | |
} | |
throw new Error(`No component with id: ${compId}`) | |
}, | |
getCompIdByNickname: (nickname: string) => { | |
- const compId = findKey(compIdToNickname, (nm) => nickname === nm) | |
- if (compId) { | |
- return compId | |
- } | |
- throw new Error(`No component with nickname: ${nickname}`) | |
+ return getCompIdByRole('wixCode', nickname) | |
}, | |
+ getCompIdByRole, | |
getElementsByCompTypeAndProps: (container: HTMLElement, componentType: string, props: object) => { | |
const compProps = chain(structureStore.getEntireStore()) | |
.pickBy((comp) => comp.componentType.toLowerCase() === componentType.toLowerCase()) | |
Index: packages/feature-test-api/src/carmi/testApiPageConfig.carmi.ts | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/packages/feature-test-api/src/carmi/testApiPageConfig.carmi.ts b/packages/feature-test-api/src/carmi/testApiPageConfig.carmi.ts | |
--- a/packages/feature-test-api/src/carmi/testApiPageConfig.carmi.ts (revision 80c27a686047e4655cac96f455607917f77ade6c) | |
+++ b/packages/feature-test-api/src/carmi/testApiPageConfig.carmi.ts (date 1635402740089) | |
@@ -3,7 +3,7 @@ | |
import { TestApiPageConfig } from '../types' | |
export const page: PageFeatureConfigProvider<TestApiPageConfig, TestApiPageConfig> = ({ | |
- componentsApi, | |
+ platformApi, | |
envApi, | |
pageApi, | |
}) => { | |
@@ -11,12 +11,7 @@ | |
const pageId = pageApi.getRequestedPageId() | |
const isMasterPage = pageId.eq('masterPage') | |
- const compIdToNickname = componentsApi | |
- .getComponentsByPredicate(() => true) | |
- .mapValues((comp, compId) => componentsApi.getCompNickname(compId)) | |
- .filterBy((x) => x) | |
- | |
- const pageConfig = chain({ compIdToNickname }) | |
+ const pageConfig = chain({ connections: platformApi.connections }) | |
const siteConfig = isQaMode.ternary(pageConfig, null) | |
const shouldLoadPageFeature = and(isQaMode, isMasterPage.not()) | |
Index: packages/feature-tpa/src/index.ts | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/packages/feature-tpa/src/index.ts b/packages/feature-tpa/src/index.ts | |
--- a/packages/feature-tpa/src/index.ts (revision 80c27a686047e4655cac96f455607917f77ade6c) | |
+++ b/packages/feature-tpa/src/index.ts (date 1635397113154) | |
@@ -60,6 +60,13 @@ | |
bind(LifeCycle.PageWillMountHandler).to(tpaCommonConfigUpdater) | |
bind(UrlChangeHandlerForPage).to(TpaStateManager) | |
bind(UrlChangeHandlerForPage).to(TpaCurrentCurrencyManager) | |
+ _.map(lazyConfig, (methods, symbol) => { | |
+ bind(symbol).to( | |
+ withDependencies([], () => { | |
+ // some kind of proxy which loads the feature if any method from "methods" is invoked | |
+ }) | |
+ ) | |
+ }) | |
} | |
export type { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment