|
1 | | -// @ts-nocheck |
2 | 1 | import { inject as service } from '@ember/service'; |
3 | 2 | import Helper from '@ember/component/helper'; |
4 | 3 | import { guidFor } from '@ember/object/internals'; |
5 | 4 |
|
| 5 | +import type Owner from '@ember/owner'; |
6 | 6 | import type PageTitleService from '../services/page-title.ts'; |
7 | | -import type { PageTitleToken } from '../services/page-title.ts'; |
| 7 | +import type { PageTitleToken } from '../private-types.ts'; |
8 | 8 |
|
9 | 9 | export type PageTitleHelperOptions = Pick< |
10 | 10 | PageTitleToken, |
@@ -34,24 +34,28 @@ interface Signature { |
34 | 34 | export default class PageTitle extends Helper<Signature> { |
35 | 35 | @service('page-title') declare tokens: PageTitleService; |
36 | 36 |
|
37 | | - get tokenId(): string { |
38 | | - return guidFor(this); |
39 | | - } |
| 37 | + tokenId = guidFor(this); |
40 | 38 |
|
41 | | - constructor() { |
42 | | - super(...arguments); |
| 39 | + constructor(owner: Owner) { |
| 40 | + super(owner); |
43 | 41 | this.tokens.push({ id: this.tokenId }); |
44 | 42 | } |
45 | 43 |
|
46 | | - compute(params, _hash) { |
47 | | - const hash = { |
48 | | - ..._hash, |
| 44 | + compute(params: string[], userOptions: PageTitleHelperOptions) { |
| 45 | + const options = { |
| 46 | + ...userOptions, |
49 | 47 | id: this.tokenId, |
50 | 48 | title: params.join(''), |
51 | 49 | }; |
52 | 50 |
|
53 | | - this.tokens.push(hash); |
| 51 | + this.tokens.push(options); |
54 | 52 | this.tokens.scheduleTitleUpdate(); |
| 53 | + // We must return an empty value here because otherwise |
| 54 | + // invoking the pageTitle helper will render something |
| 55 | + // in the component it's used in, and we don't want that. |
| 56 | + // |
| 57 | + // pageTitle is a side-effecting helper. |
| 58 | + // We *synchronize* the document.title with our internal state. |
55 | 59 | return ''; |
56 | 60 | } |
57 | 61 |
|
|
0 commit comments