Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2024.09.14] @xionwcfm/react new version 0.0.7 release #2

Merged
merged 11 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ yarn-error.log*
# Misc
.DS_Store
*.pem

*storybook.log
26 changes: 0 additions & 26 deletions apps/storybook/.gitignore

This file was deleted.

30 changes: 0 additions & 30 deletions apps/storybook/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions apps/storybook/index.html

This file was deleted.

43 changes: 0 additions & 43 deletions apps/storybook/package.json

This file was deleted.

9 changes: 0 additions & 9 deletions apps/storybook/postcss.config.mjs

This file was deleted.

1 change: 0 additions & 1 deletion apps/storybook/public/vite.svg

This file was deleted.

30 changes: 0 additions & 30 deletions apps/storybook/src/App.tsx

This file was deleted.

4 changes: 0 additions & 4 deletions apps/storybook/src/css/index.css

This file was deleted.

9 changes: 0 additions & 9 deletions apps/storybook/src/main.tsx

This file was deleted.

1 change: 0 additions & 1 deletion apps/storybook/src/vite-env.d.ts

This file was deleted.

12 changes: 0 additions & 12 deletions apps/storybook/tailwind.config.ts

This file was deleted.

25 changes: 0 additions & 25 deletions apps/storybook/tsconfig.json

This file was deleted.

11 changes: 0 additions & 11 deletions apps/storybook/tsconfig.node.json

This file was deleted.

7 changes: 0 additions & 7 deletions apps/storybook/vite.config.ts

This file was deleted.

18 changes: 7 additions & 11 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
pre-push:
parallel: true
commands:
check:
run: pnpm run check:biome && git add .
stage_fixed: true
test:
run: pnpm run test:ci

pre-commit:
parallel: true
commands:
check:
run: pnpm run check:biome
format:
run: |
pnpm run check:biome
if ! git diff --exit-code; then
git add .
git commit -m 'format code by biome'
fi
stage_fixed: true
test:
run: pnpm run test:ci
3 changes: 2 additions & 1 deletion packages/jotai/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { defineConfig } from "tsup";

export default defineConfig({
format: ["cjs", "esm"],
entry: ["./src/index.ts"],
entry: ["./src/index.ts", "!./src/**/*.test.(ts|tsx)"],
sourcemap: true,
dts: true,
clean: true,
minify: true,
treeshake: true,
splitting: false,
});
3 changes: 2 additions & 1 deletion packages/react-query/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { defineConfig } from "tsup";

export default defineConfig({
format: ["cjs", "esm"],
entry: ["./src/*.(ts|tsx)"],
entry: ["./src/index.ts", "!./src/**/*.test.(ts|tsx)"],
sourcemap: true,
dts: true,
clean: true,
minify: true,
treeshake: true,
splitting: false,
});
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xionwcfm/react",
"version": "0.0.5",
"version": "0.0.7",
"license": "MIT",
"scripts": {
"build": "tsup",
Expand Down
38 changes: 38 additions & 0 deletions packages/react/src/create-reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Reducer, useReducer } from "react";

type ActionMap<H> = {
[K in keyof H]: H[K] extends (state: any) => any
? { type: K }
: H[K] extends (state: any, payload: infer P) => any
? { type: K; payload: P }
: never;
};

type InferState<H> = H extends { [K in keyof H]: (state: infer S, ...args: any[]) => any } ? S : never;

type ActionUnion<H> = ActionMap<H>[keyof H];

export function createReducer<H extends Record<string, (state: any, ...args: any[]) => any>>(handlers: H) {
type State = InferState<H>;
type Action = ActionUnion<H>;

const reducer: Reducer<State, Action> = (state, action) => {
const handler = handlers[action.type as keyof H];
if (handler) {
return "payload" in action ? (handler as any)(state, action.payload) : (handler as any)(state);
}
return state;
};
return reducer;
}

type Todo = { checked: boolean };

const reducer = createReducer({
addTodo: (state: Todo) => {
return state;
},
removeTodo: (state: Todo, payload: string) => {
return state;
},
});
21 changes: 21 additions & 0 deletions packages/react/src/debounce-event.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Children, ReactElement, cloneElement } from "react";
import { useDebounce } from "./use-debounce";

type Props = {
capture?: string;
children: ReactElement;
delay: number;
};

export function DebounceEvent({ capture = "onClick", children, delay }: Props) {
const child = Children.only(children);
const debouncedCallback = useDebounce((...args: any[]) => {
if (child.props && typeof child.props[capture] === "function") {
return child.props[capture](...args);
}
}, delay);

return cloneElement(child, {
[capture]: debouncedCallback,
});
}
Loading
Loading