iron-ajax icon indicating copy to clipboard operation
iron-ajax copied to clipboard

Auto requests with interpolated binded-props in the URL should wait for all bindings to be set

Open nicholaswmin opened this issue 8 years ago • 0 comments

Description

Setting the url with multiple, interpolated binded-values triggers a request even if not all bindings have been defined when auto is set to true

Expected outcome

  • <iron-ajax url="[[baseUrl]]/users/[[idUser]]>" triggers an auto-request when both baseUrl and idUser have been defined.

Actual outcome

  • <iron-ajax url="[[baseUrl]]/users/[[idUser]]>" triggers a request when baseUrl is defined but before idUser has been defined, resulting in a request like so:

http://foo.com/users/ instead of http://foo.com/users/3

Steps to reproduce

Described above

Notes

Now to be clear -This can be solved in many ways - setting up an observer of some sort, a method to check the url value, or maybe a computed property that waits until all properties are defined.

For example I could do this:

<iron-ajax method="GET" url$="{{_processUrl(baseUrl, endpoint)}}" auto></iron-ajax>

<script>
...
  _processUrl: (baseUrl, endpoint) => {
    // @HACK checking if the `url` has all interpolated props set properly.
    // If it contains `//` or ends with `/` we infer that some of the binded props
    // have not been defined yet.
    if (endpoint.includes("//") || (endpoint.endsWith("/"))) return false;
    return baseUrl + "/" + endpoint;
  }
</script>

and usage:

 <foo-x endpoint="user/[[idUser]]"></foo-x>

However, I'd much prefer if I didn't have to write boilerplate code for trivial use cases like this one. If auto is really gonna be useful it should work for basic real-world cases like this one

Browsers Affected

  • [x] Chrome
  • [x] Firefox
  • [x] Safari 9
  • [x] Safari 8
  • [x] Safari 7
  • [x] Edge
  • [x] IE 11
  • [x] IE 10

nicholaswmin avatar Oct 24 '16 00:10 nicholaswmin