Skip to content

Commit

Permalink
feat: format
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticsoul committed Nov 25, 2023
1 parent be39c42 commit f67d04d
Show file tree
Hide file tree
Showing 50 changed files with 447 additions and 367 deletions.
7 changes: 2 additions & 5 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works with multi-package repos, or single-package repos to help you version and publish your code. You can find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
We have a quick list of common questions to get you started engaging with this project in [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ jobs:
run: rm pnpm-lock.yaml

- name: Install pnpm
run:
npm install -g pnpm
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

- 接入 `vitest`

- `block` 模块重构,支持热更新,支持传入ref,支持回调里使用其他钩子函数
- `block` 模块重构,支持热更新,支持传入 ref,支持回调里使用其他钩子函数
6 changes: 4 additions & 2 deletions PUB.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

### 直接发布

1. `pnpm run build`

2. `pnpm publish -r`

### changeset 发布

使用 changeset 分以下几步:

1. 当代码变更后,执行 `pnpm changeset` ,会让你输入选择变更的包和输入变更日志.
>变更日志会临时保存在.changeset文件夹中,如果输入了也可以再手工修改合并

> 变更日志会临时保存在.changeset 文件夹中,如果输入了也可以再手工修改合并
2. 发布前执行 `pnpm changeset version` ,会在每一个包下生成 CHANGELOG,并且会自动升级版本。

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
"build:watch": "turbo run build:watch",
"build_devtool": "pnpm --filter=helux-devtool run build",
"build_helux": "pnpm --filter=helux run build",
"changeset": "changeset",
"commitlint": "commitlint -e $HUSKY_GIT_PARAMS",
"cpdoc": "rm -rf ../my-opensource/helux-gh-pages/* && cp -r ./doc/build/* ../my-opensource/helux-gh-pages",
"doc": "pnpm --filter=hel-doc run build && npm run cpdoc",
"format": "prettier --cache --write . '!./pnpm-lock.yaml' '!./doc/src/components' --ignore-path .gitignore --ignore-unknown",
"prepare": "husky install",
"release:auto": "pnpm build && pnpm version:all && pnpm release:all && pnpm sync",
"changeset": "changeset",
"release:all": "changeset publish",
"version:all": "changelog version",
"sync": "cnpm sync helux && cnpm sync @helux/core && cnpm sync @helux/hooks && cnpm sync @helux/hooks-impl && cnpm sync @helux/types && cnpm sync @helux/utils"
"release:auto": "pnpm build && pnpm version:all && pnpm release:all && pnpm sync",
"sync": "cnpm sync helux && cnpm sync @helux/core && cnpm sync @helux/hooks && cnpm sync @helux/hooks-impl && cnpm sync @helux/types && cnpm sync @helux/utils",
"version:all": "changelog version"
},
"lint-staged": {
"*.{js,jsx,less,md,json}": [
Expand Down
4 changes: 1 addition & 3 deletions packages/README
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ helux: 适配 react 的库( 基于 helux-core )

helux-core: 核心逻辑库( 基于 limu )



### types 配置

packages.json 里的 `types` 值统一由 `dist/index.d.ts` 改为 `src/index.d.ts`,是因为每次构建后dist重新生成导致VSC 类型索引会失效,需要重启`ts server`,而执行稳定的`src/index.d.ts` 无此问题,但同时为了方便用户可以在dist目录看到类型文件,构建时会复制一份过去。
packages.json 里的 `types` 值统一由 `dist/index.d.ts` 改为 `src/index.d.ts`,是因为每次构建后 dist 重新生成导致 VSC 类型索引会失效,需要重启`ts server`,而执行稳定的`src/index.d.ts` 无此问题,但同时为了方便用户可以在 dist 目录看到类型文件,构建时会复制一份过去。
4 changes: 2 additions & 2 deletions packages/helux-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"src": "dist/index.d.ts",
"files": [
"dist",
"src",
Expand All @@ -45,5 +44,6 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"deprecated": false
"deprecated": false,
"src": "dist/index.d.ts"
}
1 change: 0 additions & 1 deletion packages/helux-core/src/factory/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export function isValChanged(internal: TInternal, depKey: string) {
}

if (depKey === rootValKey) {

}

const { keyPath } = getDepKeyInfo(depKey);
Expand Down
7 changes: 2 additions & 5 deletions packages/helux-core/src/factory/createWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { parseWatchOptions } from './creator/parse';

interface ICreateWatchLogicOpts<T = SharedState> {
scopeType: ScopeType;
sharedState?: T
sharedState?: T;
fnCtxBase?: IFnCtx;
immediate?: boolean;
deps?: Fn;
Expand All @@ -31,10 +31,7 @@ function putSharedToDep(list: any[]) {
}
}

export function createWatchLogic<T = SharedState>(
watchFn: (fnParams: IWatchFnParams) => void,
options: ICreateWatchLogicOpts<T>,
) {
export function createWatchLogic<T = SharedState>(watchFn: (fnParams: IWatchFnParams) => void, options: ICreateWatchLogicOpts<T>) {
const { scopeType, fnCtxBase, immediate, deps = noop, manualDepKeys, label = 'watch' } = options;
if (!isFn(watchFn)) {
throw new Error(`ERR_NON_FN: pass an non-function to ${label}!`);
Expand Down
4 changes: 2 additions & 2 deletions packages/helux-core/src/factory/creator/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import type { CoreApiCtx } from '../../types/api-ctx';
import type {
AtomMutateFnStdDict,
AtomMutateFnStdItem,
BlockOptionsType,
Dict,
IBlockOptions,
ICreateOptions,
IInnerCreateOptions,
IRuleConf,
Expand All @@ -22,8 +24,6 @@ import type {
NumStrSymbol,
WatchDepFn,
WatchOptionsType,
BlockOptionsType,
IBlockOptions,
} from '../../types/base';
import { genFnKey } from '../common/key';
import { getDepKeyByPath, tryGetLoc } from '../common/util';
Expand Down
2 changes: 1 addition & 1 deletion packages/helux-core/src/factory/creator/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { runFn } from '../../helpers/fnRunner';
import { markComputing } from '../../helpers/fnStatus';
import { runInsUpdater } from '../../helpers/insCtx';
import type { Dict, InsCtxMap } from '../../types/base';
import { diffVal, clearDiff } from '../common/sharedScope';
import { clearDiff, diffVal } from '../common/sharedScope';
import type { InsCtxDef } from './buildInternal';
import type { ICommitStateOptions } from './commitState';
import { getGlobalEmptyInternal, getGlobalIdInsKeys } from './globalId';
Expand Down
19 changes: 10 additions & 9 deletions packages/helux-core/src/hooks/common/useWatchLogic.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { noop, getVal } from '@helux/utils';
import { FnVoid } from '@helux/types';
import { getVal, noop } from '@helux/utils';
import { MOUNTED, SCOPE_TYPE } from '../../consts';
import { getDepKeyInfo } from '../../factory/common/util';
import { createWatchLogic } from '../../factory/createWatch';
import { parseWatchOptions } from '../../factory/creator/parse';
import { getDepKeyInfo } from '../../factory/common/util';
import { buildFnCtx, delFnCtx } from '../../helpers/fnCtx';
import { getSharedState } from '../../helpers/state';
import { recoverDep } from '../../helpers/fnDep';
import { getSharedState } from '../../helpers/state';
import type { CoreApiCtx } from '../../types/api-ctx';
import type { Fn, IWatchOptions, WatchOptionsType, IFnCtx } from '../../types/base';
import type { Fn, IFnCtx, IWatchOptions, WatchOptionsType } from '../../types/base';

const { HOOK } = SCOPE_TYPE;
interface ISimpleWatchOptions extends IWatchOptions {
Expand All @@ -35,11 +35,12 @@ export function useWatchSimpleLogic(apiCtx: CoreApiCtx, watchFn: Fn, options: IS
if (fnCtx.fn === noop) {
const { manualDepKeys = [] } = options;
// replay get logic for transfering deps
const deps = () => manualDepKeys.map((depKey) => {
const { sharedKey, keyPath } = getDepKeyInfo(depKey);
const state = getSharedState(sharedKey);
return getVal(state, keyPath);
});
const deps = () =>
manualDepKeys.map((depKey) => {
const { sharedKey, keyPath } = getDepKeyInfo(depKey);
const state = getSharedState(sharedKey);
return getVal(state, keyPath);
});
createWatchLogic(watchFn, { scopeType: HOOK, fnCtxBase: fnCtx, deps });
}
useFnCtxEffect(useEffect, fnCtx);
Expand Down
5 changes: 2 additions & 3 deletions packages/helux-core/src/signal/common/blockLogic.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ForwardedRef } from '@helux/types';
import { noop } from '@helux/utils';
import { initBlockCtx } from '../../helpers/blockCtx';
import { parseBlockOptions } from '../../factory/creator/parse';
import { initBlockCtx } from '../../helpers/blockCtx';
import type { CoreApiCtx } from '../../types/api-ctx';
import type { BlockCb, IBlockOptions, IBlockCtx, BlockOptionsType } from '../../types/base';
import type { BlockCb, BlockOptionsType, IBlockCtx, IBlockOptions } from '../../types/base';
import { useDelBlockCtxEffect, useDep } from './hook';
import { makeBlockComp, markBlockAndRunCb, renderResult } from './util';

Expand Down Expand Up @@ -79,7 +79,6 @@ export function blockStatusLogic<P = object>(innerOptions: IBlockLogicOptions<P>
);
}


/**
* 用户在组件里调用,推荐使用 dynamicBlock 替代 block
* 如果非要在组件里使用 block 生成组件,也能正常工作,但会额外占用一些不会释放的内存
Expand Down
12 changes: 8 additions & 4 deletions packages/helux-core/src/signal/common/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import type { CoreApiCtx } from '../../types/api-ctx';
import type { Fn, IBlockCtx, LoadingStatus } from '../../types/base';

export function useStateDep(apiCtx: CoreApiCtx, blockCtx: IBlockCtx, forceUpdate: Fn) {
useWatchSimpleLogic(apiCtx, () => {
forceUpdate();
}, { manualDepKeys: blockCtx.depKeys });
useWatchSimpleLogic(
apiCtx,
() => {
forceUpdate();
},
{ manualDepKeys: blockCtx.depKeys },
);
}

export function useDep(apiCtx: CoreApiCtx, blockCtx: IBlockCtx, forceUpdate: Fn) {
Expand All @@ -34,7 +38,7 @@ export function useDelBlockCtxEffect(apiCtx: CoreApiCtx, blockCtx: IBlockCtx, is
markBlockMounted(blockCtx);
}
return () => {
delBlockCtx(blockCtx.key, isDynamic)
delBlockCtx(blockCtx.key, isDynamic);
};
// here ignore isDynamic
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
4 changes: 2 additions & 2 deletions packages/helux-core/src/signal/common/util.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ForwardedRef } from '@helux/types';
import { noopArgs, noop, isDebug, has } from '@helux/utils';
import { has, isDebug, noop, noopArgs } from '@helux/utils';
import { IS_BLOCK } from '../../consts';
import { getAtom, isDerivedAtom } from '../../factory/common/atom';
import { markBlockFnEnd, markBlockFnStart } from '../../helpers/blockCtx';
import type { CoreApiCtx } from '../../types/api-ctx';
import type { Dict, Fn, IBlockCtx, IBlockOptions, BlockParams } from '../../types/base';
import type { Dict, Fn, IBlockCtx, IBlockOptions } from '../../types/base';
import { wrapDerivedAtomSignalComp } from './wrap';

interface IMarkBlockAndRunCbOptions {
Expand Down
4 changes: 2 additions & 2 deletions packages/helux-core/src/types/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
| it supports all react like frameworks.
|------------------------------------------------------------------------------------------------
*/
import type { MutableRefObject, ReactNode, ForwardedRef } from '@helux/types';
import type { MutableRefObject, ReactNode } from '@helux/types';
import type { Draft, GenNewStateCb, ICreateDraftOptions } from 'limu';
import type {
Action,
Expand All @@ -22,14 +22,14 @@ import type {
AtomValType,
BlockComponent,
BlockParams,
EnableStatus,
ChangeDraftCb,
DerivedAtom,
DerivedDict,
DeriveFn,
DeriveFnItem,
Dict,
EffectCb,
EnableStatus,
Fn,
IAtomCreateOptions,
IAtomCtx,
Expand Down
2 changes: 1 addition & 1 deletion packages/helux-core/src/types/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export type BlockOptionsType = EnableStatus | IBlockOptions;
*/
export type Read = <A extends readonly any[] = readonly any[]>(...args: A) => A;

export type BlockParams<P = object, T = any> = { props: P, status: LoadingStatus; read: Read, ref?: ForwardedRef<T> };
export type BlockParams<P = object, T = any> = { props: P; status: LoadingStatus; read: Read; ref?: ForwardedRef<T> };

export type BlockCb<P = object, T = any> = (props: P, params?: BlockParams<T>) => ReactNode;

Expand Down
4 changes: 2 additions & 2 deletions packages/helux-fre/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"src": "dist/index.d.ts",
"files": [
"dist",
"src",
Expand All @@ -41,5 +40,6 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"deprecated": false
"deprecated": false,
"src": "dist/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/helux-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"src": "dist/index.d.ts",
"files": [
"dist",
"src",
Expand Down Expand Up @@ -50,5 +49,6 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"deprecated": false
"deprecated": false,
"src": "dist/index.d.ts"
}
4 changes: 2 additions & 2 deletions packages/helux-hooks/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'tsup';
import ep from 'esbuild-plugin-external-global';
import { defineConfig } from 'tsup';

const { externalGlobalPlugin } = ep;

Expand All @@ -17,7 +17,7 @@ export default defineConfig([
globalName: 'HeluxHooks',
esbuildPlugins: [
externalGlobalPlugin({
'react': 'window.React',
react: 'window.React',
}),
],
},
Expand Down
1 change: 0 additions & 1 deletion packages/helux-utils/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* this lib export helux utils
*/
Expand Down
Loading

0 comments on commit f67d04d

Please sign in to comment.