@ray-core/framework-shared
Advanced tools
+30
-0
@@ -6,2 +6,32 @@ # Change Log | ||
| ## [0.5.1-beta.2](http://registry.code.tuya-inc.top:10023/godzilla/ray-core/compare/v0.5.1-beta.1...v0.5.1-beta.2) (2025-09-05) | ||
| **Note:** Version bump only for package @ray-core/framework-shared | ||
| ## [0.5.1-beta.1](http://registry.code.tuya-inc.top:10023/godzilla/ray-core/compare/v0.5.0...v0.5.1-beta.1) (2025-09-04) | ||
| ### Features | ||
| * 添加APP内存缓存生命周期 ([5b707b7](http://registry.code.tuya-inc.top:10023/godzilla/ray-core/commits/5b707b7eed7ad87988c6e49118c38d7abe2e3013)) | ||
| ## [0.5.1-beta.0](http://registry.code.tuya-inc.top:10023/godzilla/ray-core/compare/v0.5.0...v0.5.1-beta.0) (2025-09-04) | ||
| ### Features | ||
| * 添加APP内存缓存生命周期 ([5b707b7](http://registry.code.tuya-inc.top:10023/godzilla/ray-core/commits/5b707b7eed7ad87988c6e49118c38d7abe2e3013)) | ||
| # [0.5.0](http://registry.code.tuya-inc.top:10023/godzilla/ray-core/compare/v0.4.9...v0.5.0) (2025-06-23) | ||
@@ -8,0 +38,0 @@ |
@@ -31,3 +31,5 @@ export declare type Callback = (...args: any[]) => any; | ||
| unhandledRejection = "unhandledRejection", | ||
| themeChange = "themeChange" | ||
| themeChange = "themeChange", | ||
| pause = "pause", | ||
| resume = "resume" | ||
| } | ||
@@ -34,0 +36,0 @@ export declare function lifeCycleName(name: string): Lifecycle; |
+2
-0
@@ -41,2 +41,4 @@ "use strict"; | ||
| AppLifecycle["themeChange"] = "themeChange"; | ||
| AppLifecycle["pause"] = "pause"; | ||
| AppLifecycle["resume"] = "resume"; | ||
| })(AppLifecycle = exports.AppLifecycle || (exports.AppLifecycle = {})); | ||
@@ -43,0 +45,0 @@ function lifeCycleName(name) { |
@@ -31,3 +31,5 @@ export declare type Callback = (...args: any[]) => any; | ||
| unhandledRejection = "unhandledRejection", | ||
| themeChange = "themeChange" | ||
| themeChange = "themeChange", | ||
| pause = "pause", | ||
| resume = "resume" | ||
| } | ||
@@ -34,0 +36,0 @@ export declare function lifeCycleName(name: string): Lifecycle; |
+2
-0
@@ -35,2 +35,4 @@ import capitalize from './utils/capitalize'; | ||
| AppLifecycle["themeChange"] = "themeChange"; | ||
| AppLifecycle["pause"] = "pause"; | ||
| AppLifecycle["resume"] = "resume"; | ||
| })(AppLifecycle || (AppLifecycle = {})); | ||
@@ -37,0 +39,0 @@ export function lifeCycleName(name) { |
+3
-3
| { | ||
| "name": "@ray-core/framework-shared", | ||
| "version": "0.5.0", | ||
| "version": "0.5.1-beta.2", | ||
| "description": "使用真正的 React 构建跨平台小程序", | ||
@@ -21,3 +21,3 @@ "license": "MIT", | ||
| "devDependencies": { | ||
| "@ray-core/types": "0.5.0", | ||
| "@ray-core/types": "0.5.1-beta.2", | ||
| "@types/react": "^16.9.33", | ||
@@ -30,3 +30,3 @@ "@types/react-is": "^16.7.1", | ||
| }, | ||
| "gitHead": "2aac5b8888ad5ab181eac842c7a18466c22f50f9" | ||
| "gitHead": "7ffd172b0efbc2c7df1f4ee74a6f30a9941c7d86" | ||
| } |
| export {}; |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var AppInstanceContext_1 = __importDefault(require("../AppInstanceContext")); | ||
| var lifecycle_1 = require("../lifecycle"); | ||
| describe('App Instance Context', function () { | ||
| it('works', function () { | ||
| var fn = function () { return void 0; }; | ||
| var unregister = AppInstanceContext_1.default.registerLifecycle(lifecycle_1.AppLifecycle.show, fn); | ||
| expect(AppInstanceContext_1.default.lifecycleCallback[lifecycle_1.AppLifecycle.show][0]).toBe(fn); | ||
| unregister(); | ||
| expect(AppInstanceContext_1.default.lifecycleCallback[lifecycle_1.AppLifecycle.show]).toHaveLength(0); | ||
| }); | ||
| }); |
| export {}; |
| "use strict"; | ||
| var __extends = (this && this.__extends) || (function () { | ||
| var extendStatics = function (d, b) { | ||
| extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
| return extendStatics(d, b); | ||
| }; | ||
| return function (d, b) { | ||
| if (typeof b !== "function" && b !== null) | ||
| throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| }; | ||
| })(); | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var React = __importStar(require("react")); | ||
| var react_test_renderer_1 = __importDefault(require("react-test-renderer")); | ||
| var createPageWrapper_1 = __importDefault(require("../createPageWrapper")); | ||
| describe('createPageWrapper', function () { | ||
| var Page = /** @class */ (function (_super) { | ||
| __extends(Page, _super); | ||
| function Page() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| Page.prototype.render = function () { | ||
| return React.createElement("view", null, "hi"); | ||
| }; | ||
| return Page; | ||
| }(React.Component)); | ||
| it('get Page ref', function () { | ||
| var WrappedPage = (0, createPageWrapper_1.default)(Page, ''); | ||
| var testRenderer = react_test_renderer_1.default.create(React.createElement(WrappedPage, { page: null, query: {} })); | ||
| var instance = testRenderer.getInstance(); | ||
| expect(instance.pageComponentInstance).toBeInstanceOf(Page); | ||
| }); | ||
| it('get Page ref with HOC', function () { | ||
| var hoc = function (PageComponent) { | ||
| return React.forwardRef(function (_, ref) { | ||
| return React.createElement(PageComponent, { ref: ref }); | ||
| }); | ||
| }; | ||
| var WrappedPage = (0, createPageWrapper_1.default)(hoc(Page), ''); | ||
| var testRenderer = react_test_renderer_1.default.create(React.createElement(WrappedPage, { page: null, query: {} })); | ||
| var instance = testRenderer.getInstance(); | ||
| expect(instance.pageComponentInstance).toBeInstanceOf(Page); | ||
| }); | ||
| it('does not pass ref to FC', function () { | ||
| var FCPage = function (props) { return React.createElement("view", null, "hi"); }; | ||
| var WrappedPage = (0, createPageWrapper_1.default)(FCPage, ''); | ||
| var testRenderer = react_test_renderer_1.default.create(React.createElement(WrappedPage, { page: null, query: {} })); | ||
| var instance = testRenderer.getInstance(); | ||
| expect(instance.pageComponentInstance).toBeNull(); | ||
| }); | ||
| }); |
| export {}; |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
| Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
| }) : function(o, v) { | ||
| o["default"] = v; | ||
| }); | ||
| var __importStar = (this && this.__importStar) || function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
| __setModuleDefault(result, mod); | ||
| return result; | ||
| }; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var React = __importStar(require("react")); | ||
| var PluginDriver_1 = __importDefault(require("../PluginDriver")); | ||
| describe('PluginDriver', function () { | ||
| it('onAppConfig', function () { | ||
| var pluginDriver = new PluginDriver_1.default([ | ||
| { | ||
| onAppConfig: function (_a) { | ||
| var config = _a.config; | ||
| config.foo = 1; | ||
| return config; | ||
| }, | ||
| }, | ||
| { | ||
| onAppConfig: function (_a) { | ||
| var config = _a.config; | ||
| config.bar = 1; | ||
| return config; | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(pluginDriver.onAppConfig({})).toEqual({ foo: 1, bar: 1 }); | ||
| }); | ||
| it('onPageConfig', function () { | ||
| var pluginDriver = new PluginDriver_1.default([ | ||
| { | ||
| onPageConfig: function (_a) { | ||
| var config = _a.config; | ||
| config.foo = 1; | ||
| return config; | ||
| }, | ||
| }, | ||
| { | ||
| onPageConfig: function (_a) { | ||
| var config = _a.config, page = _a.page; | ||
| config.page = page; | ||
| return config; | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(pluginDriver.onPageConfig({ config: {}, page: 'pages/foo' })).toEqual({ foo: 1, page: 'pages/foo' }); | ||
| }); | ||
| it('onAppComponent', function () { | ||
| var App = function (props) { return props.children; }; | ||
| var wrap = function (component) { | ||
| var Wrapped = function () { return React.createElement(component); }; | ||
| Wrapped.displayName = 'Wrapped'; | ||
| return Wrapped; | ||
| }; | ||
| var pluginDriver = new PluginDriver_1.default([ | ||
| { | ||
| onAppComponent: function (_a) { | ||
| var component = _a.component; | ||
| return wrap(component); | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(pluginDriver.onAppComponent(App).displayName).toEqual('Wrapped'); | ||
| }); | ||
| it('onPageComponent', function () { | ||
| var Page = function () { return React.createElement('view'); }; | ||
| var wrap = function (component, page) { | ||
| var Wrapped = function () { return React.createElement(component); }; | ||
| Wrapped.displayName = page; | ||
| return Wrapped; | ||
| }; | ||
| var pluginDriver = new PluginDriver_1.default([ | ||
| { | ||
| onPageComponent: function (_a) { | ||
| var component = _a.component, page = _a.page; | ||
| return wrap(component, page); | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(pluginDriver.onPageComponent({ component: Page, page: 'pages/foo/index' }).displayName).toEqual('pages/foo/index'); | ||
| }); | ||
| it('onCreateHostComponent', function () { | ||
| var View = function () { return React.createElement('view'); }; | ||
| var wrap = function (component) { | ||
| var Wrapped = function () { return React.createElement(component); }; | ||
| Wrapped.displayName = 'Wrapped'; | ||
| return Wrapped; | ||
| }; | ||
| var pluginDriver = new PluginDriver_1.default([ | ||
| { | ||
| onCreateHostComponent: function (_a) { | ||
| var component = _a.component; | ||
| return wrap(component); | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(pluginDriver.onCreateHostComponent(View).displayName).toEqual('Wrapped'); | ||
| }); | ||
| }); |
| export {}; |
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| var __generator = (this && this.__generator) || function (thisArg, body) { | ||
| var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
| return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
| function verb(n) { return function (v) { return step([n, v]); }; } | ||
| function step(op) { | ||
| if (f) throw new TypeError("Generator is already executing."); | ||
| while (_) try { | ||
| if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
| if (y = 0, t) op = [op[0] & 2, t.value]; | ||
| switch (op[0]) { | ||
| case 0: case 1: t = op; break; | ||
| case 4: _.label++; return { value: op[1], done: false }; | ||
| case 5: _.label++; y = op[1]; op = [0]; continue; | ||
| case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
| default: | ||
| if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
| if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
| if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
| if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
| if (t[2]) _.ops.pop(); | ||
| _.trys.pop(); continue; | ||
| } | ||
| op = body.call(thisArg, _); | ||
| } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
| if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
| } | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var promisify_1 = require("../promisify"); | ||
| describe('promisify', function () { | ||
| it('promisify api and resolve when succeed', function () { | ||
| function api(_a) { | ||
| var success = _a.success; | ||
| success('success'); | ||
| } | ||
| var promisifyAPI = (0, promisify_1.promisify)(api); | ||
| expect.assertions(1); | ||
| expect(promisifyAPI()).resolves.toEqual('success'); | ||
| }); | ||
| it('resolve by success param', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
| function api(_a) { | ||
| var success = _a.success; | ||
| success('success'); | ||
| } | ||
| var promisifyAPI, success; | ||
| return __generator(this, function (_a) { | ||
| switch (_a.label) { | ||
| case 0: | ||
| promisifyAPI = (0, promisify_1.promisify)(api); | ||
| success = jest.fn(); | ||
| return [4 /*yield*/, promisifyAPI({ | ||
| success: success, | ||
| })]; | ||
| case 1: | ||
| _a.sent(); | ||
| expect(success).toBeCalledTimes(1); | ||
| return [2 /*return*/]; | ||
| } | ||
| }); | ||
| }); }); | ||
| it('promisify api and reject when failed', function () { | ||
| function api(_a) { | ||
| var fail = _a.fail; | ||
| fail('error'); | ||
| } | ||
| var promisifyAPI = (0, promisify_1.promisify)(api); | ||
| expect.assertions(1); | ||
| expect(promisifyAPI()).rejects.toEqual('error'); | ||
| }); | ||
| it('reject by fail param', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
| function api(_a) { | ||
| var fail = _a.fail; | ||
| fail('fail'); | ||
| } | ||
| var promisifyAPI, fail; | ||
| return __generator(this, function (_a) { | ||
| switch (_a.label) { | ||
| case 0: | ||
| promisifyAPI = (0, promisify_1.promisify)(api); | ||
| fail = jest.fn(); | ||
| return [4 /*yield*/, promisifyAPI({ | ||
| fail: fail, | ||
| }).catch(function (error) { | ||
| expect(error).toBe('fail'); | ||
| })]; | ||
| case 1: | ||
| _a.sent(); | ||
| expect(fail).toBeCalledTimes(1); | ||
| return [2 /*return*/]; | ||
| } | ||
| }); | ||
| }); }); | ||
| }); |
| export {}; |
| import AppInstanceContext from '../AppInstanceContext'; | ||
| import { AppLifecycle } from '../lifecycle'; | ||
| describe('App Instance Context', function () { | ||
| it('works', function () { | ||
| var fn = function () { return void 0; }; | ||
| var unregister = AppInstanceContext.registerLifecycle(AppLifecycle.show, fn); | ||
| expect(AppInstanceContext.lifecycleCallback[AppLifecycle.show][0]).toBe(fn); | ||
| unregister(); | ||
| expect(AppInstanceContext.lifecycleCallback[AppLifecycle.show]).toHaveLength(0); | ||
| }); | ||
| }); |
| export {}; |
| var __extends = (this && this.__extends) || (function () { | ||
| var extendStatics = function (d, b) { | ||
| extendStatics = Object.setPrototypeOf || | ||
| ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
| function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
| return extendStatics(d, b); | ||
| }; | ||
| return function (d, b) { | ||
| if (typeof b !== "function" && b !== null) | ||
| throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
| extendStatics(d, b); | ||
| function __() { this.constructor = d; } | ||
| d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
| }; | ||
| })(); | ||
| import * as React from 'react'; | ||
| import TestRenderer from 'react-test-renderer'; | ||
| import createPageWrapper from '../createPageWrapper'; | ||
| describe('createPageWrapper', function () { | ||
| var Page = /** @class */ (function (_super) { | ||
| __extends(Page, _super); | ||
| function Page() { | ||
| return _super !== null && _super.apply(this, arguments) || this; | ||
| } | ||
| Page.prototype.render = function () { | ||
| return React.createElement("view", null, "hi"); | ||
| }; | ||
| return Page; | ||
| }(React.Component)); | ||
| it('get Page ref', function () { | ||
| var WrappedPage = createPageWrapper(Page, ''); | ||
| var testRenderer = TestRenderer.create(React.createElement(WrappedPage, { page: null, query: {} })); | ||
| var instance = testRenderer.getInstance(); | ||
| expect(instance.pageComponentInstance).toBeInstanceOf(Page); | ||
| }); | ||
| it('get Page ref with HOC', function () { | ||
| var hoc = function (PageComponent) { | ||
| return React.forwardRef(function (_, ref) { | ||
| return React.createElement(PageComponent, { ref: ref }); | ||
| }); | ||
| }; | ||
| var WrappedPage = createPageWrapper(hoc(Page), ''); | ||
| var testRenderer = TestRenderer.create(React.createElement(WrappedPage, { page: null, query: {} })); | ||
| var instance = testRenderer.getInstance(); | ||
| expect(instance.pageComponentInstance).toBeInstanceOf(Page); | ||
| }); | ||
| it('does not pass ref to FC', function () { | ||
| var FCPage = function (props) { return React.createElement("view", null, "hi"); }; | ||
| var WrappedPage = createPageWrapper(FCPage, ''); | ||
| var testRenderer = TestRenderer.create(React.createElement(WrappedPage, { page: null, query: {} })); | ||
| var instance = testRenderer.getInstance(); | ||
| expect(instance.pageComponentInstance).toBeNull(); | ||
| }); | ||
| }); |
| export {}; |
| import * as React from 'react'; | ||
| import PluginDriver from '../PluginDriver'; | ||
| describe('PluginDriver', function () { | ||
| it('onAppConfig', function () { | ||
| var pluginDriver = new PluginDriver([ | ||
| { | ||
| onAppConfig: function (_a) { | ||
| var config = _a.config; | ||
| config.foo = 1; | ||
| return config; | ||
| }, | ||
| }, | ||
| { | ||
| onAppConfig: function (_a) { | ||
| var config = _a.config; | ||
| config.bar = 1; | ||
| return config; | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(pluginDriver.onAppConfig({})).toEqual({ foo: 1, bar: 1 }); | ||
| }); | ||
| it('onPageConfig', function () { | ||
| var pluginDriver = new PluginDriver([ | ||
| { | ||
| onPageConfig: function (_a) { | ||
| var config = _a.config; | ||
| config.foo = 1; | ||
| return config; | ||
| }, | ||
| }, | ||
| { | ||
| onPageConfig: function (_a) { | ||
| var config = _a.config, page = _a.page; | ||
| config.page = page; | ||
| return config; | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(pluginDriver.onPageConfig({ config: {}, page: 'pages/foo' })).toEqual({ foo: 1, page: 'pages/foo' }); | ||
| }); | ||
| it('onAppComponent', function () { | ||
| var App = function (props) { return props.children; }; | ||
| var wrap = function (component) { | ||
| var Wrapped = function () { return React.createElement(component); }; | ||
| Wrapped.displayName = 'Wrapped'; | ||
| return Wrapped; | ||
| }; | ||
| var pluginDriver = new PluginDriver([ | ||
| { | ||
| onAppComponent: function (_a) { | ||
| var component = _a.component; | ||
| return wrap(component); | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(pluginDriver.onAppComponent(App).displayName).toEqual('Wrapped'); | ||
| }); | ||
| it('onPageComponent', function () { | ||
| var Page = function () { return React.createElement('view'); }; | ||
| var wrap = function (component, page) { | ||
| var Wrapped = function () { return React.createElement(component); }; | ||
| Wrapped.displayName = page; | ||
| return Wrapped; | ||
| }; | ||
| var pluginDriver = new PluginDriver([ | ||
| { | ||
| onPageComponent: function (_a) { | ||
| var component = _a.component, page = _a.page; | ||
| return wrap(component, page); | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(pluginDriver.onPageComponent({ component: Page, page: 'pages/foo/index' }).displayName).toEqual('pages/foo/index'); | ||
| }); | ||
| it('onCreateHostComponent', function () { | ||
| var View = function () { return React.createElement('view'); }; | ||
| var wrap = function (component) { | ||
| var Wrapped = function () { return React.createElement(component); }; | ||
| Wrapped.displayName = 'Wrapped'; | ||
| return Wrapped; | ||
| }; | ||
| var pluginDriver = new PluginDriver([ | ||
| { | ||
| onCreateHostComponent: function (_a) { | ||
| var component = _a.component; | ||
| return wrap(component); | ||
| }, | ||
| }, | ||
| ]); | ||
| expect(pluginDriver.onCreateHostComponent(View).displayName).toEqual('Wrapped'); | ||
| }); | ||
| }); |
| export {}; |
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| var __generator = (this && this.__generator) || function (thisArg, body) { | ||
| var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
| return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
| function verb(n) { return function (v) { return step([n, v]); }; } | ||
| function step(op) { | ||
| if (f) throw new TypeError("Generator is already executing."); | ||
| while (_) try { | ||
| if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
| if (y = 0, t) op = [op[0] & 2, t.value]; | ||
| switch (op[0]) { | ||
| case 0: case 1: t = op; break; | ||
| case 4: _.label++; return { value: op[1], done: false }; | ||
| case 5: _.label++; y = op[1]; op = [0]; continue; | ||
| case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
| default: | ||
| if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
| if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
| if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
| if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
| if (t[2]) _.ops.pop(); | ||
| _.trys.pop(); continue; | ||
| } | ||
| op = body.call(thisArg, _); | ||
| } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
| if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
| } | ||
| }; | ||
| import { promisify } from '../promisify'; | ||
| describe('promisify', function () { | ||
| it('promisify api and resolve when succeed', function () { | ||
| function api(_a) { | ||
| var success = _a.success; | ||
| success('success'); | ||
| } | ||
| var promisifyAPI = promisify(api); | ||
| expect.assertions(1); | ||
| expect(promisifyAPI()).resolves.toEqual('success'); | ||
| }); | ||
| it('resolve by success param', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
| function api(_a) { | ||
| var success = _a.success; | ||
| success('success'); | ||
| } | ||
| var promisifyAPI, success; | ||
| return __generator(this, function (_a) { | ||
| switch (_a.label) { | ||
| case 0: | ||
| promisifyAPI = promisify(api); | ||
| success = jest.fn(); | ||
| return [4 /*yield*/, promisifyAPI({ | ||
| success: success, | ||
| })]; | ||
| case 1: | ||
| _a.sent(); | ||
| expect(success).toBeCalledTimes(1); | ||
| return [2 /*return*/]; | ||
| } | ||
| }); | ||
| }); }); | ||
| it('promisify api and reject when failed', function () { | ||
| function api(_a) { | ||
| var fail = _a.fail; | ||
| fail('error'); | ||
| } | ||
| var promisifyAPI = promisify(api); | ||
| expect.assertions(1); | ||
| expect(promisifyAPI()).rejects.toEqual('error'); | ||
| }); | ||
| it('reject by fail param', function () { return __awaiter(void 0, void 0, void 0, function () { | ||
| function api(_a) { | ||
| var fail = _a.fail; | ||
| fail('fail'); | ||
| } | ||
| var promisifyAPI, fail; | ||
| return __generator(this, function (_a) { | ||
| switch (_a.label) { | ||
| case 0: | ||
| promisifyAPI = promisify(api); | ||
| fail = jest.fn(); | ||
| return [4 /*yield*/, promisifyAPI({ | ||
| fail: fail, | ||
| }).catch(function (error) { | ||
| expect(error).toBe('fail'); | ||
| })]; | ||
| case 1: | ||
| _a.sent(); | ||
| expect(fail).toBeCalledTimes(1); | ||
| return [2 /*return*/]; | ||
| } | ||
| }); | ||
| }); }); | ||
| }); |
-22
| MIT License | ||
| Copyright (c) 2019 当轩 | ||
| Copyright (c) 2019 - present Weizhu <yesmeck@gmail.com> | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
91517
-22.1%67
-20.24%1798
-24.42%