You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.locationdirectly which has undesirable consequences.
Alternatives:
Someone suggested using this.get('router.url') but it's undefined in index.js and 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 underlying ember-metal/environment it relies on for location.
Wrap access to window.location or 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?
The text was updated successfully, but these errors were encountered:
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 fromindex.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 changingwindow.location
directly which has undesirable consequences.Alternatives:
this.get('router.url')
but it's undefined inindex.js
and only returns the route path.Ember.Location
, but access to the required information in it is private and/or undocumented. The same thing goes for the underlyingember-metal/environment
it relies on for location.window.location
or 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?
The text was updated successfully, but these errors were encountered: