Skip to content

Commit 004f111

Browse files
committed
Privateize the service
1 parent 8eb20b1 commit 004f111

4 files changed

Lines changed: 14 additions & 16 deletions

File tree

addon/rollup.config.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ export default {
1818
// addon. Anything not listed here may get optimized away.
1919
addon.publicEntrypoints([
2020
'index.js',
21-
'helpers/**/*.js',
22-
'services/**/*.js',
21+
'helpers/page-title.js',
2322
'test-support/index.js',
2423
]),
2524

2625
// These are the modules that should get reexported into the traditional
2726
// "app" tree. Things in here should also be in publicEntrypoints above, but
2827
// not everything in publicEntrypoints necessarily needs to go here.
29-
addon.appReexports(['helpers/**/*.js', 'services/**/*.js']),
28+
addon.appReexports(['helpers/**/*.js']),
3029

3130
// This babel config should *not* apply presets or compile away ES modules.
3231
// It exists only to provide development niceties for you, like automatic
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { scheduleOnce } from '@ember/runloop';
2-
import Service, { service } from '@ember/service';
2+
import { service } from '@ember/service';
33
import { isEmpty } from '@ember/utils';
44
import { assert } from '@ember/debug';
55
import type ApplicationInstance from '@ember/application/instance';
66
import type RouterService from '@ember/routing/router-service';
77
import type Owner from '@ember/owner';
8+
import { setOwner } from '@ember/owner';
9+
import { associateDestroyableChild } from '@ember/destroyable';
810

911
import type {
1012
FastBootDocument,
@@ -36,10 +38,9 @@ function hasPageTitleConfig(
3638
const configKeys = ['separator', 'prepend', 'replace'] as const;
3739

3840
/**
39-
@class page-title
40-
@extends Ember.Service
41+
@internal
4142
*/
42-
export default class PageTitleService extends Service {
43+
export class PageTitleManager {
4344
@service('router') declare router: RouterService;
4445

4546
// in fastboot context "document" is instance of
@@ -60,7 +61,9 @@ export default class PageTitleService extends Service {
6061
};
6162

6263
constructor(owner: Owner) {
63-
super(owner);
64+
setOwner(this, owner);
65+
associateDestroyableChild(this, owner);
66+
6467
this._validateExistingTitleElement();
6568

6669
if (hasResolveRegistration(owner)) {

addon/src/helpers/page-title.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { service } from '@ember/service';
21
import Helper from '@ember/component/helper';
32
import { guidFor } from '@ember/object/internals';
43

54
import type Owner from '@ember/owner';
6-
import type PageTitleService from '../services/page-title.ts';
5+
import type PageTitleManager from './manager.ts';
76
import type { PageTitleToken } from '../private-types.ts';
87

98
export type PageTitleHelperOptions = Pick<
@@ -32,12 +31,14 @@ interface Signature {
3231
* ```
3332
*/
3433
export default class PageTitle extends Helper<Signature> {
35-
@service('page-title') declare tokens: PageTitleService;
34+
declare tokens: PageTitleManager;
3635

3736
tokenId = guidFor(this);
3837

3938
constructor(owner: Owner) {
4039
super(owner);
40+
41+
this.tokens = new PageTitleManager(owner);
4142
this.tokens.push({ id: this.tokenId });
4243
}
4344

addon/src/service-registry.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import type PageTitleService from './services/page-title.ts';
21
import type { FastBootDocument } from './private-types.ts';
32

43
export default interface ServiceRegistry {
5-
/**
6-
* The service for managing the title of the page.
7-
*/
8-
'page-title': PageTitleService;
94
/**
105
* ⚠️ This service is not provided by ember-page-title,
116
* but is needed by ember-page-title

0 commit comments

Comments
 (0)