crosshook 1.0.7 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +37 -6
- package/package.json +1 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -196,16 +196,47 @@ Use React state / Zustand / Redux instead.
|
|
|
196
196
|
|
|
197
197
|
## 🔷 TypeScript Usage (Optional)
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
crosshook supports global event typing via module augmentation.
|
|
200
|
+
|
|
201
|
+
This provides:
|
|
202
|
+
|
|
203
|
+
✅ Event name autocomplete
|
|
204
|
+
✅ Payload type safety
|
|
205
|
+
✅ No generics required
|
|
206
|
+
|
|
207
|
+
✅ 1. Create crosshook.d.ts
|
|
208
|
+
|
|
209
|
+
Place anywhere TypeScript can see (recommended: src/):
|
|
200
210
|
|
|
201
211
|
``` ts
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
212
|
+
// src/crosshook.d.ts
|
|
213
|
+
import "crosshook";
|
|
214
|
+
|
|
215
|
+
declare module "crosshook" {
|
|
216
|
+
interface CrosshookEvents {
|
|
217
|
+
"toast.show": { message: string };
|
|
218
|
+
"modal.open": { id: string };
|
|
219
|
+
"user.login": { userId: number };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
✅ 2. Use normally
|
|
225
|
+
|
|
226
|
+
``` ts
|
|
227
|
+
import { useRegister, call } from "crosshook";
|
|
228
|
+
|
|
229
|
+
// Listener
|
|
230
|
+
useRegister("toast.show", (payload) => {
|
|
231
|
+
// payload is typed as { message: string }
|
|
232
|
+
console.log(payload.message);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// Caller
|
|
236
|
+
call("toast.show", { message: "Hello!" });
|
|
237
|
+
// 👆 TypeScript error if payload wrong
|
|
206
238
|
```
|
|
207
239
|
|
|
208
|
-
(Advanced typed helpers coming soon)
|
|
209
240
|
|
|
210
241
|
------------------------------------------------------------------------
|
|
211
242
|
|