From 9b620df22c37549316e1a44428ac48f6a3c619f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Thu, 12 Jul 2018 15:46:13 +0200 Subject: [PATCH] [react-tracking] The callback variant also passes arguments. --- types/react-tracking/index.d.ts | 2 +- .../test/react-tracking-with-types-tests.tsx | 7 ++++++- .../test/react-tracking-without-types-tests.tsx | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/types/react-tracking/index.d.ts b/types/react-tracking/index.d.ts index 8117fb3336..8705a32781 100644 --- a/types/react-tracking/index.d.ts +++ b/types/react-tracking/index.d.ts @@ -50,7 +50,7 @@ interface Options { process?(ownTrackingData: T): T | Falsy; } -export type TrackingInfo = T | ((props: P, state: S) => T); +export type TrackingInfo = T | ((props: P, state: S, args: any[any]) => T); // Duplicated from ES6 lib to remove the `void` typing, otherwise `track` can’t be used as a HOC function that passes // through a JSX component that be used without casting. diff --git a/types/react-tracking/test/react-tracking-with-types-tests.tsx b/types/react-tracking/test/react-tracking-with-types-tests.tsx index 76c9ccb5b5..a840216af0 100644 --- a/types/react-tracking/test/react-tracking-with-types-tests.tsx +++ b/types/react-tracking/test/react-tracking-with-types-tests.tsx @@ -30,10 +30,15 @@ class ClassPage extends React.Component { // ... other stuff } + @track((_props, _state, [e]: [React.MouseEvent]) => ({ event: `drag started at ${e.screenX}x${e.screenY}` })) + handleDrag(event: React.MouseEvent) { + // no-op + } + @track((props, state) => ({ event: `got ${props.someProp} and clicked ${state.isClicked}` })) render() { return ( - ); diff --git a/types/react-tracking/test/react-tracking-without-types-tests.tsx b/types/react-tracking/test/react-tracking-without-types-tests.tsx index 02a89d929c..a3cf2b4330 100644 --- a/types/react-tracking/test/react-tracking-without-types-tests.tsx +++ b/types/react-tracking/test/react-tracking-without-types-tests.tsx @@ -14,6 +14,11 @@ class ClassPage extends React.Component { // ... other stuff } + @track((_props, _state, [e]) => ({ event: `drag started at ${e.screenX}x${e.screenY}` })) + handleDrag(event: any) { + // no-op + } + // Only need to cast this to `any` because the settings for this project is to disallow implicit `any`. @track((props: any, state: any) => ({ event: `got ${props.someProp} and clicked ${state.isClicked}` })) render() {