Skip to content
This repository was archived by the owner on Nov 25, 2021. It is now read-only.

Commit a3e3dc5

Browse files
committed
refactor: rename fetch{Hover,Actions} -> get{Hover,Actions}
"get" is better than "fetch" because these no longer necessarily come from a remote source. BREAKING CHANGE: Fields were renamed: fetch{Hover,Actions} -> get{Hover,Actions}.
1 parent e0caa80 commit a3e3dc5

File tree

4 files changed

+52
-50
lines changed

4 files changed

+52
-50
lines changed

src/hoverifier.test.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from './hoverifier'
1818
import { findPositionsFromEvents, SupportedMouseEvent } from './positions'
1919
import { CodeViewProps, DOM } from './testutils/dom'
20-
import { createHoverAttachment, createStubActionsFetcher, createStubHoverFetcher } from './testutils/fixtures'
20+
import { createHoverAttachment, createStubActionsProvider, createStubHoverProvider } from './testutils/fixtures'
2121
import { dispatchMouseEventAtPositionImpure } from './testutils/mouse'
2222
import { HoverAttachment, LOADING } from './types'
2323

@@ -43,8 +43,8 @@ describe('Hoverifier', () => {
4343
closeButtonClicks: NEVER,
4444
hoverOverlayElements: of(null),
4545
hoverOverlayRerenders: EMPTY,
46-
fetchHover: createStubHoverFetcher({ range: hoverRange }, LOADER_DELAY + delayTime),
47-
fetchActions: () => of(null),
46+
getHover: createStubHoverProvider({ range: hoverRange }, LOADER_DELAY + delayTime),
47+
getActions: () => of(null),
4848
})
4949

5050
const positionJumps = new Subject<PositionJump>()
@@ -104,8 +104,8 @@ describe('Hoverifier', () => {
104104
closeButtonClicks: NEVER,
105105
hoverOverlayElements: of(null),
106106
hoverOverlayRerenders: EMPTY,
107-
fetchHover: createStubHoverFetcher(hover, delayTime),
108-
fetchActions: createStubActionsFetcher(['foo', 'bar'], delayTime),
107+
getHover: createStubHoverProvider(hover, delayTime),
108+
getActions: createStubActionsProvider(['foo', 'bar'], delayTime),
109109
})
110110

111111
const positionJumps = new Subject<PositionJump>()
@@ -193,11 +193,11 @@ describe('Hoverifier', () => {
193193
hoverOverlayElements: of(null),
194194
hoverOverlayRerenders: EMPTY,
195195
// Only show on line 24, not line 25 (which is the 2nd click event below).
196-
fetchHover: position =>
197-
position.line === 24 ? createStubHoverFetcher({}, delayTime)(position) : of(null),
198-
fetchActions: position =>
196+
getHover: position =>
197+
position.line === 24 ? createStubHoverProvider({}, delayTime)(position) : of(null),
198+
getActions: position =>
199199
position.line === 24
200-
? createStubActionsFetcher(['foo', 'bar'], delayTime)(position)
200+
? createStubActionsProvider(['foo', 'bar'], delayTime)(position)
201201
: of(null),
202202
})
203203

@@ -265,10 +265,9 @@ describe('Hoverifier', () => {
265265
hoverOverlayElements: of(null),
266266
hoverOverlayRerenders: EMPTY,
267267
// Only show on line 24, not line 25 (which is the 2nd click event below).
268-
fetchHover: position =>
269-
position.line === 24 ? createStubHoverFetcher({})(position) : of(null),
270-
fetchActions: position =>
271-
position.line === 24 ? createStubActionsFetcher(['foo', 'bar'])(position) : of(null),
268+
getHover: position => (position.line === 24 ? createStubHoverProvider({})(position) : of(null)),
269+
getActions: position =>
270+
position.line === 24 ? createStubActionsProvider(['foo', 'bar'])(position) : of(null),
272271
})
273272

274273
const positionJumps = new Subject<PositionJump>()
@@ -345,8 +344,8 @@ describe('Hoverifier', () => {
345344
closeButtonClicks: new Observable<MouseEvent>(),
346345
hoverOverlayElements: of(null),
347346
hoverOverlayRerenders: EMPTY,
348-
fetchHover: createStubHoverFetcher(hover, LOADER_DELAY + hoverDelayTime),
349-
fetchActions: createStubActionsFetcher(actions, LOADER_DELAY + actionsDelayTime),
347+
getHover: createStubHoverProvider(hover, LOADER_DELAY + hoverDelayTime),
348+
getActions: createStubActionsProvider(actions, LOADER_DELAY + actionsDelayTime),
350349
})
351350

352351
const positionJumps = new Subject<PositionJump>()
@@ -416,8 +415,8 @@ describe('Hoverifier', () => {
416415
closeButtonClicks: new Observable<MouseEvent>(),
417416
hoverOverlayElements: of(null),
418417
hoverOverlayRerenders: EMPTY,
419-
fetchHover: createStubHoverFetcher(hover),
420-
fetchActions: () => of(null),
418+
getHover: createStubHoverProvider(hover),
419+
getActions: () => of(null),
421420
})
422421

423422
const positionJumps = new Subject<PositionJump>()
@@ -477,8 +476,8 @@ describe('Hoverifier', () => {
477476
closeButtonClicks: new Observable<MouseEvent>(),
478477
hoverOverlayElements: of(null),
479478
hoverOverlayRerenders: EMPTY,
480-
fetchHover: createStubHoverFetcher(hover),
481-
fetchActions: () => of(null),
479+
getHover: createStubHoverProvider(hover),
480+
getActions: () => of(null),
482481
})
483482

484483
const positionJumps = new Subject<PositionJump>()
@@ -533,7 +532,7 @@ describe('Hoverifier', () => {
533532
/**
534533
* This test ensures that the adjustPosition options is being called in the ways we expect. This test is actually not the best way to ensure the feature
535534
* works as expected. This is a good example of a bad side effect of how the main `hoverifier.ts` file is too tightly integrated with itself. Ideally, I'd be able to assert
536-
* that the effected positions have actually been adjusted as intended but this is impossible with the current implementation. We can assert that the `HoverFetcher` and `ActionsFetcher`s
535+
* that the effected positions have actually been adjusted as intended but this is impossible with the current implementation. We can assert that the `HoverProvider` and `ActionsProvider`s
537536
* have the adjusted positions (AdjustmentDirection.CodeViewToActual). However, we cannot reliably assert that the code "highlighting" the token has the position adjusted (AdjustmentDirection.ActualToCodeView).
538537
*/
539538
/**
@@ -546,8 +545,8 @@ describe('Hoverifier', () => {
546545
scheduler.run(({ cold, expectObservable }) => {
547546
const adjustmentDirections = new Subject<AdjustmentDirection>()
548547

549-
const fetchHover = createStubHoverFetcher({})
550-
const fetchActions = createStubActionsFetcher(['foo', 'bar'])
548+
const getHover = createStubHoverProvider({})
549+
const getActions = createStubActionsProvider(['foo', 'bar'])
551550

552551
const adjustPosition: PositionAdjuster<{}> = ({ direction, position }) => {
553552
adjustmentDirections.next(direction)
@@ -559,8 +558,8 @@ describe('Hoverifier', () => {
559558
closeButtonClicks: new Observable<MouseEvent>(),
560559
hoverOverlayElements: of(null),
561560
hoverOverlayRerenders: EMPTY,
562-
fetchHover,
563-
fetchActions,
561+
getHover,
562+
getActions,
564563
})
565564

566565
const positionJumps = new Subject<PositionJump>()

src/hoverifier.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ export interface HoverifierOptions<C extends object, D, A> {
7474
hoverOverlayElements: Subscribable<HTMLElement | null>
7575

7676
/**
77-
* Called to fetch the data to display in the hover.
77+
* Called to get the data to display in the hover.
7878
*/
79-
fetchHover: HoverFetcher<C, D>
79+
getHover: HoverProvider<C, D>
8080

8181
/**
82-
* Called to fetch the actions to display in the hover.
82+
* Called to get the actions to display in the hover.
8383
*/
84-
fetchActions: ActionsFetcher<C, A>
84+
getActions: ActionsProvider<C, A>
8585
}
8686

8787
/**
@@ -150,8 +150,8 @@ export interface AdjustPositionProps<C extends object> {
150150
}
151151

152152
/**
153-
* Function to adjust positions coming into and out of hoverifier. It can be used to correct the position used in HoverFetcher and
154-
* ActionsFetcher requests and the position of th etoken to highlight in the code view. This is useful for code hosts that convert whitespace.
153+
* Function to adjust positions coming into and out of hoverifier. It can be used to correct the position used in HoverProvider and
154+
* ActionsProvider requests and the position of the token to highlight in the code view. This is useful for code hosts that convert whitespace.
155155
*
156156
*
157157
* @template C Extra context for the hovered token.
@@ -293,15 +293,15 @@ export const MOUSEOVER_DELAY = 50
293293
* @template C Extra context for the hovered token.
294294
* @template D The type of the hover content data.
295295
*/
296-
export type HoverFetcher<C extends object, D> = (
296+
export type HoverProvider<C extends object, D> = (
297297
position: HoveredToken & C
298298
) => SubscribableOrPromise<(HoverAttachment & D) | null>
299299

300300
/**
301301
* @template C Extra context for the hovered token.
302302
* @template A The type of an action.
303303
*/
304-
export type ActionsFetcher<C extends object, A> = (position: HoveredToken & C) => SubscribableOrPromise<A[] | null>
304+
export type ActionsProvider<C extends object, A> = (position: HoveredToken & C) => SubscribableOrPromise<A[] | null>
305305

306306
/**
307307
* Function responsible for resolving the position of a hovered token
@@ -319,8 +319,8 @@ export type ContextResolver<C extends object> = (hoveredToken: HoveredToken) =>
319319
export function createHoverifier<C extends object, D, A>({
320320
closeButtonClicks,
321321
hoverOverlayRerenders,
322-
fetchHover,
323-
fetchActions,
322+
getHover,
323+
getActions,
324324
}: HoverifierOptions<C, D, A>): Hoverifier<C, D, A> {
325325
// Internal state that is not exposed to the caller
326326
// Shared between all hoverified code views
@@ -568,21 +568,21 @@ export function createHoverifier<C extends object, D, A>({
568568
if (!position) {
569569
return of({ hoverOrError: null, position: undefined, part: undefined, ...rest })
570570
}
571-
// Fetch the hover for that position
572-
const hoverFetch = from(fetchHover(position)).pipe(
571+
// Get the hover for that position
572+
const hover = from(getHover(position)).pipe(
573573
catchError((error): [ErrorLike] => [asError(error)]),
574574
share()
575575
)
576-
// 1. Reset the hover content, so no old hover content is displayed at the new position while fetching
577-
// 2. Show a loader if the hover fetch hasn't returned after 100ms
576+
// 1. Reset the hover content, so no old hover content is displayed at the new position while getting
577+
// 2. Show a loader if the hover hasn't returned after 100ms
578578
// 3. Show the hover once it returned
579579
return merge(
580580
[undefined],
581581
of(LOADING).pipe(
582582
delay(LOADER_DELAY),
583-
takeUntil(hoverFetch)
583+
takeUntil(hover)
584584
),
585-
hoverFetch
585+
hover
586586
).pipe(
587587
map(hoverOrError => ({
588588
...rest,
@@ -685,16 +685,16 @@ export function createHoverifier<C extends object, D, A>({
685685
* This is a higher-order Observable (Observable that emits Observables).
686686
*/
687687
const actionObservables = resolvedPositions.pipe(
688-
// Fetch the actions for that position
688+
// Get the actions for that position
689689
map(({ position }) => {
690690
if (!position) {
691691
return of(null)
692692
}
693-
return concat([LOADING], from(fetchActions(position)).pipe(catchError(error => [asError(error)])))
693+
return concat([LOADING], from(getActions(position)).pipe(catchError(error => [asError(error)])))
694694
})
695695
)
696696

697-
// ACTIONS FETCH
697+
// ACTIONS
698698
// On every new hover position, (pre)fetch actions and update the state
699699
subscription.add(
700700
actionObservables
@@ -710,7 +710,7 @@ export function createHoverifier<C extends object, D, A>({
710710
// if either the hover or the definition turn out non-empty, pin the tooltip.
711711
// If they both turn out empty, unpin it so we don't end up with an invisible tooltip.
712712
//
713-
// zip together the corresponding hover and definition fetches
713+
// zip together the corresponding hover and definition
714714
subscription.add(
715715
combineLatest(
716716
zip(hoverObservables, actionObservables),

src/testutils/fixtures.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { of } from 'rxjs'
22
import { delay } from 'rxjs/operators'
33

4-
import { ActionsFetcher, HoverFetcher } from '../hoverifier'
4+
import { ActionsProvider, HoverProvider } from '../hoverifier'
55
import { HoverAttachment } from '../types'
66

77
/**
@@ -18,21 +18,24 @@ export const createHoverAttachment = (hover: Partial<HoverAttachment> = {}): Hov
1818
})
1919

2020
/**
21-
* Create a stubbed HoverFetcher
21+
* Create a stubbed HoverProvider
2222
* @param hover optional values to be passed to createHoverAttachment
2323
* @param delayTime optionally delay the hover fetch
2424
*/
25-
export function createStubHoverFetcher(hover: Partial<HoverAttachment> = {}, delayTime?: number): HoverFetcher<{}, {}> {
25+
export function createStubHoverProvider(
26+
hover: Partial<HoverAttachment> = {},
27+
delayTime?: number
28+
): HoverProvider<{}, {}> {
2629
return () => of(createHoverAttachment(hover)).pipe(delay(delayTime || 0))
2730
}
2831

2932
/**
30-
* Create a stubbed ActionsFetcher
33+
* Create a stubbed ActionsProvider
3134
*
3235
* @template A The type of an action.
3336
* @param actions optional value to emit as the actions
3437
* @param delayTime optionally delay the fetch
3538
*/
36-
export function createStubActionsFetcher<A>(actions: A[], delayTime?: number): ActionsFetcher<{}, A> {
39+
export function createStubActionsProvider<A>(actions: A[], delayTime?: number): ActionsProvider<{}, A> {
3740
return () => of(actions).pipe(delay(delayTime || 0))
3841
}

src/token_position.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function convertCodeElementIdempotent(element: HTMLElement): void {
8484
*
8585
* The browser extension works by registering a hover event listeners on the <td> element. When the user hovers over
8686
* "return" (in the first <span> node) the event target will be the <span> node. We can use the event target to determine which line
87-
* and which character offset on that line to use to fetch tooltip data. But when the user hovers over "Router"
87+
* and which character offset on that line to use to get tooltip data. But when the user hovers over "Router"
8888
* (in the second text node) the event target will be the <td> node, which lacks the appropriate specificity to request
8989
* tooltip data. To circumvent this, all we need to do is wrap every free text node in a <span> tag.
9090
*

0 commit comments

Comments
 (0)