Skip to content

Commit 82fa8dd

Browse files
author
kirillbaldin
committed
chore(stories): add Todo workspace and User management examples; update Cleanup advanced story with renamed props and restructured code
1 parent 416008c commit 82fa8dd

11 files changed

Lines changed: 123 additions & 34 deletions

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ disposeTimeout();
3737
disposeReaction();
3838
```
3939

40+
Each public utility is also available as a package subpath:
41+
42+
```ts
43+
import { cleanupReaction } from "@meded90/cleanup/cleanupReaction";
44+
import { cleanupTimeout } from "@meded90/cleanup/cleanupTimeout";
45+
```
46+
4047
## API
4148

4249
- [`cleanupReaction`](./src/cleanup/cleanupReaction.ts)
@@ -54,7 +61,6 @@ disposeReaction();
5461
- [`cleanupRequestAnimationFrame`](./src/cleanup/cleanupRequestAnimationFrame.ts)
5562
- [`cleanupIdleCallback`](./src/cleanup/cleanupIdleCallback.ts)
5663

57-
5864
## Scripts
5965

6066
- `pnpm dev` - starts Storybook locally on port 6007.

package.json

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
},
2424
"files": [
2525
"dist",
26+
"src/**/*.ts",
27+
"src/**/*.d.ts",
28+
"!src/**/*.doc.mdx",
29+
"!src/**/*.stories.tsx",
30+
"!src/**/*.test.ts",
2631
"README.md",
2732
"LICENSE"
2833
],
@@ -37,6 +42,76 @@
3742
"import": "./dist/index.js",
3843
"require": "./dist/index.cjs"
3944
},
45+
"./cleanupAutorun": {
46+
"types": "./dist/cleanup/cleanupAutorun.d.ts",
47+
"import": "./dist/cleanupAutorun.js",
48+
"require": "./dist/cleanupAutorun.cjs"
49+
},
50+
"./cleanupBodyEventListener": {
51+
"types": "./dist/cleanup/cleanupEventListener.d.ts",
52+
"import": "./dist/cleanupEventListener.js",
53+
"require": "./dist/cleanupEventListener.cjs"
54+
},
55+
"./cleanupDocumentEventListener": {
56+
"types": "./dist/cleanup/cleanupEventListener.d.ts",
57+
"import": "./dist/cleanupEventListener.js",
58+
"require": "./dist/cleanupEventListener.cjs"
59+
},
60+
"./cleanupEventListener": {
61+
"types": "./dist/cleanup/cleanupEventListener.d.ts",
62+
"import": "./dist/cleanupEventListener.js",
63+
"require": "./dist/cleanupEventListener.cjs"
64+
},
65+
"./cleanupIdleCallback": {
66+
"types": "./dist/cleanup/cleanupIdleCallback.d.ts",
67+
"import": "./dist/cleanupIdleCallback.js",
68+
"require": "./dist/cleanupIdleCallback.cjs"
69+
},
70+
"./cleanupInterval": {
71+
"types": "./dist/cleanup/cleanupInterval.d.ts",
72+
"import": "./dist/cleanupInterval.js",
73+
"require": "./dist/cleanupInterval.cjs"
74+
},
75+
"./cleanupReaction": {
76+
"types": "./dist/cleanup/cleanupReaction.d.ts",
77+
"import": "./dist/cleanupReaction.js",
78+
"require": "./dist/cleanupReaction.cjs"
79+
},
80+
"./cleanupReactionList": {
81+
"types": "./dist/cleanup/cleanupReactionList.d.ts",
82+
"import": "./dist/cleanupReactionList.js",
83+
"require": "./dist/cleanupReactionList.cjs"
84+
},
85+
"./cleanupReactionMap": {
86+
"types": "./dist/cleanup/cleanupReactionMap.d.ts",
87+
"import": "./dist/cleanupReactionMap.js",
88+
"require": "./dist/cleanupReactionMap.cjs"
89+
},
90+
"./cleanupReactionPrimitiveList": {
91+
"types": "./dist/cleanup/cleanupReactionPrimitiveList.d.ts",
92+
"import": "./dist/cleanupReactionPrimitiveList.js",
93+
"require": "./dist/cleanupReactionPrimitiveList.cjs"
94+
},
95+
"./cleanupRequestAnimationFrame": {
96+
"types": "./dist/cleanup/cleanupRequestAnimationFrame.d.ts",
97+
"import": "./dist/cleanupRequestAnimationFrame.js",
98+
"require": "./dist/cleanupRequestAnimationFrame.cjs"
99+
},
100+
"./cleanupSelectorEventListener": {
101+
"types": "./dist/cleanup/cleanupEventListener.d.ts",
102+
"import": "./dist/cleanupEventListener.js",
103+
"require": "./dist/cleanupEventListener.cjs"
104+
},
105+
"./cleanupTimeout": {
106+
"types": "./dist/cleanup/cleanupTimeout.d.ts",
107+
"import": "./dist/cleanupTimeout.js",
108+
"require": "./dist/cleanupTimeout.cjs"
109+
},
110+
"./cleanupWindowEventListener": {
111+
"types": "./dist/cleanup/cleanupEventListener.d.ts",
112+
"import": "./dist/cleanupEventListener.js",
113+
"require": "./dist/cleanupEventListener.cjs"
114+
},
40115
"./package.json": "./package.json"
41116
},
42117
"publishConfig": {
@@ -47,7 +122,7 @@
47122
"dev": "storybook dev -p 6007",
48123
"storybook": "storybook dev -p 6007",
49124
"storybook:build": "STORYBOOK_DOCS_WATCH=0 storybook build -c .storybook -o storybook-static",
50-
"build": "pnpm run build:types && vp build --config vite.config.ts",
125+
"build": "rm -rf dist && pnpm run build:types && vp build --config vite.config.ts",
51126
"build:types": "tsc -p tsconfig.build.json",
52127
"typecheck": "tsc -p tsconfig.json --noEmit",
53128
"test": "vp test --config vitest.config.ts --run",

src/cleanup/cleanupEventListener.doc.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { Meta } from '@storybook/blocks';
2424
#### Source Code:
2525

2626
```ts
27-
export default function cleanupEventListener<Type extends Element | HTMLDivElement | Window | Document | null, Key extends Type extends Window ? keyof WindowEventMap : Type extends Document ? keyof DocumentEventMap : keyof HTMLElementEventMap>(type: Key, func: (event: any | void) => Disposer, ref: RefLike<Type> | Type | null, options?: boolean | AddEventListenerOptions) {
27+
export function cleanupEventListener<Type extends Element | HTMLDivElement | Window | Document | null, Key extends Type extends Window ? keyof WindowEventMap : Type extends Document ? keyof DocumentEventMap : keyof HTMLElementEventMap>(type: Key, func: (event: any | void) => Disposer, ref: RefLike<Type> | Type | null, options?: boolean | AddEventListenerOptions) {
2828
let current: Type | null = null;
2929
if (!ref) {
3030
return () => { };

src/cleanup/cleanupEventListener.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { isFunction } from "lodash";
1+
import lodash from "lodash";
22

33
import { Disposer } from "../types/disposer";
44

5+
const { isFunction } = lodash;
6+
57
type RefLike<Type> = {
68
readonly current: Type | null;
79
};
@@ -17,7 +19,7 @@ type RefLike<Type> = {
1719
* @param options - addEventListener options.
1820
* @returns function for removing the listener and running cleanup.
1921
*/
20-
export default function cleanupEventListener<
22+
export function cleanupEventListener<
2123
Type extends Element | HTMLDivElement | Window | Document | null,
2224
Key extends Type extends Window
2325
? keyof WindowEventMap
@@ -115,3 +117,5 @@ export function cleanupSelectorEventListener<E extends keyof HTMLElementEventMap
115117
) {
116118
return cleanupEventListener<Element, E>(type, func, document.querySelector(selector), options);
117119
}
120+
121+
export default cleanupEventListener;

src/cleanup/cleanupIdleCallback.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { isFunction } from "lodash";
1+
import lodash from "lodash";
22
import { action } from "mobx";
33

4+
const { isFunction } = lodash;
5+
46
type IdleHandle = number | ReturnType<typeof setTimeout>;
57

68
function requestIdleCallbackSafe(

src/cleanup/cleanupInterval.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { isFunction, isString } from "lodash";
1+
import lodash from "lodash";
2+
import ms from "ms";
23

3-
import ms, { StringValue } from "../ms";
44
import { Disposer } from "../types/disposer";
5+
import { StringValue } from "../types/msStringValue";
6+
7+
const { isFunction, isString } = lodash;
58

69
/**
710
* Runs an async effect on an interval, cleaning up the previous result before the next call.

src/cleanup/cleanupRequestAnimationFrame.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { isFunction } from "lodash";
1+
import lodash from "lodash";
22

33
import { Disposer } from "../types/disposer";
44

5+
const { isFunction } = lodash;
6+
57
/**
68
* Setup/cleanup wrapper for requestAnimationFrame.
79
* On rerun, the previous frame is cancelled and its cleanup runs.

src/cleanup/cleanupTimeout.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { isFunction, isString } from "lodash";
1+
import lodash from "lodash";
22
import { action } from "mobx";
3+
import ms from "ms";
34

4-
import ms, { StringValue } from "../ms";
5+
import { StringValue } from "../types/msStringValue";
6+
7+
const { isFunction, isString } = lodash;
58

69
/**
710
* Setup/cleanup wrapper for setTimeout:

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ export type {
1919
} from "./cleanup/cleanupReactionPrimitiveList";
2020
export { cleanupRequestAnimationFrame } from "./cleanup/cleanupRequestAnimationFrame";
2121
export { cleanupTimeout } from "./cleanup/cleanupTimeout";
22-
export { default as ms } from "./ms";
23-
export type { StringValue } from "./ms";
2422
export type { Disposer, DisposerSync } from "./types/disposer";
23+
export type { StringValue } from "./types/msStringValue";

src/ms.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)