From f9d49356aea7f08cf7cab3c98199aae47aa757ad Mon Sep 17 00:00:00 2001 From: Nelson Javier Novoa Tellez Date: Mon, 22 Oct 2018 10:43:25 -0500 Subject: [PATCH 1/4] Expose globalHistory as @reach/router does --- types/reach__router/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/reach__router/index.d.ts b/types/reach__router/index.d.ts index 3a849dd8ee..792662027c 100644 --- a/types/reach__router/index.d.ts +++ b/types/reach__router/index.d.ts @@ -147,3 +147,5 @@ export interface RedirectRequest { export function isRedirect(error: any): error is RedirectRequest; export function redirectTo(uri: string): void; + +export const globalHistory: History; From a1f9b81264bd1c28b59eab5798f8b0ffc2d50a7d Mon Sep 17 00:00:00 2001 From: Nelson Javier Novoa Tellez Date: Mon, 22 Oct 2018 13:01:27 -0500 Subject: [PATCH 2/4] Enrich HistoryListener type adding parameters --- types/reach__router/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/reach__router/index.d.ts b/types/reach__router/index.d.ts index 792662027c..b3f0e0f582 100644 --- a/types/reach__router/index.d.ts +++ b/types/reach__router/index.d.ts @@ -15,7 +15,9 @@ export interface History { navigate: NavigateFn; } -export type HistoryListener = () => void; +export type HistoryListenerLocation = WindowLocation & { state?: any }; +export type HistoryListenerParameter = { location: HistoryListenerLocation, action: "PUSH" | "POP" }; +export type HistoryListener = (parameter: HistoryListenerParameter) => void; export type HistoryUnsubscribe = () => void; export class Router extends React.Component { } From 1340339ce960f33eb98f39ec17c07b90787edb79 Mon Sep 17 00:00:00 2001 From: Nelson Javier Novoa Tellez Date: Mon, 22 Oct 2018 15:29:23 -0500 Subject: [PATCH 3/4] Extract action types to its own type. Change Histotyl.location property type from string to HistoryLocation to be accurate to current API --- types/reach__router/index.d.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/types/reach__router/index.d.ts b/types/reach__router/index.d.ts index b3f0e0f582..65d3fb0658 100644 --- a/types/reach__router/index.d.ts +++ b/types/reach__router/index.d.ts @@ -8,18 +8,19 @@ import * as React from "react"; import { Location as HLocation } from "history"; export type WindowLocation = Window["location"] & HLocation; +export type HistoryActionType = "PUSH" | "POP"; +export type HistoryLocation = WindowLocation & { state?: any }; +export type HistoryListenerParameter = { location: HistoryLocation, action: HistoryActionType }; +export type HistoryListener = (parameter: HistoryListenerParameter) => void; +export type HistoryUnsubscribe = () => void; + export interface History { - readonly location: string; + readonly location: HistoryLocation; readonly transitioning: boolean; listen: (listener: HistoryListener) => HistoryUnsubscribe; navigate: NavigateFn; } -export type HistoryListenerLocation = WindowLocation & { state?: any }; -export type HistoryListenerParameter = { location: HistoryListenerLocation, action: "PUSH" | "POP" }; -export type HistoryListener = (parameter: HistoryListenerParameter) => void; -export type HistoryUnsubscribe = () => void; - export class Router extends React.Component { } export interface RouterProps { From 2b22bc81f45408e087bb6af6d74cda281ff3aaba Mon Sep 17 00:00:00 2001 From: Nelson Javier Novoa Tellez Date: Mon, 22 Oct 2018 15:42:25 -0500 Subject: [PATCH 4/4] Change HistoryListenerParameter from type to interface --- types/reach__router/index.d.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/types/reach__router/index.d.ts b/types/reach__router/index.d.ts index 65d3fb0658..60b1c6253e 100644 --- a/types/reach__router/index.d.ts +++ b/types/reach__router/index.d.ts @@ -10,7 +10,10 @@ export type WindowLocation = Window["location"] & HLocation; export type HistoryActionType = "PUSH" | "POP"; export type HistoryLocation = WindowLocation & { state?: any }; -export type HistoryListenerParameter = { location: HistoryLocation, action: HistoryActionType }; +export interface HistoryListenerParameter { + location: HistoryLocation; + action: HistoryActionType; +} export type HistoryListener = (parameter: HistoryListenerParameter) => void; export type HistoryUnsubscribe = () => void;