Skip to content

Commit

Permalink
fix: scenario hooks to be compatible with react
Browse files Browse the repository at this point in the history
  • Loading branch information
JOU-amjs committed Jun 5, 2023
1 parent 2267625 commit e5dde2c
Show file tree
Hide file tree
Showing 38 changed files with 9,376 additions and 4,350 deletions.
6 changes: 0 additions & 6 deletions config/cp-dts.js

This file was deleted.

10 changes: 10 additions & 0 deletions config/cp-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const cpy = require('cpy');
const { readFileSync, writeFileSync } = require('fs');
const { resolve } = require('path');

(async () => {
// 将src/index.js修改为对应框架,并复制文件到对应框架下
const fileContent = readFileSync(resolve(__dirname, '../src/index.js'));
writeFileSync(resolve('./index.js'), fileContent.toString().replace('{framework}', process.env.FW));
await cpy(resolve(__dirname, '../typings/**'), resolve('./typings'));
})();
2 changes: 2 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ export default {
// react
// '**/packages/scene-react/test/functions.spec.ts(x)?'
// '**/packages/scene-react/test/useRetriableRequest.spec.ts(x)?'
// '**/packages/scene-react/test/usePagination.spec.ts(x)?'
// '**/packages/scene-react/test/useSerialRequest.spec.ts(x)?'
// svelte
// '**/packages/scene-svelte/test/functions.spec.ts(x)?'
],
Expand Down
9,939 changes: 5,974 additions & 3,965 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"test": "jest",
"test:coverage": "jest --coverage",
"cp:dts": "npm run cp:dts --workspaces",
"cp:files": "npm run cp:files --workspaces",
"build": "npm run build --workspaces",
"release": "npm run release --workspaces",
"coveralls": "npm run test:coverage && coveralls < coverage/lcov.info",
Expand Down
29 changes: 23 additions & 6 deletions packages/scene-react/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { $, $$, onMounted$, upd$, useFlag$, watch$, _$, _exp$, _expBatch$ } from '@/framework/react';
import {
$,
$$,
_$,
_exp$,
_expBatch$,
onMounted$,
upd$,
useFlag$,
useMemorizedCallback$,
useRequestRefState$,
watch$
} from '@/framework/react';
import usePagination_unified from '@/hooks/pagination/usePagination';
import useSQRequest_unified from '@/hooks/silent/useSQRequest';
import useCaptcha_unified from '@/hooks/useCaptcha';
import useForm_unified from '@/hooks/useForm';
import useRetriableRequest_unified from '@/hooks/useRetriableRequest';
import { actionDelegationMiddleware as actionDelegationMiddleware_unified } from '@/middlewares/actionDelegation';

export const usePagination = (handler, config = {}) =>
usePagination_unified(handler, config, $, $$, upd$, _$, _exp$, _expBatch$, watch$);
usePagination_unified(handler, config, $, $$, upd$, _$, _exp$, _expBatch$, watch$, useFlag$, useRequestRefState$, useMemorizedCallback$);

// 已通过 hooks/silent/useSQRequest 导入测试
/* c8 ignore start */
Expand All @@ -26,14 +39,18 @@ export { filterSilentMethods, getSilentMethod } from '@/hooks/silent/virtualResp
export { default as isVData } from '@/hooks/silent/virtualResponse/isVData';
export { default as stringifyVData } from '@/hooks/silent/virtualResponse/stringifyVData';
export { default as updateStateEffect } from '@/hooks/silent/virtualResponse/updateStateEffect';
export { accessAction, actionDelegationMiddleware } from '@/middlewares/actionDelegation'; // 导出actionDelegation中间件
export { default as useSerialRequest } from '@/hooks/useSerialRequest';
export { accessAction } from '@/middlewares/actionDelegation';

// 导出actionDelegation中间件
export const actionDelegationMiddleware = id => actionDelegationMiddleware_unified(id, useFlag$);

// 导出useCaptcha
export const useCaptcha = (handler, config = {}) => useCaptcha_unified(handler, config, $, upd$, _$, _exp$, useFlag$);
export const useCaptcha = (handler, config = {}) => useCaptcha_unified(handler, config, $, upd$, _$, _exp$, useFlag$, useMemorizedCallback$);

// 导出useForm
export const useForm = (handler, config = {}) =>
useForm_unified(handler, config, $, _$, _exp$, upd$, watch$, onMounted$, useFlag$);
useForm_unified(handler, config, $, $$, _$, _exp$, upd$, watch$, onMounted$, useFlag$, useMemorizedCallback$);

// 导出useRetriableRequest
export const useRetriableRequest = (handler, config = {}) => useRetriableRequest_unified(handler, config, useFlag$);
export const useRetriableRequest = (handler, config = {}) => useRetriableRequest_unified(handler, config, useFlag$, useMemorizedCallback$);
4 changes: 2 additions & 2 deletions packages/scene-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"unpkg": "dist/alova-scene.umd.min.js",
"scripts": {
"clean": "rimraf ./dist",
"cp:dts": "node ../../config/cp-dts.js",
"cp:files": "cross-env FW=react node ../../config/cp-files.js",
"build:esm": "cross-env NODE_ENV=development EXTENSION=reacthooks rollup -c ../../config/rollup.config.esm.js",
"build:umd": "cross-env NODE_ENV=development EXTENSION=reacthooks rollup -c ../../config/rollup.config.umd.js",
"build:umd.min": "cross-env NODE_ENV=production EXTENSION=reacthooks rollup -c ../../config/rollup.config.umd.js",
"build": "npm run clean && npm run build:esm && npm run build:umd && npm run build:umd.min && npm run cp:dts",
"build": "npm run clean && npm run cp:files && npm run build:esm && npm run build:umd && npm run build:umd.min",
"publish": "npm publish"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/scene-react/test/functions.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { $, $$, upd$, watch$, _$, _exp$, _expBatch$ } from '@/framework/react';
import { $, $$, _$, _exp$, _expBatch$, upd$, watch$ } from '@/framework/react';
import '@testing-library/jest-dom';
import { fireEvent, render, screen } from '@testing-library/react';
import React, { ReactElement } from 'react';
Expand All @@ -16,7 +16,7 @@ describe('react framework functions', () => {
<span role="pageCount">{pageCount}</span>
<button
role="btn"
onClick={() => setStateVal1(v => v + 1)}>
onClick={() => setStateVal1((v: number) => v + 1)}>
btn
</button>
<button
Expand Down
Loading

0 comments on commit e5dde2c

Please sign in to comment.