Skip to content

Commit

Permalink
feat: add helux-openinula
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticsoul committed Jan 10, 2024
1 parent 3fa9351 commit af1d573
Show file tree
Hide file tree
Showing 11 changed files with 522 additions and 87 deletions.
10 changes: 10 additions & 0 deletions packages/helux-openinula/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
modules: false,
},
],
],
};
11 changes: 11 additions & 0 deletions packages/helux-openinula/README.md
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
3 changes: 3 additions & 0 deletions packages/helux-openinula/index.d.ts
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';
46 changes: 46 additions & 0 deletions packages/helux-openinula/package.json
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
}
70 changes: 70 additions & 0 deletions packages/helux-openinula/rollup.config.js
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;
3 changes: 3 additions & 0 deletions packages/helux-openinula/src/index.d.ts
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';
98 changes: 98 additions & 0 deletions packages/helux-openinula/src/index.ts
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;
15 changes: 15 additions & 0 deletions packages/helux-openinula/tsconfig.json
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/**/*"]
}
21 changes: 21 additions & 0 deletions packages/helux-openinula/tsup.config.ts
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',
}),
],
},
]);
Loading

0 comments on commit af1d573

Please sign in to comment.