Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative urlRoot #50

Open
EvanCarroll opened this issue Jun 3, 2015 · 0 comments
Open

Relative urlRoot #50

EvanCarroll opened this issue Jun 3, 2015 · 0 comments

Comments

@EvanCarroll
Copy link

In the upcoming release of ampsersand-sync, xhr2.js will be used. There is already a bug and pull request tracking this AmpersandJS/ampersand-sync#32 This gives us a great new feature we didn't previously have: we can test the interfaces outside of the browser, using Mocha. It also raises a question..

var model = BaseModel.extend({
    urlRoot: "/login"
});

What this does inside the browser is logical: it's a simple relative URL and all of it is handled behind the scenes. However, we'll have to hack ampersand-model.url() https://github.com/AmpersandJS/ampersand-model/blob/master/ampersand-model.js#L128 so we can reference some kind of global root path or something. If we don't have a reference to a global root path, or some way to emulate this functionality transparently everywhere ampersand-models are instantiated then we can we either

  • Have all urlRoots absolute urls.
  • Lose the ability to run them headless under Node.js.

Suggested Fix

Add a computed lazy property that emulates something like baseURI, we'll use baseURL as an example here.

*. Default baseURL property with
1. window.document.location.href (if this exists)
2. if it doesn't exist default it to global.document.location.href
3. throw fatal error.

This would permit us to always calculate the base for the current urlRoot.

*. Add a convenience function, isRelativeURL to check whether or not urlRoot is relative.
*. Add a conditional here using the new isRelativeURL. If the root is relative, use a URL library to make the urlRoot relative to the baseURL.

Suggestions? Ideas? One consideration we may have is the ambiguity in names. Under the current scheme urlRoot is often not the root at all. It's often relative to the implicit url root of document.window.location.href. This doesn't fix this bad property name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant