Skip to content

Commit 7da2fb7

Browse files
author
zhengyanan18
committed
feat: 京东小程序transform渲染模式相关的taro侧改动
1 parent 786c0bb commit 7da2fb7

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

packages/taro-platform-jd/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export default (ctx: IPluginContext) => {
1313
useConfigName: 'mini',
1414
async fn ({ config }) {
1515
const program = new JD(ctx, config)
16+
if (config.useTransformRender) {
17+
process.env.JD_RENDER_TYPE = 'transform'
18+
}
1619
await program.start()
1720
}
1821
})

packages/taro-platform-jd/src/program.ts

+10
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,14 @@ export default class JD extends TaroPlatformBase {
4343
modifyTemplate () {
4444
this.template.mergeComponents(this.ctx, components)
4545
}
46+
47+
/**
48+
* 获取jd平台特殊的需要注入env的配置
49+
* @returns
50+
*/
51+
getTargetPlatformOptions() {
52+
return {
53+
JD_RENDER_TYPE: JSON.stringify(process.env.JD_RENDER_TYPE || ''),
54+
}
55+
}
4656
}

packages/taro-react/src/props.ts

+4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ function setEvent (dom: TaroElement, name: string, value: unknown, oldValue?: un
131131
dom.addEventListener(eventName, value, process.env.TARO_PLATFORM !== PLATFORM_TYPE.HARMONY ? { isCapture, sideEffect: false } : undefined)
132132
} else {
133133
dom.addEventListener(eventName, value, process.env.TARO_PLATFORM !== PLATFORM_TYPE.HARMONY ? isCapture : undefined)
134+
// 京东小程序transform模式: 把事件绑定写到data里
135+
if (process.env.JD_RENDER_TYPE === 'transform') {
136+
dom.setAttribute(`bind${eventName}`, 'eh')
137+
}
134138
}
135139
} else {
136140
dom.removeEventListener(eventName, oldValue as any)

packages/taro-runtime/src/utils/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,14 @@ export function extend (ctor: Ctor, methodName: string, options: TFunc | Record<
123123
}
124124

125125
let componentsAlias
126+
declare let jd: any
126127
export function getComponentsAlias () {
127128
if (!componentsAlias) {
128129
componentsAlias = _getComponentsAlias(internalComponents)
130+
// 京东小程序transform模式, 把mapping传入基础库
131+
if (process.env.JD_RENDER_TYPE === 'transform') {
132+
jd && jd.setMapping && jd.setMapping(componentsAlias)
133+
}
129134
}
130135
return componentsAlias
131136
}

packages/taro-service/src/platform-plugin-base/mini.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,27 @@ ${exampleCommand}`))
113113
return runner.bind(null, appPath)
114114
}
115115

116+
// 获取该平台特殊的需要注入env的配置,对应平台需覆盖本方法
117+
protected getTargetPlatformOptions() {
118+
return {}
119+
}
120+
116121
/**
117122
* 准备 runner 参数
118123
* @param extraOptions 需要额外合入 Options 的配置项
119124
*/
120125
protected getOptions (extraOptions = {}) {
121126
const { ctx, globalObject, fileType, template } = this
127+
// 平台特性注入
128+
const platformOptions = this.getTargetPlatformOptions()
122129

123130
const config = recursiveMerge(Object.assign({}, this.config), {
124131
env: {
125132
FRAMEWORK: JSON.stringify(this.config.framework),
126133
TARO_ENV: JSON.stringify(this.platform),
127134
TARO_PLATFORM: JSON.stringify(this.platformType),
128-
TARO_VERSION: JSON.stringify(getPkgVersion())
135+
TARO_VERSION: JSON.stringify(getPkgVersion()),
136+
...platformOptions
129137
}
130138
})
131139

0 commit comments

Comments
 (0)