Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/link.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { tracked } from '@glimmer/tracking';
import { assert } from '@ember/debug';
import { action } from '@ember/object';

import { BEHAVIOR, type Behavior } from './-behavior.ts';
import { getOwner, setOwner } from './-owner.ts';
Expand Down Expand Up @@ -208,9 +207,8 @@ export default class Link {
/**
* Transition into the target route.
*/
@action
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
transitionTo(event?: Event | unknown): Transition | undefined {
transitionTo = (event?: Event | unknown): Transition | undefined => {
if (!this.canOpen(event)) {
return;
}
Expand All @@ -220,15 +218,14 @@ export default class Link {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return this._linkManager.router.transitionTo(...this._routeArgs);
}
};

/**
* Transition into the target route while replacing the current URL, if
* possible.
*/
@action
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
replaceWith(event?: Event | unknown): Transition | undefined {
replaceWith = (event?: Event | unknown): Transition | undefined => {
if (!this.canOpen(event)) {
return;
}
Expand All @@ -238,11 +235,10 @@ export default class Link {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return this._linkManager.router.replaceWith(...this._routeArgs);
}
};

@action
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
open(event?: Event | unknown): Transition | undefined {
open = (event?: Event | unknown): Transition | undefined => {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const method = this.behavior.open ?? 'transition';

Expand All @@ -251,5 +247,5 @@ export default class Link {
}

return this.transitionTo(event);
}
};
}
25 changes: 13 additions & 12 deletions src/test-support/test-link.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { guidFor } from '@ember/object/internals';

import { preventDefault } from '../-behavior.ts';
import Link from '../link.ts';

import type Transition from '@ember/routing/transition';
Expand Down Expand Up @@ -80,8 +80,8 @@ export default class TestLink extends Link {
return this.routeName;
}

@action
transitionTo(event?: Event): Transition {
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
transitionTo = (event?: Event | unknown): Transition => {
this._preventTransitionOut(event);

// Fire both the `onTransitionTo` event used for testing, as well as the
Expand All @@ -90,10 +90,10 @@ export default class TestLink extends Link {
this.onTransitionTo?.();

return this._createDummyTransition();
}
};

@action
replaceWith(event?: Event): Transition {
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
replaceWith = (event?: Event | unknown): Transition => {
this._preventTransitionOut(event);

// Fire both the `onReplaceWith` event used for testing, as well as the
Expand All @@ -102,22 +102,23 @@ export default class TestLink extends Link {
this.onReplaceWith?.();

return this._createDummyTransition();
}
};

@action
open(event?: Event): Transition | undefined {
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
open = (event?: Event | unknown): Transition | undefined => {
const method = this.behavior.open;

if (method === 'replace') {
return this.replaceWith(event);
}

return this.transitionTo(event);
}
};

private _preventTransitionOut(event?: Event) {
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
private _preventTransitionOut(event?: Event | unknown) {
// Make sure we don't transition out of the testing page
event?.preventDefault();
preventDefault(event);
}

private _createDummyTransition(): Transition {
Expand Down