Skip to content

Provide read-only access to window.location #156

@srvance

Description

@srvance

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:

  1. Someone suggested using this.get('router.url') but it's undefined in index.js and only returns the route path.
  2. 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.
  3. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions