Skip to content

Commit

Permalink
Clean up few things
Browse files Browse the repository at this point in the history
  • Loading branch information
raido committed Sep 3, 2020
1 parent eb8afb2 commit d26898a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
11 changes: 8 additions & 3 deletions addon/helpers/page-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ export default Helper.extend({
_hash._deprecate
);
}
let hash = assign({}, _hash);
hash.id = this.tokenId;
hash.title = params.join('');
let hash = assign(
{},
_hash,
{
id: this.tokenId,
title: params.join('')
}
);

this.tokens.push(hash);
this.tokens.scheduleTitleUpdate();
Expand Down
7 changes: 0 additions & 7 deletions addon/services/page-title-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default Service.extend({
init() {
this._super();
set(this, 'tokens', A());
set(this, 'length', 0);
this._removeExistingTitleTag();

let config = getOwner(this).resolveRegistration('config:environment');
Expand Down Expand Up @@ -117,7 +116,6 @@ export default Service.extend({
let tokens = copy(this.tokens);
tokens.push(token);
set(this, 'tokens', A(tokens));
set(this, 'length', this.length + 1);
},

remove(id) {
Expand All @@ -136,7 +134,6 @@ export default Service.extend({
let tokens = A(copy(this.tokens));
tokens.removeObject(token);
set(this, 'tokens', A(tokens));
set(this, 'length', this.length - 1);
},

visibleTokens: computed('tokens', {
Expand Down Expand Up @@ -195,10 +192,6 @@ export default Service.extend({
}
}),

// TODO use something else for initial render for routes
// without model() returning promise
// Example: A -> B -> C - when C is the target route and model() takes long time to load
// title of A and B will no be rendered until activeTransition.promise resolves.
scheduleTitleUpdate() {
let router = getOwner(this).lookup('router:main');
let routes = router._routerMicrolib || router.router;
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/services/page-title-list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ module('service:page-title-list', function(hooks) {
setupTest(hooks);

test('the list has no tokens by default', function (assert) {
assert.equal(this.owner.lookup('service:page-title-list').length, 0);
assert.equal(this.owner.lookup('service:page-title-list').tokens.length, 0);
});

test('calling `push` adds a token to the end of the list', function (assert) {
let list = this.owner.lookup('service:page-title-list');
list.push({ id: 1});
assert.equal(list.length, 1);
assert.equal(list.tokens.length, 1);
});

test('tokens have next and previous tokens', function (assert) {
Expand All @@ -24,7 +24,7 @@ module('service:page-title-list', function(hooks) {
list.push(second);
list.push(third);

assert.equal(list.length, 3);
assert.equal(list.tokens.length, 3);

assert.equal(first.previous, null);
assert.equal(first.next, second);
Expand All @@ -46,7 +46,7 @@ module('service:page-title-list', function(hooks) {
list.push(second);
list.push(third);
list.remove(2);
assert.equal(list.length, 2);
assert.equal(list.tokens.length, 2);

assert.equal(first.previous, null);
assert.equal(first.next, third);
Expand Down

0 comments on commit d26898a

Please sign in to comment.