-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fa9351
commit af1d573
Showing
11 changed files
with
522 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
modules: false, | ||
}, | ||
], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# helux-preact | ||
|
||
对接 helux-core 供 `openinula` 使用的状态库 | ||
|
||
## desc | ||
|
||
[helux](https://heluxjs.github.io/helux),集原子,信号、依赖追踪为一体,支持细粒度响应式更新的状态引擎(兼容所有类react库,包括react18) | ||
|
||
## online demo | ||
|
||
https://codesandbox.io/p/devbox/helux-openinula-66gfj2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from '@helux/core/src/types/api'; | ||
export * from '@helux/core/src/types/base'; | ||
export * from '@helux/core/src/types/model'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "@helux/openinula", | ||
"version": "4.0.1", | ||
"description": "State library for preact that integrates atom, signal, collection dep, derive and watch.", | ||
"bugs": { | ||
"url": "https://github.com/heluxjs/helux/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/heluxjs/helux", | ||
"directory": "packages/helux" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "fantasticsoul", | ||
"email": "[email protected]", | ||
"url": "https://github.com/fantasticsoul" | ||
}, | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "src/index.d.ts", | ||
"files": [ | ||
"dist", | ||
"src", | ||
"README.md", | ||
"tsconfig.json" | ||
], | ||
"scripts": { | ||
"build": "tsup", | ||
"build:watch": "tsup --watch", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"dependencies": { | ||
"@helux/core": "workspace:^", | ||
"openinula": "0.1.2-SNAPSHOT" | ||
}, | ||
"peerDependencies": { | ||
"openinula": "0.1.2-SNAPSHOT" | ||
}, | ||
"bundleDependencies": [], | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
"deprecated": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import babel from 'rollup-plugin-babel'; // 支持jsx | ||
import commonjs from 'rollup-plugin-commonjs'; // 支持按commonjs规范来导入外部模块 | ||
import resolve from 'rollup-plugin-node-resolve'; // 支持内部的模块路径解析 | ||
import { uglify } from 'rollup-plugin-uglify'; | ||
import pkg from './package.json'; | ||
|
||
const external = Object.keys(pkg.peerDependencies || {}); | ||
const env = process.env.BUILD_ENV; | ||
let bundleName = pkg.name; | ||
if (bundleName.includes('/')) { | ||
const [org, name] = bundleName.split('/'); | ||
bundleName = `${org.substring(1)}-${name}`; | ||
} | ||
const globalName = 'HeluxPreact'; | ||
|
||
const env2outputConf = { | ||
commonjs: { | ||
format: 'cjs', | ||
dir: 'lib', | ||
}, | ||
es: { | ||
format: 'es', | ||
dir: 'es', | ||
}, | ||
development: { | ||
format: 'umd', | ||
file: `dist/${bundleName}.js`, | ||
name: globalName, | ||
}, | ||
production: { | ||
format: 'umd', | ||
file: `dist/${bundleName}.min.js`, | ||
name: globalName, | ||
}, | ||
}; | ||
|
||
const config = { | ||
input: 'src-js/index.js', | ||
external, | ||
output: { | ||
...env2outputConf[env], | ||
exports: 'named', | ||
globals: { | ||
preact: 'preact', | ||
'@helux/core': 'HeluxCore', | ||
}, | ||
}, | ||
plugins: [ | ||
resolve(), | ||
commonjs(), | ||
babel({ | ||
exclude: '**/node_modules/**', | ||
runtimeHelpers: true, | ||
}), | ||
], | ||
}; | ||
|
||
if (env === 'production') { | ||
config.plugins.push( | ||
uglify({ | ||
compress: { | ||
pure_getters: true, | ||
unsafe: true, | ||
unsafe_comps: true, | ||
}, | ||
}), | ||
); | ||
} | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from '@helux/core/src/types/api'; | ||
export * from '@helux/core/src/types/base'; | ||
export * from '@helux/core/src/types/model'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { initHeluxContext } from "@helux/core"; | ||
import * as React from "openinula"; | ||
|
||
console.log(React); | ||
|
||
const api = initHeluxContext({ | ||
heluxCtxKey: "__HELUX_openinula__", | ||
reactLib: React, | ||
}); | ||
|
||
/** | ||
* for compatible wit v2 helux | ||
* 这个接口仅为了兼容 helux v2 升级到 v3 后不报错 | ||
*/ | ||
export const createShared = api.share; | ||
|
||
// 导出 core 所有方法,类型由 index.d.ts 提供(见 package.json 的 types 配置) | ||
export const { | ||
atom, | ||
atomx, | ||
share, | ||
sharex, | ||
// derive api | ||
derive, | ||
deriveDict, | ||
defineDeriveTask, | ||
defineDeriveFnItem, | ||
runDerive, | ||
runDeriveTask, | ||
// watch api | ||
watch, | ||
watchEffect, | ||
// hooks api | ||
useAtom, | ||
useAtomX, | ||
useReactive, | ||
useReactiveX, | ||
useDerived, | ||
useWatch, | ||
useWatchEffect, | ||
useGlobalId, | ||
useService, | ||
useOnEvent, | ||
useMutable, | ||
useMutateLoading, | ||
useActionLoading, | ||
useEffect, | ||
useLayoutEffect, | ||
useStable, | ||
useObject, | ||
useLocalForceUpdate, | ||
useGlobalForceUpdate, | ||
// action api | ||
action, | ||
// signal api | ||
signal, | ||
block, | ||
dynamicBlock, | ||
$, | ||
// mutate api | ||
mutate, | ||
mutateDict, | ||
runMutate, | ||
runMutateTask, | ||
defineMutateFnItem, | ||
// sync api | ||
sync, | ||
syncer, | ||
// model api | ||
model, | ||
modelFactory, | ||
// emit api | ||
emit, | ||
on, | ||
// init api | ||
init, | ||
// util api | ||
reactiveDesc, | ||
flush, | ||
isAtom, | ||
isSharedState, | ||
isDerivedAtom, | ||
isDerivedResult, | ||
storeSrv, | ||
shallowCompare, | ||
markRaw, | ||
isDiff, | ||
produce, | ||
getMutateLoading, | ||
getActionLoading, | ||
getDeriveLoading, | ||
getRawState, | ||
getSnap, | ||
getAtom, | ||
addMiddleware, | ||
addPlugin, | ||
cst, | ||
} = api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": true, | ||
"baseUrl": "./src", | ||
"allowJs": true, | ||
"allowSyntheticDefaultImports": true, | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"jsx": "react", | ||
"target": "esnext", | ||
"outDir": "src-js" | ||
}, | ||
"include": ["src/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import copyStaticFile from 'esbuild-copy-static-files'; | ||
import { defineConfig } from 'tsup'; | ||
export default defineConfig([ | ||
{ | ||
entry: ['src/index.ts'], | ||
format: ['esm', 'cjs'], | ||
dts: false, | ||
splitting: true, | ||
sourcemap: true, | ||
clean: true, | ||
treeshake: false, | ||
minify: 'terser', | ||
external: [], | ||
esbuildPlugins: [ | ||
copyStaticFile({ | ||
src: './src/index.d.ts', | ||
dest: './dist/index.d.ts', | ||
}), | ||
], | ||
}, | ||
]); |
Oops, something went wrong.