This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 363
/
macro.ts
74 lines (59 loc) · 2.2 KB
/
macro.ts
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as React from 'react';
import { NodePath } from '@babel/traverse';
import { createMacro } from 'babel-plugin-macros';
import { slash } from '@remax/shared';
import Store from '@remax/build-store';
import createHostComponentMacro from './createHostComponent';
import requirePluginComponentMacro from './requirePluginComponent';
import requirePluginMacro from './requirePlugin';
import usePageEventMacro from './usePageEvent';
import useAppEventMacro from './useAppEvent';
type PageEventName =
| 'onLoad'
| 'onShow'
| 'onHide'
| 'onReady'
| 'onPullDownRefresh'
| 'onReachBottom'
| 'onPageScroll'
| 'onShareAppMessage'
| 'onShareTimeline'
| 'onTitleClick'
| 'onOptionMenuClick'
| 'onPopMenuClick'
| 'onPullIntercept'
| 'onBack'
| 'onKeyboardHeight'
| 'onTabItemTap'
| 'beforeTabItemTap'
| 'onResize'
| 'onUnload';
type AppEventName =
| 'onLaunch'
| 'onShow'
| 'onHide'
| 'onError'
| 'onShareAppMessage'
| 'onShareTimeline'
| 'onPageNotFound'
| 'onUnhandledRejection'
| 'onThemeChange';
function remax({ references, state }: { references: { [name: string]: NodePath[] }; state: any }) {
references.createHostComponent?.forEach(path => createHostComponentMacro(path, state));
references.requirePluginComponent?.forEach(path => requirePluginComponentMacro(path, state));
references.requirePlugin?.forEach(path => requirePluginMacro(path));
const importer = slash(state.file.opts.filename);
Store.appEvents.delete(importer);
Store.pageEvents.delete(importer);
references.useAppEvent?.forEach(path => useAppEventMacro(path, state));
references.usePageEvent?.forEach(path => usePageEventMacro(path, state));
}
export declare function createHostComponent<P = any>(
name: string,
props: Array<string | [string, string]>
): React.ComponentType<P>;
export declare function requirePluginComponent<P = any>(pluginName: string): React.ComponentType<P>;
export declare function requirePlugin<P = any>(pluginName: string): P;
export declare function usePageEvent(eventName: PageEventName, callback: (...params: any[]) => any): void;
export declare function useAppEvent(eventName: AppEventName, callback: (...params: any[]) => any): void;
export default createMacro(remax);