Skip to content

Commit

Permalink
build: commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticsoul committed Dec 6, 2023
1 parent 53cd624 commit c17c122
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 31 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "helux",
"version": "3.4.24",
"version": "3.4.25",
"description": "A state library core that integrates atom, signal, collection dep, derive and watch, it supports all react like frameworks( including react 18 ).",
"keywords": [],
"author": {
Expand All @@ -10,7 +10,6 @@
},
"main": "index.js",
"scripts": {
"limu": "pnpm i limu@latest --filter @helux/core",
"build": "turbo run build",
"build:watch": "turbo run build:watch",
"build_devtool": "pnpm --filter=helux-devtool run build",
Expand All @@ -20,6 +19,7 @@
"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",
"limu": "pnpm i limu@latest --filter @helux/core",
"prepare": "husky install",
"release:all": "changeset publish",
"release:auto": "pnpm build && pnpm version:all && pnpm release:all && pnpm sync",
Expand Down
9 changes: 7 additions & 2 deletions packages/helux-core/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { limuUtils, produce } from 'limu';
import { EVENT_NAME, RECORD_LOADING } from './consts/user';
import * as limu from 'limu';
import { EVENT_NAME, RECORD_LOADING, VER, LIMU_VER } from './consts/user';
import { getAtom, isAtom, isDerivedAtom } from './factory/common/atom';
import { addMiddleware } from './factory/common/middleware';
import { addPlugin } from './factory/common/plugin';
Expand All @@ -23,6 +23,7 @@ import { useAtom, useShared } from './hooks/useShared';
import { useWatch } from './hooks/useWatch';
import { block, dynamicBlock, signal } from './signal';

const { limuUtils, produce } = limu;
const { shallowCompare, isDiff } = limuUtils;
const createShared = share; // for compatible wit v2 helux
const $ = signal; // signal api alias
Expand Down Expand Up @@ -93,4 +94,8 @@ export {
addPlugin,
EVENT_NAME,
RECORD_LOADING,
VER,
LIMU_VER,
// reexport limu
limu,
};
6 changes: 1 addition & 5 deletions packages/helux-core/src/consts/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { createSymbol, HAS_SYMBOL } from '../helpers/sym';
export { EVENT_NAME, FROM, RECORD_LOADING } from './user';
export { EVENT_NAME, FROM, RECORD_LOADING, VER, LIMU_VER } from './user';
export { HAS_SYMBOL };

export const VER = '3.4.24';

export const PROD_FLAG = true;

export const PROTO_KEY = '__proto__';

export const FN_KEY = createSymbol('HeluxFnKey');
Expand Down
6 changes: 6 additions & 0 deletions packages/helux-core/src/consts/user.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { VER as limuVer } from 'limu';

export const VER = '3.4.25';

export const LIMU_VER = limuVer;

/** 可按需注册更多的事件名并实现,方便插件收集更多的运行时数据做对应分析 */
export const EVENT_NAME = {
ON_DATA_CHANGED: 'ON_DATA_CHANGED',
Expand Down
16 changes: 11 additions & 5 deletions packages/helux-core/src/factory/common/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@ export function getInternalMap() {

/**
* for hot reload
* see window.__HELUX__.help.shared.INTERMAL_MAP
* see window.__HELUX__.ctx.shared.INTERMAL_MAP
*/
export function clearInternal(moduleName: string, loc: string) {
if (!moduleName || !isDebug() || !loc) return;
const map = getInternalMap();
const { INTERMAL_MAP, SHARED_KEY_STATE_MAP, STATE_SHARED_KEY_MAP } = getSharedScope();
let matchedKeys: number[] = [];
let cleared = false;
map.forEach((item) => {
INTERMAL_MAP.forEach((item) => {
if (item.moduleName === moduleName && item.loc === loc) {
matchedKeys.push(item.sharedKey);
}
});

// 清除第一个即可
if (matchedKeys.length > 1) {
Reflect.deleteProperty(map, matchedKeys[0]);
cleared = true;
const key = matchedKeys[0];
const prev = INTERMAL_MAP.get(key);
INTERMAL_MAP.delete(key);
if (prev) {
SHARED_KEY_STATE_MAP.delete(prev.sharedKey);
STATE_SHARED_KEY_MAP.delete(prev.rawState);
}
}

return cleared;
Expand Down
4 changes: 2 additions & 2 deletions packages/helux-core/src/factory/common/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getVal, isDebug, isFn, isObj, isProxyAvailable, prefixValKey, isMap, noop } from '@helux/utils';
import { getVal, isDebug, isFn, isMap, isObj, isProxyAvailable, noop, prefixValKey } from '@helux/utils';
import { immut, IOperateParams } from 'limu';
import { KEY_SPLITER, STATE_TYPE, MAP, ARR } from '../../consts';
import { ARR, KEY_SPLITER, MAP, STATE_TYPE } from '../../consts';
import { createOb } from '../../helpers/obj';
import type { Dict, ISetStateOptions, NumStrSymbol, TriggerReason } from '../../types/base';
import { DepKeyInfo } from '../../types/inner';
Expand Down
3 changes: 3 additions & 0 deletions packages/helux-core/src/factory/root.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { VER as LIMU_VER } from 'limu';
import { asType, safeObjGet } from '@helux/utils';
import { VER } from '../consts';
import type { Dict, Fn, IBlockCtx, IFnCtx, IPlugin, IUnmountInfo, LoadingState, Middleware, NumStrSymbol } from '../types/base';
Expand Down Expand Up @@ -70,6 +71,7 @@ function buildSharedScope() {
return {
keySeed: 0, // for sharedKey
SHARED_KEY_STATE_MAP: new Map<number, Dict>(),
/** rawState to sharedKey */
STATE_SHARED_KEY_MAP: new Map<any, number>(),
/** sharedKey to internal */
INTERMAL_MAP: new Map<number, TInternal>(),
Expand Down Expand Up @@ -103,6 +105,7 @@ function buildEventBus() {
export function createRoot() {
const root = {
VER,
LIMU_VER,
rootState: {} as Dict,
setState: (moduleName: string, partialState: Dict) => {
const modData = root.ctx.mod[moduleName];
Expand Down
6 changes: 3 additions & 3 deletions packages/helux-core/src/helpers/insCtx.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { delListItem, enureReturnArr, isFn, isSymbol, nodupPush, prefixValKey, warn } from '@helux/utils';
import { immut, limuUtils, IOperateParams } from 'limu';
import { immut, limuUtils } from 'limu';
import { DICT, EXPIRE_MS, IS_DERIVED_ATOM, KEY_SPLITER, NOT_MOUNT, OTHER, RENDER_END, RENDER_START } from '../consts';
import { hasRunningFn } from '../factory/common/fnScope';
import { genInsKey } from '../factory/common/key';
import { cutDepKeyByStop, recordArrKey } from '../factory/common/stopDep';
import { callOnRead, newOpParams, isArrLikeVal, isArrLike } from '../factory/common/util';
import { callOnRead, isArrLike, isArrLikeVal, newOpParams } from '../factory/common/util';
import type { InsCtxDef } from '../factory/creator/buildInternal';
import { mapGlobalId } from '../factory/creator/globalId';
import type { Dict, Ext, IFnCtx, IUseSharedStateOptions } from '../types/base';
Expand Down Expand Up @@ -192,7 +192,7 @@ export function buildInsCtx(options: Ext<IUseSharedStateOptions>): InsCtxDef {
}
if (
!isValArrLike
|| (!isParentArrLike && arrDep) // 值是数组或 Map 时,开启了 arrDep 才记录
|| (!isParentArrLike && arrDep) // 值是数组或 Map 时,开启了 arrDep 才记录
) {
doRecord();
}
Expand Down
3 changes: 1 addition & 2 deletions packages/helux-core/src/helpers/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,5 @@ export function recordMod(sharedState: Dict, options: ParsedOptions) {
}
// may hot replace for dev mode or add new mod
rootState[usefulName] = sharedState;
const internal = getInternal(sharedState);
ctx.mod[usefulName] = { setState: internal.setState };
ctx.mod[usefulName] = getInternal(sharedState);
}
12 changes: 10 additions & 2 deletions packages/helux-core/src/types/api.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
|------------------------------------------------------------------------------------------------
| helux-core@3.1.2
| helux-core@3.4.25
| A state library core that integrates atom, signal, collection dep, derive and watch,
| it supports all react like frameworks.
| it supports all react like frameworks ( including react 18 ).
|------------------------------------------------------------------------------------------------
*/
import type { MutableRefObject, ReactNode } from '@helux/types';
Expand Down Expand Up @@ -70,6 +70,14 @@ import type {
SyncFnBuilder,
WatchOptionsType,
} from './base';
import * as limuMod from 'limu';

export declare const VER: '3.4.25';

export declare const LIMU_VER: string;

// reexport limu
export declare const limu: typeof limuMod;

export declare const EVENT_NAME: {
ON_DATA_CHANGED: 'ON_DATA_CHANGED';
Expand Down
4 changes: 2 additions & 2 deletions packages/helux/__tests__/hook-options/arrDep.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { atom, share, useAtom, useShared } from '../helux';
import { atom, useAtom, share, useShared } from '../helux';
import { makeTest } from './arrDep.make';

makeTest({ label: 'useAtom', atom, useAtom });

// makeTest({ label: 'useShared', atom: share as any, useAtom: useShared as any });
makeTest({ label: 'useShared', atom: share as any, useAtom: useShared as any });
6 changes: 5 additions & 1 deletion packages/helux/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,9 @@ export const {
addMiddleware,
addPlugin,
EVENT_NAME,
LOADING_MODE,
RECORD_LOADING,
VER,
LIMU_VER,
// reexport limu
limu,
} = api;
2 changes: 1 addition & 1 deletion packages/helux/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfig } from 'vite';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
// latest total test case count: 209
// latest total test case count: 225
test: {
globals: true,
environment: 'jsdom',
Expand Down
8 changes: 6 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

## desc

```
npm run test
```

test files are under [packages/helux/__tests__](../packages/helux/__tests__)
test files are under [packages/helux/**tests**](../packages/helux/__tests__)

0 comments on commit c17c122

Please sign in to comment.