Last active
February 5, 2021 21:39
-
-
Save sukima/13aee6fcdcce60a85751f85a4bf6138e to your computer and use it in GitHub Desktop.
add-page-title-segment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Helper from '@ember/component/helper'; | |
class TitleSegments { | |
constructor(segments = []) { | |
this.replace(segments); | |
} | |
replace(segments) { | |
this.segments = [...segments]; | |
} | |
*[Symbol.iterator]() { | |
yield* this.segments; | |
} | |
} | |
function setTitleSegments() { | |
const reverseFlatten = (a, i) => [...i, ...a]; | |
document.title = [...titleSegmentsTracking].reduce(reverseFlatten, []).join(' | '); | |
} | |
const titleSegmentsTracking = new Set([new TitleSegments([document.title])]); | |
export default class AddPageTitleSegment extends Helper { | |
constructor() { | |
super(...arguments); | |
this.titleSegments = new TitleSegments(); | |
titleSegmentsTracking.add(this.titleSegments); | |
} | |
willDestroy() { | |
titleSegmentsTracking.delete(this.titleSegments); | |
setTitleSegments(); | |
super.willDestroy(...arguments); | |
} | |
compute(segments) { | |
this.titleSegments.replace(segments); | |
setTitleSegments(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import EmberRouter from '@ember/routing/router'; | |
import config from './config/environment'; | |
const Router = EmberRouter.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('foo'); | |
this.route('bar', function() { | |
this.route('baz'); | |
}); | |
}); | |
export default Router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment