Skip to content

Commit

Permalink
fix: remove deprecated {{title}} ast transform (#176)
Browse files Browse the repository at this point in the history
* fix: remove deprecated {{title}} at transform

BREAKING CHANGE: removes deprecated `{{title}}` ast transform, rename to `{{page-title}}`

* fix: use router service and fix lint

* chore: fix lint
  • Loading branch information
knownasilya authored Sep 23, 2020
1 parent af3a830 commit 0c7b999
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 91 deletions.
15 changes: 7 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ module.exports = {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true
}
legacyDecorators: true,
},
},
plugins: ['ember'],
extends: ['eslint:recommended', 'plugin:ember/recommended'],
env: {
browser: true
browser: true,
},
rules: {},
overrides: [
Expand All @@ -27,7 +27,6 @@ module.exports = {
'index.js',
'testem.js',
'config/**/*.js',
'lib/**/*.js',
'tests/dummy/config/**/*.js',
],
excludedFiles: [
Expand All @@ -37,14 +36,14 @@ module.exports = {
'tests/dummy/app/**',
],
parserOptions: {
sourceType: 'script'
sourceType: 'script',
},
env: {
browser: false,
node: true,
},
plugins: ['node'],
extends: ['plugin:node/recommended']
}
]
extends: ['plugin:node/recommended'],
},
],
};
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ ember install ember-page-title

### Compatibility

* Ember.js v3.12 or above
* Ember CLI v2.13 or above
* Node.js v10 or above
- Ember.js v3.12 or above
- Ember CLI v2.13 or above
- Node.js v10 or above

<details>
<summary>Fastboot vs Non-Fastboot Notes</summary>
Expand Down Expand Up @@ -61,13 +61,13 @@ module.exports = function (environment) {
### Deprecations

- Since **v5.2.2**: The `{{title}}` helper has been deprecated, use `{{page-title}}` instead, it has the same API. The
`{{title}}` helper was an AST transform and will be removed in the next major release.
`{{title}}` helper was an AST transform and was removed in **v6.0.0**.

### Upgrading notes for 5.x to 6.x

`ember-page-title` no longer requires the usage of `ember-cli-head`.

Please remove `{{head-layout}}` from your application's `application.hbs` route template.
- `ember-page-title` no longer requires the usage of `ember-cli-head`.
Please remove `{{head-layout}}` from your application's `application.hbs` route template.
- `{{title}}` has been removed, please rename to `{{page-title}}`.

### Upgrading notes for 3.x to 4.x

Expand Down
22 changes: 5 additions & 17 deletions addon/helpers/page-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { guidFor } from '@ember/object/internals';
import { assign } from '@ember/polyfills';

/**
`{{page-title}}` is used to communicate with
`{{page-title}}` helper used to set the title of the current route context.
@public
@method page-title
Expand All @@ -22,22 +22,10 @@ export default Helper.extend({
},

compute(params, _hash) {
// page-title used via title ast transform, which is deprecated
if (_hash && _hash._deprecate) {
// eslint-disable-next-line no-console
console.warn(
'Using `{{title}}` helper is deprecated, use `{{page-title}}` instead. ' +
_hash._deprecate
);
}
let hash = assign(
{},
_hash,
{
id: this.tokenId,
title: params.join('')
}
);
let hash = assign({}, _hash, {
id: this.tokenId,
title: params.join(''),
});

this.tokens.push(hash);
this.tokens.scheduleTitleUpdate();
Expand Down
10 changes: 5 additions & 5 deletions addon/services/page-title-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default Service.extend({

remove(id) {
let token = this.tokens.findBy('id', id);
let {next, previous} = token;
let { next, previous } = token;
if (next) {
next.previous = previous;
}
Expand All @@ -143,7 +143,7 @@ export default Service.extend({
visibleTokens: computed('tokens', {
get() {
let tokens = this.tokens;
let i = (tokens ? tokens.length : 0);
let i = tokens ? tokens.length : 0;
let visible = [];
while (i--) {
let token = tokens[i];
Expand All @@ -155,7 +155,7 @@ export default Service.extend({
}
}
return visible;
}
},
}),

sortedTokens: computed('visibleTokens', {
Expand Down Expand Up @@ -193,7 +193,7 @@ export default Service.extend({
return frontGroups.concat(
groups.reduce((E, group) => E.concat(group), [])
);
}
},
}),

scheduleTitleUpdate() {
Expand Down Expand Up @@ -243,5 +243,5 @@ export default Service.extend({
let title = titles[i];
title.parentNode.removeChild(title);
}
}
},
});
24 changes: 1 addition & 23 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
'use strict';

module.exports = {
name: 'ember-page-title',

setupPreprocessorRegistry(_, registry) {
const plugin = this._buildPlugin();

plugin.parallelBabel = {
requireFile: __filename,
buildUsing: '_buildPlugin',
params: {}
};

registry.add('htmlbars-ast-plugin', plugin);
},

_buildPlugin() {
return {
name: 'translate-title-helper-to-page-title-helper',
plugin: require('./lib/plugins/translate-helper-name'),
baseDir() {
return __dirname;
}
};
}
name: require('./package').name,
};
31 changes: 0 additions & 31 deletions lib/plugins/translate-helper-name.js

This file was deleted.

0 comments on commit 0c7b999

Please sign in to comment.