-
-
Notifications
You must be signed in to change notification settings - Fork 405
Description
Summary: Provide an Ember-y way to read the full URL contained in window.location that also supports testable ways of changing the value.
Context: I have a site-brand service that computes critical branding elements based on the domain used to access the app. First invocation is from index.js to set the window title with ember-cli-document-title, so router-based solutions aren't sufficient. Testing the naive implementation of the service would require changing window.location directly which has undesirable consequences.
Alternatives:
- Someone suggested using
this.get('router.url')but it's undefined inindex.jsand only returns the route path. - Someone suggested using
Ember.Location, but access to the required information in it is private and/or undocumented. The same thing goes for the underlyingember-metal/environmentit relies on for location. - Wrap access to
window.locationor memoize it in a way that can be overridden by tests.
I'm doing #3, but feel something more Ember-y would be of general utility.
I understand we're talking about SPAs, so the protocol and domain parts won't change over the app's lifetime. I also suggest read-only because external links should be handled as links and internal ones should be handled through the router. It should be changeable during testing, but without the side effects you'd get from changing window.location.
Thoughts?