-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy pathwxToSwan.js
More file actions
51 lines (46 loc) · 1.51 KB
/
wxToSwan.js
File metadata and controls
51 lines (46 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { error, isDev } from '@mpxjs/utils'
import { implemented } from '../core/implement'
import { mergeLifecycle } from './mergeLifecycle'
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',
'wx://component-export': 'swan://component-export'
}
const unsupported = ['moved', 'relations']
function convertErrorDesc (key) {
error(`Options.${key} is not supported in runtime conversion from wx to swan.`, global.currentResource || global.currentModuleId)
}
function notSupportTip (options) {
unsupported.forEach(key => {
if (options[key]) {
if (!implemented[key]) {
isDev && convertErrorDesc(key)
delete options[key]
} else if (implemented[key].remove) {
delete options[key]
}
}
})
}
export default {
lifecycle: mergeLifecycle(wxLifecycle.LIFECYCLE),
lifecycle2: mergeLifecycle(LIFECYCLE),
pageMode: 'blend',
support: true,
lifecycleProxyMap: wxLifecycle.lifecycleProxyMap,
convert (options, type) {
if (options.behaviors) {
options.behaviors.forEach((behavior, idx) => {
if (typeof behavior === 'string' && BEHAVIORS_MAP[behavior]) {
options.behaviors.splice(idx, 1, BEHAVIORS_MAP[behavior])
}
})
}
if (type === 'page' && !options.__pageCtor__) {
options.options = options.options || {}
options.options.addGlobalClass = true
}
notSupportTip(options)
}
}