Skip to content

Commit

Permalink
refactor platform/patch
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki committed Dec 10, 2024
1 parent 1e2262a commit b2a9df5
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 1,422 deletions.
27 changes: 3 additions & 24 deletions packages/core/src/convertor/convertor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import * as wxLifecycle from '../platform/patch/wx/lifecycle'
import * as aliLifecycle from '../platform/patch/ali/lifecycle'
import * as webLifecycle from '../platform/patch/web/lifecycle'
import * as swanLifecycle from '../platform/patch/swan/lifecycle'
import { LIFECYCLE, lifecycleProxyMap, pageMode } from '../platform/patch/lifecycle/index'
import { mergeLifecycle } from './mergeLifecycle'
import { error } from '@mpxjs/utils'
import wxToAliRule from './wxToAli'
Expand All @@ -13,24 +10,6 @@ import wxToDdRule from './wxToDd'
import wxToJdRule from './wxToJd'
import wxToReactRule from './wxToReact'

// 根据当前环境获取的默认生命周期信息
let lifecycleInfo
let pageMode

if (__mpx_mode__ === 'web') {
lifecycleInfo = webLifecycle
pageMode = ''
} else if (__mpx_mode__ === 'ali') {
lifecycleInfo = aliLifecycle
pageMode = ''
} else if (__mpx_mode__ === 'swan') {
lifecycleInfo = swanLifecycle
pageMode = 'blend'
} else {
lifecycleInfo = wxLifecycle
pageMode = 'blend'
}

/**
* 转换规则包含四点
* lifecycle [object] 生命周期
Expand All @@ -40,8 +19,8 @@ if (__mpx_mode__ === 'web') {
* convert [function] 自定义转换函数, 接收一个options
*/
const defaultConvertRule = {
lifecycle: mergeLifecycle(lifecycleInfo.LIFECYCLE),
lifecycleProxyMap: lifecycleInfo.lifecycleProxyMap,
lifecycle: mergeLifecycle(LIFECYCLE),
lifecycleProxyMap: lifecycleProxyMap,
pageMode,
support: !!pageMode,
convert: null
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/convertor/wxToAli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as wxLifecycle from '../platform/patch/wx/lifecycle'
import * as aliLifecycle from '../platform/patch/ali/lifecycle'
import * as wxLifecycle from '../platform/patch/lifecycle/index.wx'
import { LIFECYCLE } from '../platform/patch/lifecycle/index'
import { mergeLifecycle } from './mergeLifecycle'
import { error, hasOwn, isDev } from '@mpxjs/utils'
import { implemented } from '../core/implement'
Expand Down Expand Up @@ -38,7 +38,7 @@ function notSupportTip (options) {

export default {
lifecycle: mergeLifecycle(wxLifecycle.LIFECYCLE),
lifecycle2: mergeLifecycle(aliLifecycle.LIFECYCLE),
lifecycle2: mergeLifecycle(LIFECYCLE),
pageMode: 'blend',
support: false,
lifecycleProxyMap: wxLifecycle.lifecycleProxyMap,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/convertor/wxToSwan.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { error, isDev } from '@mpxjs/utils'
import { implemented } from '../core/implement'
import { mergeLifecycle } from './mergeLifecycle'
import * as wxLifecycle from '../platform/patch/wx/lifecycle'
import * as swanLifecycle from '../platform/patch/swan/lifecycle'
import * as wxLifecycle from '../platform/patch/lifecycle/index.wx'
import { LIFECYCLE } from '../platform/patch/lifecycle/index'

const BEHAVIORS_MAP = {
'wx://form-field': 'swan://form-field',
Expand Down Expand Up @@ -30,7 +30,7 @@ function notSupportTip (options) {

export default {
lifecycle: mergeLifecycle(wxLifecycle.LIFECYCLE),
lifecycle2: mergeLifecycle(swanLifecycle.LIFECYCLE),
lifecycle2: mergeLifecycle(LIFECYCLE),
pageMode: 'blend',
support: true,
lifecycleProxyMap: wxLifecycle.lifecycleProxyMap,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/convertor/wxToWeb.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as wxLifecycle from '../platform/patch/wx/lifecycle'
import * as webLifecycle from '../platform/patch/web/lifecycle'
import * as wxLifecycle from '../platform/patch/lifecycle/index.wx'
import { LIFECYCLE } from '../platform/patch/lifecycle/index'
import { mergeLifecycle } from './mergeLifecycle'
import {
isObject,
Expand Down Expand Up @@ -32,7 +32,7 @@ function notSupportTip (options) {

export default {
lifecycle: mergeLifecycle(wxLifecycle.LIFECYCLE),
lifecycle2: mergeLifecycle(webLifecycle.LIFECYCLE),
lifecycle2: mergeLifecycle(LIFECYCLE),
pageMode: 'blend',
support: true,
lifecycleProxyMap: wxLifecycle.lifecycleProxyMap,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/platform/createApp.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import transferOptions from '../core/transferOptions'
import builtInKeysMap from './patch/builtInKeysMap'
import { makeMap, spreadProp, parseUrlQuery, getFocusedNavigation } from '@mpxjs/utils'
import { mergeLifecycle } from '../convertor/mergeLifecycle'
import * as wxLifecycle from '../platform/patch/wx/lifecycle'
import { LIFECYCLE } from '../platform/patch/lifecycle/index'
import Mpx from '../index'
import { createElement, memo, useRef, useEffect } from 'react'
import * as ReactNative from 'react-native'
import { ref } from '../observer/ref'

const appHooksMap = makeMap(mergeLifecycle(wxLifecycle.LIFECYCLE).app)
const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)

function getOrientation (window = ReactNative.Dimensions.get('window')) {
return window.width > window.height ? 'landscape' : 'portrait'
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/platform/createApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import mergeOptions from '../core/mergeOptions'
import builtInKeysMap from './patch/builtInKeysMap'
import { makeMap, spreadProp, isBrowser } from '@mpxjs/utils'
import { mergeLifecycle } from '../convertor/mergeLifecycle'
import * as webLifecycle from '../platform/patch/web/lifecycle'
import { LIFECYCLE } from '../platform/patch/lifecycle/index'
import Mpx from '../index'
import { initAppProvides } from './export/apiInject'

const webAppHooksMap = makeMap(mergeLifecycle(webLifecycle.LIFECYCLE).app)
const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)

function filterOptions (options, appData) {
const newOptions = {}
Object.keys(options).forEach(key => {
if (builtInKeysMap[key]) {
return
}
if (__mpx_mode__ === 'web' && !webAppHooksMap[key] && key !== 'provide') {
if (__mpx_mode__ === 'web' && !appHooksMap[key] && key !== 'provide') {
appData[key] = options[key]
} else {
newOptions[key] = options[key]
Expand Down
193 changes: 0 additions & 193 deletions packages/core/src/platform/patch/ali/getDefaultOptions.js

This file was deleted.

61 changes: 0 additions & 61 deletions packages/core/src/platform/patch/ali/lifecycle.js

This file was deleted.

Loading

0 comments on commit b2a9df5

Please sign in to comment.