@ray-js/runtime 1.3.0-beta.2-beta-2 → 1.3.0-beta.3

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/lib/index.d.ts CHANGED
@@ -10,3 +10,5 @@ export declare const useNativeEffect: typeof runtime['useNativeEffect'];
10
10
  export declare const useQuery: typeof runtime['useQuery'];
11
11
  export declare const usePageInstance: typeof runtime['usePageInstance'];
12
12
  export declare const useComponentInstance: typeof runtime['useComponentInstance'];
13
+ export declare const createPortal: typeof runtime.createPortal;
14
+ export declare const useModal: typeof runtime['useModal'];
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import * as runtime from '@ray-core/runtime';
1
2
  export { lifecycle } from './lifecycle';
2
3
  export { PageInstance } from './PageInstance';
3
4
  export { PageInstanceContext } from './PageInstanceContext';
@@ -18,4 +19,9 @@ export var usePageInstance = function () {
18
19
  };
19
20
  export var useComponentInstance = function () {
20
21
  return console.warn("// TODO \u6682\u672A\u5B9E\u73B0\u94A9\u5B50 'useComponentInstance'");
22
+ };
23
+ export var createPortal = runtime.createPortal;
24
+ export var useModal = function () {
25
+ console.warn("// TODO \u6682\u672A\u5B9E\u73B0\u94A9\u5B50 'useModal'");
26
+ return undefined;
21
27
  };
@@ -1,12 +1,14 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _typeof from "@babel/runtime/helpers/esm/typeof";
3
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
4
4
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
5
5
  import _createClass from "@babel/runtime/helpers/esm/createClass";
6
+ import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
6
7
  import _inherits from "@babel/runtime/helpers/esm/inherits";
7
8
  import _createSuper from "@babel/runtime/helpers/esm/createSuper";
8
9
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
10
  var _excluded = ["forwardedRef"];
11
+ import "core-js/modules/es.array.concat.js";
10
12
  import "core-js/modules/es.object.to-string.js";
11
13
  import "core-js/modules/web.dom-collections.for-each.js";
12
14
  import "core-js/modules/es.object.keys.js";
@@ -22,14 +24,40 @@ export function withPageLifecycle(Component) {
22
24
  var _super = _createSuper(WithPageLifeCycle);
23
25
 
24
26
  function WithPageLifeCycle() {
27
+ var _this;
28
+
25
29
  _classCallCheck(this, WithPageLifeCycle);
26
30
 
27
- return _super.apply(this, arguments);
31
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
32
+ args[_key] = arguments[_key];
33
+ }
34
+
35
+ _this = _super.call.apply(_super, [this].concat(args));
36
+
37
+ _defineProperty(_assertThisInitialized(_this), "refHandle", function (ref) {
38
+ var forwardedRef = _this.props.forwardedRef;
39
+
40
+ if (ref) {
41
+ _this.additionToLifecycle(ref);
42
+ }
43
+
44
+ if (forwardedRef) {
45
+ if (typeof forwardedRef === 'function') {
46
+ forwardedRef(ref);
47
+ } else if (_typeof(forwardedRef) === 'object') {
48
+ forwardedRef.current = ref;
49
+ }
50
+ }
51
+ });
52
+
53
+ return _this;
28
54
  }
29
55
 
30
56
  _createClass(WithPageLifeCycle, [{
31
57
  key: "render",
32
58
  value: function render() {
59
+ var _this2 = this;
60
+
33
61
  var _this$props = this.props,
34
62
  forwardedRef = _this$props.forwardedRef,
35
63
  rest = _objectWithoutProperties(_this$props, _excluded);
@@ -37,28 +65,18 @@ export function withPageLifecycle(Component) {
37
65
  return /*#__PURE__*/React.createElement(PageInstanceContext.Consumer, null, function (context) {
38
66
  var $instance = context.$instance; // 挂载页面事件
39
67
 
40
- function additionToLifecycle(ins) {
68
+ _this2.additionToLifecycle = function (ins) {
41
69
  Object.keys(pageLifecycles).forEach(function (event) {
42
70
  if (typeof ins[event] === 'function') {
43
71
  $instance.registerLifecycle(event, ins, ins[event]);
44
72
  }
45
73
  });
46
- }
74
+ };
47
75
 
48
- return /*#__PURE__*/React.createElement(Component, _extends({
49
- ref: function ref(_ref) {
50
- if (_ref) {
51
- additionToLifecycle(_ref);
52
- }
53
-
54
- if (forwardedRef) {
55
- if (typeof forwardedRef === 'function') {
56
- forwardedRef(_ref);
57
- } else if (_typeof(forwardedRef) === 'object') {
58
- forwardedRef.current = _ref;
59
- }
60
- }
61
- }
76
+ return /*#__PURE__*/React.createElement(Component // fixed: 坑货,不能直接一个匿名函数,因为每次渲染匿名函数都是个新的,导致每次渲染都会调用一次
77
+ // 进而导致生命周期函数重复添加
78
+ , _extends({
79
+ ref: _this2.refHandle
62
80
  }, rest));
63
81
  });
64
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/runtime",
3
- "version": "1.3.0-beta.2-beta-2",
3
+ "version": "1.3.0-beta.3",
4
4
  "description": "Ray cross runtime",
5
5
  "keywords": [
6
6
  "ray"
@@ -21,11 +21,11 @@
21
21
  "watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
22
22
  },
23
23
  "dependencies": {
24
- "@ray-core/runtime": "^0.2.6"
24
+ "@ray-core/runtime": "^0.3.0-beta.4"
25
25
  },
26
26
  "devDependencies": {
27
- "@ray-js/cli": "^1.3.0-beta.2-beta-2",
28
- "@ray-js/types": "^1.3.0-beta.2-beta-2"
27
+ "@ray-js/cli": "^1.3.0-beta.3",
28
+ "@ray-js/types": "^1.3.0-beta.3"
29
29
  },
30
30
  "maintainers": [
31
31
  {
@@ -33,6 +33,6 @@
33
33
  "email": "tuyafe@tuya.com"
34
34
  }
35
35
  ],
36
- "gitHead": "067ce2e382196cd995ebc4774fc5e977ac21115c",
36
+ "gitHead": "be72a5dad6214ebf9c6653df02956374c735c98e",
37
37
  "repository": {}
38
38
  }