@tarojs/plugin-framework-react 4.0.0-canary.11 → 4.0.0-canary.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +8 -8
- package/dist/index.js +27 -185
- package/dist/index.js.map +1 -1
- package/dist/runtime.js +84 -283
- package/dist/runtime.js.map +1 -1
- package/package.json +31 -36
- package/dist/reconciler.js +0 -347
- package/dist/reconciler.js.map +0 -1
package/dist/runtime.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { EMPTY_OBJ, isFunction, isArray, hooks, ensure, isUndefined } from '@tarojs/shared';
|
|
2
2
|
import { Current, getPageInstance, injectPageInstance, incrementId, document, perf, PAGE_INIT, getPath, window, CONTEXT_ACTIONS, safeExecute, removePageInstance, ON_READY, requestAnimationFrame, eventCenter, getOnReadyEventKey, ON_SHOW, getOnShowEventKey, ON_HIDE, getOnHideEventKey, eventHandler, addLeadingSlash } from '@tarojs/runtime';
|
|
3
|
-
import * as Solid from 'solid-js';
|
|
4
|
-
import { createContext, createMemo, useContext, createRenderEffect, onCleanup } from 'solid-js';
|
|
5
|
-
import * as SolidReconciler from '@tarojs/plugin-framework-react/dist/reconciler';
|
|
6
3
|
|
|
7
4
|
const reactMeta = {
|
|
8
5
|
PageContext: EMPTY_OBJ,
|
|
9
6
|
R: EMPTY_OBJ,
|
|
10
7
|
};
|
|
11
|
-
const solidMeta = {
|
|
12
|
-
PageContext: createContext(''),
|
|
13
|
-
};
|
|
14
8
|
|
|
15
9
|
const HOOKS_APP_ID = 'taro-app';
|
|
16
10
|
function isClassComponent(R, component) {
|
|
@@ -50,87 +44,49 @@ function setRouterParams(options) {
|
|
|
50
44
|
|
|
51
45
|
const createTaroHook = (lifecycle) => {
|
|
52
46
|
return (fn) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
(inst[lifecycle])
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
(inst[lifecycle]) = undefined;
|
|
90
|
-
}
|
|
91
|
-
else if (isArray(list)) {
|
|
92
|
-
(inst[lifecycle]) = list.filter(item => item !== callback);
|
|
93
|
-
}
|
|
94
|
-
instRef.current = undefined;
|
|
95
|
-
};
|
|
96
|
-
}, []);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
const context = useContext(solidMeta.PageContext);
|
|
100
|
-
const id = context || HOOKS_APP_ID;
|
|
101
|
-
createRenderEffect(() => {
|
|
102
|
-
let inst = getPageInstance(id);
|
|
103
|
-
let first = false;
|
|
104
|
-
if (!inst) {
|
|
105
|
-
first = true;
|
|
106
|
-
inst = Object.create({
|
|
107
|
-
id: id,
|
|
108
|
-
type: 'page',
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (isFunction(inst[lifecycle])) {
|
|
112
|
-
inst[lifecycle] = [inst[lifecycle], fn];
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
inst[lifecycle] = [
|
|
116
|
-
...((inst[lifecycle]) || []),
|
|
117
|
-
fn
|
|
118
|
-
];
|
|
47
|
+
const { R: React, PageContext } = reactMeta;
|
|
48
|
+
const id = React.useContext(PageContext) || HOOKS_APP_ID;
|
|
49
|
+
const instRef = React.useRef();
|
|
50
|
+
// hold fn ref and keep up to date
|
|
51
|
+
const fnRef = React.useRef(fn);
|
|
52
|
+
if (fnRef.current !== fn)
|
|
53
|
+
fnRef.current = fn;
|
|
54
|
+
React.useLayoutEffect(() => {
|
|
55
|
+
let inst = instRef.current = getPageInstance(id);
|
|
56
|
+
let first = false;
|
|
57
|
+
if (!inst) {
|
|
58
|
+
first = true;
|
|
59
|
+
instRef.current = Object.create(null);
|
|
60
|
+
inst = instRef.current;
|
|
61
|
+
}
|
|
62
|
+
// callback is immutable but inner function is up to date
|
|
63
|
+
const callback = (...args) => fnRef.current(...args);
|
|
64
|
+
if (isFunction(inst[lifecycle])) {
|
|
65
|
+
(inst[lifecycle]) = [inst[lifecycle], callback];
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
(inst[lifecycle]) = [
|
|
69
|
+
...((inst[lifecycle]) || []),
|
|
70
|
+
callback
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
if (first) {
|
|
74
|
+
injectPageInstance(inst, id);
|
|
75
|
+
}
|
|
76
|
+
return () => {
|
|
77
|
+
const inst = instRef.current;
|
|
78
|
+
if (!inst)
|
|
79
|
+
return;
|
|
80
|
+
const list = inst[lifecycle];
|
|
81
|
+
if (list === callback) {
|
|
82
|
+
(inst[lifecycle]) = undefined;
|
|
119
83
|
}
|
|
120
|
-
if (
|
|
121
|
-
|
|
84
|
+
else if (isArray(list)) {
|
|
85
|
+
(inst[lifecycle]) = list.filter(item => item !== callback);
|
|
122
86
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
(inst[lifecycle]) = undefined;
|
|
127
|
-
}
|
|
128
|
-
else if (isArray(list)) {
|
|
129
|
-
(inst[lifecycle]) = list.filter(item => item !== fn);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
}
|
|
87
|
+
instRef.current = undefined;
|
|
88
|
+
};
|
|
89
|
+
}, []);
|
|
134
90
|
};
|
|
135
91
|
};
|
|
136
92
|
/** LifeCycle */
|
|
@@ -159,42 +115,37 @@ const useTitleClick = createTaroHook('onTitleClick');
|
|
|
159
115
|
/** Router */
|
|
160
116
|
const useReady = createTaroHook('onReady');
|
|
161
117
|
const useRouter = (dynamic = false) => {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return dynamic ? Current.router : React.useMemo(() => Current.router, []);
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
return dynamic ? Current.router : createMemo(() => Current.router);
|
|
168
|
-
}
|
|
118
|
+
const React = reactMeta.R;
|
|
119
|
+
return dynamic ? Current.router : React.useMemo(() => Current.router, []);
|
|
169
120
|
};
|
|
170
121
|
const useTabItemTap = createTaroHook('onTabItemTap');
|
|
171
122
|
const useScope = () => undefined;
|
|
172
123
|
|
|
173
124
|
var taroHooks = /*#__PURE__*/Object.freeze({
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
125
|
+
__proto__: null,
|
|
126
|
+
useAddToFavorites: useAddToFavorites,
|
|
127
|
+
useDidHide: useDidHide,
|
|
128
|
+
useDidShow: useDidShow,
|
|
129
|
+
useError: useError,
|
|
130
|
+
useLaunch: useLaunch,
|
|
131
|
+
useLoad: useLoad,
|
|
132
|
+
useOptionMenuClick: useOptionMenuClick,
|
|
133
|
+
usePageNotFound: usePageNotFound,
|
|
134
|
+
usePageScroll: usePageScroll,
|
|
135
|
+
usePullDownRefresh: usePullDownRefresh,
|
|
136
|
+
usePullIntercept: usePullIntercept,
|
|
137
|
+
useReachBottom: useReachBottom,
|
|
138
|
+
useReady: useReady,
|
|
139
|
+
useResize: useResize,
|
|
140
|
+
useRouter: useRouter,
|
|
141
|
+
useSaveExitState: useSaveExitState,
|
|
142
|
+
useScope: useScope,
|
|
143
|
+
useShareAppMessage: useShareAppMessage,
|
|
144
|
+
useShareTimeline: useShareTimeline,
|
|
145
|
+
useTabItemTap: useTabItemTap,
|
|
146
|
+
useTitleClick: useTitleClick,
|
|
147
|
+
useUnhandledRejection: useUnhandledRejection,
|
|
148
|
+
useUnload: useUnload
|
|
198
149
|
});
|
|
199
150
|
|
|
200
151
|
let h$1;
|
|
@@ -213,12 +164,7 @@ function setReconciler(ReactDOM) {
|
|
|
213
164
|
});
|
|
214
165
|
});
|
|
215
166
|
hooks.tap('batchedEventUpdates', function (cb) {
|
|
216
|
-
|
|
217
|
-
ReactDOM === null || ReactDOM === void 0 ? void 0 : ReactDOM.unstable_batchedUpdates(cb);
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
Solid.batch(cb);
|
|
221
|
-
}
|
|
167
|
+
ReactDOM === null || ReactDOM === void 0 ? void 0 : ReactDOM.unstable_batchedUpdates(cb);
|
|
222
168
|
});
|
|
223
169
|
hooks.tap('mergePageInstance', function (prev, next) {
|
|
224
170
|
if (!prev || !next)
|
|
@@ -233,8 +179,7 @@ function setReconciler(ReactDOM) {
|
|
|
233
179
|
next[item] = nextList.concat(prevList);
|
|
234
180
|
});
|
|
235
181
|
});
|
|
236
|
-
|
|
237
|
-
if (process.env.TARO_PLATFORM === 'web' && process.env.FRAMEWORK !== 'solid') {
|
|
182
|
+
if (process.env.TARO_PLATFORM === 'web') {
|
|
238
183
|
hooks.tap('createPullDownComponent', (el, _, R, customWrapper) => {
|
|
239
184
|
const isReactComponent = isClassComponent(R, el);
|
|
240
185
|
return R.forwardRef((props, ref) => {
|
|
@@ -336,7 +281,12 @@ function createReactApp(App, react, dom, config) {
|
|
|
336
281
|
return appInstanceRef.current;
|
|
337
282
|
}
|
|
338
283
|
function waitAppWrapper(cb) {
|
|
339
|
-
|
|
284
|
+
/**
|
|
285
|
+
* 当同个事件触发多次时,waitAppWrapper 会出现同步和异步任务的执行顺序问题,
|
|
286
|
+
* 导致某些场景下 onShow 会优于 onLaunch 执行
|
|
287
|
+
*/
|
|
288
|
+
appWrapperPromise.then(() => cb());
|
|
289
|
+
// appWrapper ? cb() : appWrapperPromise.then(() => cb())
|
|
340
290
|
}
|
|
341
291
|
function renderReactRoot() {
|
|
342
292
|
var _a, _b;
|
|
@@ -409,7 +359,12 @@ function createReactApp(App, react, dom, config) {
|
|
|
409
359
|
}
|
|
410
360
|
},
|
|
411
361
|
unmount(id, cb) {
|
|
412
|
-
appWrapper
|
|
362
|
+
if (appWrapper) {
|
|
363
|
+
appWrapper.unmount(id, cb);
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
appWrapperPromise.then(appWrapper => appWrapper.unmount(id, cb));
|
|
367
|
+
}
|
|
413
368
|
}
|
|
414
369
|
}, {
|
|
415
370
|
config: setDefaultDescriptor({
|
|
@@ -538,167 +493,13 @@ function createReactApp(App, react, dom, config) {
|
|
|
538
493
|
Current.app = appObj;
|
|
539
494
|
return appObj;
|
|
540
495
|
}
|
|
541
|
-
function createSolidApp(App, config) {
|
|
542
|
-
setReconciler();
|
|
543
|
-
const appRef = {
|
|
544
|
-
mount: () => { },
|
|
545
|
-
unmount: () => { },
|
|
546
|
-
};
|
|
547
|
-
function getAppInstance() {
|
|
548
|
-
return appRef;
|
|
549
|
-
}
|
|
550
|
-
function AppWrapper() {
|
|
551
|
-
const [pages, setPages] = Solid.createSignal([]);
|
|
552
|
-
appRef.mount = (component, id) => {
|
|
553
|
-
setPages((old) => {
|
|
554
|
-
return [...old, { id, component }];
|
|
555
|
-
});
|
|
556
|
-
};
|
|
557
|
-
appRef.unmount = (id) => {
|
|
558
|
-
setPages(pages().filter((item) => {
|
|
559
|
-
return item.id !== id;
|
|
560
|
-
}));
|
|
561
|
-
};
|
|
562
|
-
return SolidReconciler.createComponent(App, {
|
|
563
|
-
ref: appRef,
|
|
564
|
-
children: SolidReconciler.createComponent(Solid.For, {
|
|
565
|
-
get each() {
|
|
566
|
-
return pages();
|
|
567
|
-
},
|
|
568
|
-
children: ({ id, component }) => {
|
|
569
|
-
const children = () => SolidReconciler.createComponent(solidMeta.PageContext.Provider, {
|
|
570
|
-
value: id,
|
|
571
|
-
children: () => {
|
|
572
|
-
injectPageInstance({ id: id, type: 'page' }, id);
|
|
573
|
-
return SolidReconciler.createComponent(component, {
|
|
574
|
-
tid: id,
|
|
575
|
-
});
|
|
576
|
-
},
|
|
577
|
-
});
|
|
578
|
-
const root = process.env.TARO_PLATFORM === 'web'
|
|
579
|
-
? document.createElement('div')
|
|
580
|
-
: SolidReconciler.createElement('root');
|
|
581
|
-
if (process.env.TARO_PLATFORM === 'web') {
|
|
582
|
-
root.setAttribute('id', id);
|
|
583
|
-
root.classList.add('taro_page');
|
|
584
|
-
}
|
|
585
|
-
else {
|
|
586
|
-
SolidReconciler.setProp(root, 'id', id);
|
|
587
|
-
}
|
|
588
|
-
SolidReconciler.insert(root, children);
|
|
589
|
-
return root;
|
|
590
|
-
},
|
|
591
|
-
}),
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
function renderSolidRoot() {
|
|
595
|
-
let appId = 'app';
|
|
596
|
-
if (process.env.TARO_PLATFORM === 'web') {
|
|
597
|
-
appId = (config === null || config === void 0 ? void 0 : config.appId) || appId;
|
|
598
|
-
}
|
|
599
|
-
const container = document.getElementById(appId);
|
|
600
|
-
SolidReconciler.render(AppWrapper, container);
|
|
601
|
-
}
|
|
602
|
-
if (process.env.TARO_PLATFORM !== 'web') {
|
|
603
|
-
renderSolidRoot();
|
|
604
|
-
}
|
|
605
|
-
const [ONLAUNCH, ONSHOW, ONHIDE] = hooks.call('getMiniLifecycleImpl').app;
|
|
606
|
-
const appObj = Object.create({
|
|
607
|
-
mount(component, id, cb) {
|
|
608
|
-
const appInstance = getAppInstance();
|
|
609
|
-
appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount(component, id);
|
|
610
|
-
Solid.batch((...args) => {
|
|
611
|
-
perf.stop(PAGE_INIT);
|
|
612
|
-
return cb(...args);
|
|
613
|
-
});
|
|
614
|
-
},
|
|
615
|
-
unmount(id, cb) {
|
|
616
|
-
const appInstance = getAppInstance();
|
|
617
|
-
appInstance === null || appInstance === void 0 ? void 0 : appInstance.unmount(id);
|
|
618
|
-
Solid.batch(cb);
|
|
619
|
-
},
|
|
620
|
-
}, {
|
|
621
|
-
config: setDefaultDescriptor({
|
|
622
|
-
configurable: true,
|
|
623
|
-
value: config,
|
|
624
|
-
}),
|
|
625
|
-
[ONLAUNCH]: setDefaultDescriptor({
|
|
626
|
-
value(options) {
|
|
627
|
-
setRouterParams(options);
|
|
628
|
-
if (process.env.TARO_PLATFORM === 'web') {
|
|
629
|
-
renderSolidRoot();
|
|
630
|
-
}
|
|
631
|
-
const onLaunch = () => {
|
|
632
|
-
var _a;
|
|
633
|
-
const app = getAppInstance();
|
|
634
|
-
if (app) {
|
|
635
|
-
// 把 App Class 上挂载的额外属性同步到全局 app 对象中
|
|
636
|
-
if (app.taroGlobalData) {
|
|
637
|
-
const globalData = app.taroGlobalData;
|
|
638
|
-
const keys = Object.keys(globalData);
|
|
639
|
-
const descriptors = Object.getOwnPropertyDescriptors(globalData);
|
|
640
|
-
keys.forEach(key => {
|
|
641
|
-
Object.defineProperty(this, key, {
|
|
642
|
-
configurable: true,
|
|
643
|
-
enumerable: true,
|
|
644
|
-
get() {
|
|
645
|
-
return globalData[key];
|
|
646
|
-
},
|
|
647
|
-
set(value) {
|
|
648
|
-
globalData[key] = value;
|
|
649
|
-
}
|
|
650
|
-
});
|
|
651
|
-
});
|
|
652
|
-
Object.defineProperties(this, descriptors);
|
|
653
|
-
}
|
|
654
|
-
(_a = app.onCreate) === null || _a === void 0 ? void 0 : _a.call(app);
|
|
655
|
-
}
|
|
656
|
-
};
|
|
657
|
-
onLaunch();
|
|
658
|
-
triggerAppHook('onLaunch', options);
|
|
659
|
-
},
|
|
660
|
-
}),
|
|
661
|
-
[ONSHOW]: setDefaultDescriptor({
|
|
662
|
-
value(options) {
|
|
663
|
-
setRouterParams(options);
|
|
664
|
-
triggerAppHook('onShow', options);
|
|
665
|
-
},
|
|
666
|
-
}),
|
|
667
|
-
[ONHIDE]: setDefaultDescriptor({
|
|
668
|
-
value() {
|
|
669
|
-
triggerAppHook('onHide');
|
|
670
|
-
},
|
|
671
|
-
}),
|
|
672
|
-
onError: setDefaultDescriptor({
|
|
673
|
-
value(error) {
|
|
674
|
-
triggerAppHook('onError', error);
|
|
675
|
-
},
|
|
676
|
-
}),
|
|
677
|
-
onPageNotFound: setDefaultDescriptor({
|
|
678
|
-
value(res) {
|
|
679
|
-
triggerAppHook('onPageNotFound', res);
|
|
680
|
-
},
|
|
681
|
-
}),
|
|
682
|
-
});
|
|
683
|
-
function triggerAppHook(lifecycle, ...option) {
|
|
684
|
-
const instance = getPageInstance(HOOKS_APP_ID);
|
|
685
|
-
if (instance) {
|
|
686
|
-
const app = getAppInstance();
|
|
687
|
-
const func = hooks.call('getLifecycle', instance, lifecycle);
|
|
688
|
-
if (Array.isArray(func)) {
|
|
689
|
-
func.forEach((cb) => cb.apply(app, option));
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
Current.app = appObj;
|
|
694
|
-
return appObj;
|
|
695
|
-
}
|
|
696
496
|
|
|
697
497
|
const getNativeCompId = incrementId();
|
|
698
498
|
let h;
|
|
699
499
|
let ReactDOM;
|
|
700
500
|
let nativeComponentApp;
|
|
701
501
|
function initNativeComponentEntry(params) {
|
|
502
|
+
var _a;
|
|
702
503
|
const { R, ReactDOM, cb, isDefaultEntryDom = true } = params;
|
|
703
504
|
class NativeComponentWrapper extends R.Component {
|
|
704
505
|
constructor() {
|
|
@@ -782,7 +583,7 @@ function initNativeComponentEntry(params) {
|
|
|
782
583
|
// create
|
|
783
584
|
const nativeApp = document.createElement('nativeComponent');
|
|
784
585
|
// insert
|
|
785
|
-
app === null || app === void 0 ? void 0 : app.appendChild(nativeApp);
|
|
586
|
+
(_a = app === null || app === void 0 ? void 0 : app.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(nativeApp);
|
|
786
587
|
app = nativeApp;
|
|
787
588
|
}
|
|
788
589
|
// eslint-disable-next-line react/no-deprecated
|
|
@@ -1161,5 +962,5 @@ if (process.env.FRAMEWORK === 'preact' && process.env.TARO_PLATFORM === 'mini')
|
|
|
1161
962
|
// })
|
|
1162
963
|
}
|
|
1163
964
|
|
|
1164
|
-
export { connectReactPage, createH5NativeComponentConfig, createNativeComponentConfig, createNativePageConfig, createReactApp,
|
|
965
|
+
export { connectReactPage, createH5NativeComponentConfig, createNativeComponentConfig, createNativePageConfig, createReactApp, setReconciler, useAddToFavorites, useDidHide, useDidShow, useError, useLaunch, useLoad, useOptionMenuClick, usePageNotFound, usePageScroll, usePullDownRefresh, usePullIntercept, useReachBottom, useReady, useResize, useRouter, useSaveExitState, useScope, useShareAppMessage, useShareTimeline, useTabItemTap, useTitleClick, useUnhandledRejection, useUnload };
|
|
1165
966
|
//# sourceMappingURL=runtime.js.map
|