In the upcoming release of ampsersand-sync, xhr2.js will be used. There is already a bug and pull request tracking this https://github.com/AmpersandJS/ampersand-sync/issues/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
window.document.location.href (if this exists)
if it doesn't exist default it to global.document.location.href
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.
In the upcoming release of
ampsersand-sync
, xhr2.js will be used. There is already a bug and pull request tracking this https://github.com/AmpersandJS/ampersand-sync/issues/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..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 everywhereampersand-models
are instantiated then we can we eitherSuggested Fix
Add a computed lazy property that emulates something like baseURI, we'll use
baseURL
as an example here.*. Default baseURL property with
window.document.location.href
(if this exists)global.document.location.href
This would permit us to always calculate the base for the current
urlRoot
.. Add a convenience function,
isRelativeURL
to check whether or noturlRoot
is relative. . Add a conditional here using the newisRelativeURL
. If the root is relative, use a URL library to make theurlRoot
relative to thebaseURL
.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 ofdocument.window.location.href
. This doesn't fix this bad property name.