@ray-js/runtime 1.6.29 → 1.6.30-alpha.0
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.
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import React from 'react';
|
|
13
|
+
import { pageLifecycles } from '@ray-js/types';
|
|
14
|
+
import { PageInstanceContext } from '../PageInstanceContext';
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
16
|
+
export function withPageLifecycle(Component) {
|
|
17
|
+
const displayName = `WithPageLifecycle(${Component.displayName || Component.name})`;
|
|
18
|
+
class WithPageLifeCycle extends React.Component {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(...arguments);
|
|
21
|
+
this.refHandle = (ref) => {
|
|
22
|
+
const forwardedRef = this.props.forwardedRef;
|
|
23
|
+
if (ref) {
|
|
24
|
+
this.additionToLifecycle(ref);
|
|
25
|
+
}
|
|
26
|
+
if (forwardedRef) {
|
|
27
|
+
if (typeof forwardedRef === 'function') {
|
|
28
|
+
forwardedRef(ref);
|
|
29
|
+
}
|
|
30
|
+
else if (typeof forwardedRef === 'object') {
|
|
31
|
+
forwardedRef.current = ref;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
render() {
|
|
37
|
+
const _a = this.props, { forwardedRef } = _a, rest = __rest(_a, ["forwardedRef"]);
|
|
38
|
+
return (<PageInstanceContext.Consumer>
|
|
39
|
+
{(context) => {
|
|
40
|
+
const { $instance } = context;
|
|
41
|
+
// 挂载页面事件
|
|
42
|
+
this.additionToLifecycle = function additionToLifecycle(ins) {
|
|
43
|
+
Object.keys(pageLifecycles).forEach((event) => {
|
|
44
|
+
if (typeof ins[event] === 'function') {
|
|
45
|
+
$instance.registerLifecycle(event, ins, ins[event]);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
return (<Component
|
|
50
|
+
// fixed: 坑货,不能直接一个匿名函数,因为每次渲染匿名函数都是个新的,导致每次渲染都会调用一次
|
|
51
|
+
// 进而导致生命周期函数重复添加
|
|
52
|
+
ref={this.refHandle} {...rest}/>);
|
|
53
|
+
}}
|
|
54
|
+
</PageInstanceContext.Consumer>);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
WithPageLifeCycle.displayName = displayName;
|
|
58
|
+
const forwardRef = React.forwardRef((props, ref) => {
|
|
59
|
+
return <WithPageLifeCycle {...props} forwardedRef={ref}/>;
|
|
60
|
+
});
|
|
61
|
+
forwardRef.displayName = displayName;
|
|
62
|
+
return forwardRef;
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/runtime",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.30-alpha.0",
|
|
4
4
|
"description": "Ray cross runtime",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ray"
|
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
"@ray-core/runtime": "^0.4.8"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@ray-js/cli": "1.6.
|
|
31
|
-
"@ray-js/types": "1.6.
|
|
30
|
+
"@ray-js/cli": "1.6.30-alpha.0",
|
|
31
|
+
"@ray-js/types": "1.6.30-alpha.0",
|
|
32
|
+
"typescript": "^5.8.2"
|
|
32
33
|
},
|
|
33
34
|
"publishConfig": {
|
|
34
35
|
"access": "public",
|