Skip to content

Commit

Permalink
fix(): bind window as first param of getConfirmation
Browse files Browse the repository at this point in the history
When `create***History` runs, `getUserConfirmation` defaults to the
`getConfirmation` function, which expects the global `window` object as
its first parameter.  However, it is later invoked without passing
`window`, probably because the signature for the user-defined flavor in
`CreateBrowserHistoryOptions` does not expect `window` to be passed.

The simple fix is to bind `window` to the default `getConfirmation`
function as its first parameter.
  • Loading branch information
Michael Speed Elder committed Dec 7, 2020
1 parent 228e1f3 commit a43f6f1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stencil/router",
"version": "1.0.1",
"version": "1.0.2",
"description": "Stencil Router",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
12 changes: 5 additions & 7 deletions packages/router/src/components/prompt/prompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ActiveRouter from '../../global/active-router';
tag: 'stencil-router-prompt'
})
export class StencilRouterPrompt implements ComponentInterface {
@Element() el!: HTMLElement;
@Element() el!: HTMLStencilRouterPromptElement;
@Prop() when = true;
@Prop() message: string | Prompt = '';
@Prop() history?: RouterHistory;
Expand All @@ -30,20 +30,18 @@ export class StencilRouterPrompt implements ComponentInterface {
}

componentWillLoad() {
if (this.when ) {
if (this.when) {
this.enable(this.message);
}
}

@Watch('message')
@Watch('when')
updateMessage(newMessage: string, prevMessage: string) {
if (this.when) {
if (!this.when || prevMessage !== newMessage) {
this.enable(this.message);
}
} else {
if (!this.when) {
this.disable();
} else if (prevMessage !== newMessage) {
this.enable(newMessage);
}
}

Expand Down
11 changes: 5 additions & 6 deletions packages/router/src/utils/createBrowserHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ const createBrowserHistory = (win: Window, props: CreateBrowserHistoryOptions =
const scrollHistory = createScrollHistory(win);

const forceRefresh = (props.forceRefresh != null) ? props.forceRefresh : false;
const getUserConfirmation = (props.getUserConfirmation != null) ? props.getUserConfirmation : getConfirmation;
const getUserConfirmation =
props.getUserConfirmation != null
? props.getUserConfirmation
: getConfirmation.bind(undefined, win);
const keyLength = (props.keyLength != null) ? props.keyLength : 6;
const basename = props.basename ? stripTrailingSlash(addLeadingSlash(props.basename)) : '';

Expand Down Expand Up @@ -83,11 +86,9 @@ const createBrowserHistory = (win: Window, props: CreateBrowserHistoryOptions =
return createLocation(path, state, key || createKey(keyLength));
};


const transitionManager = createTransitionManager();

const setState = (nextState?: NextState) => {

// Capture location for the view before changing history.
scrollHistory.capture(history.location.key);

Expand All @@ -103,7 +104,7 @@ const createBrowserHistory = (win: Window, props: CreateBrowserHistoryOptions =
);
};

const handlePopState = (event: any) => {
const handlePopState = (event: PopStateEvent) => {
// Ignore extraneous popstate events in WebKit.
if (!isExtraneousPopstateEvent(globalNavigator, event)) {
handlePop(getDOMLocation(event.state));
Expand All @@ -114,7 +115,6 @@ const createBrowserHistory = (win: Window, props: CreateBrowserHistoryOptions =
handlePop(getDOMLocation(getHistoryState()));
};


const handlePop = (location: LocationSegments) => {
if (forceNextPop) {
forceNextPop = false;
Expand Down Expand Up @@ -263,7 +263,6 @@ const createBrowserHistory = (win: Window, props: CreateBrowserHistoryOptions =
const goBack = () => go(-1);
const goForward = () => go(1);


const checkDOMListeners = (delta: number) => {
listenerCount += delta;

Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/utils/createHashHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const createHashHistory = (win: Window, props: CreateHashHistoryOptions = {}) =>
const keyLength = (props.keyLength != null) ? props.keyLength : 6;

const {
getUserConfirmation = getConfirmation,
getUserConfirmation = getConfirmation.bind(undefined, win),
hashType = 'slash'
} = props;
const basename = props.basename ? stripTrailingSlash(addLeadingSlash(props.basename)) : '';
Expand Down

0 comments on commit a43f6f1

Please sign in to comment.