Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to ember-source 5.1 types (and other fixes) #256

Merged
merged 13 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 2 additions & 7 deletions addon/dev-only-types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
export {};

declare global {
interface Window {
FastBoot: any;
}
}
import 'ember-source/types';
import 'ember-cli-fastboot';
15 changes: 4 additions & 11 deletions addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,18 @@
},
"devDependencies": {
"@babel/core": "^7.16.12",
"@babel/eslint-parser": "^7.22.9",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-decorators": "^7.16.7",
"@babel/plugin-transform-typescript": "^7.19.3",
"@babel/preset-typescript": "^7.18.6",
"@embroider/addon-dev": "^2.0.0",
"@embroider/addon-dev": "^3.2.0",
"@simple-dom/document": "^1.4.0",
"@tsconfig/ember": "^3.0.0",
"@types/ember-cli-fastboot": "^2.2.2",
"@types/ember__application": "^4.0.0",
"@types/ember__debug": "^4.0.0",
"@types/ember__destroyable": "^4.0.0",
"@types/ember__helper": "^4.0.0",
"@types/ember__object": "^4.0.2",
"@types/ember__owner": "^4.0.0",
"@types/ember__routing": "^4.0.11",
"@types/ember__runloop": "^4.0.1",
"@types/ember__test-helpers": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"babel-eslint": "^10.1.0",
"ember-source": "^5.1.2",
"ember-template-lint": "^3.6.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
Expand Down
3 changes: 2 additions & 1 deletion addon/src/helpers/page-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { inject as service } from '@ember/service';
import Helper from '@ember/component/helper';
import { guidFor } from '@ember/object/internals';
import PageTitleService, { PageTitleToken } from '../services/page-title';
import type Owner from '@ember/owner';

export type PageTitleHelperOptions = Pick<
PageTitleToken,
Expand Down Expand Up @@ -30,7 +31,7 @@ export default class PageTitle extends Helper<PageTitleSignature> {
return guidFor(this);
}

constructor(owner: object | undefined) {
constructor(owner: Owner | undefined) {
super(owner);
this.tokens.push({ id: this.tokenId });
}
Expand Down
18 changes: 16 additions & 2 deletions addon/src/services/page-title.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getOwner } from '@ember/application';
import { getOwner } from '@ember/owner';
import { scheduleOnce } from '@ember/runloop';
import Service, { inject as service } from '@ember/service';
import { isEmpty } from '@ember/utils';
Expand Down Expand Up @@ -73,7 +73,7 @@ export default class PageTitleService extends Service {

// SAFETY: This is only valid because we cast it to a type which is optional
// *and* whose key is optional. It may be *wrong*, but it is at least sound.
const config = getOwner(this).factoryFor('config:environment')?.class as
const config = getOwner(this)?.factoryFor('config:environment')?.class as
| {
pageTitle?: PageTitleConfig;
}
Expand Down Expand Up @@ -154,6 +154,8 @@ export default class PageTitleService extends Service {

remove(id: PageTitleToken['id']) {
const token = this._findTokenById(id);
if (!token) return;

const { next, previous } = token;

if (next) {
Expand All @@ -178,6 +180,8 @@ export default class PageTitleService extends Service {

while (i--) {
const token = tokens[i];
if (!token) return;

if (token.replace) {
visible.unshift(token);
break;
Expand All @@ -191,6 +195,8 @@ export default class PageTitleService extends Service {

get sortedTokens() {
const visible = this.visibleTokens;
if (!visible) return;

let appending = true;
let group: PageTitleToken[] = [];
const groups = [group];
Expand Down Expand Up @@ -230,16 +236,22 @@ export default class PageTitleService extends Service {

toString() {
const tokens = this.sortedTokens;
if (!tokens) return '';

const title = [];

for (let i = 0, len = tokens.length; i < len; i++) {
const token = tokens[i];
if (!token) break;

if (token.title) {
title.push(token.title);
if (i + 1 < len) {
title.push(token.separator);
}
}
}

return title.join('');
}

Expand Down Expand Up @@ -312,6 +324,8 @@ export default class PageTitleService extends Service {
// Remove existing title elements from previous render cycle
for (let i = 0; i < headChildNodes.length; i++) {
const node = headChildNodes[i];
if (!node) break;

if (node.nodeName.toLowerCase() === 'title') {
headElement.removeChild(node);
}
Expand Down
1 change: 1 addition & 0 deletions addon/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "@tsconfig/ember",
"compilerOptions": {
"baseUrl": "./src",
"experimentalDecorators": true,
"paths": {
// No paths, no absolute imports, only node_modules imports allowed
// But fallback for type-overrides and such
Expand Down
Loading