Search code examples
ember.jsobserversquery-string

Ember .observe() returns callback twice when used with query-params


http://jsbin.com/vowup/2

If I click change to random, program logs in console twice.

For some strange reason it works ok when setting revision variable to string, but logs twice for number or any other kind of variable


Solution

  • Change your code to this and the answer will become clear:

      toggleHistory: (function() {
        console.log(this.get("revision"));
      }).observes("revision")
    

    You will see output like:

    0.7038348997011781
    "0.7038348997011781"
    

    Your numbers are being coerced to strings. That is caused by this line:

    queryParams: ["revision"]
    

    Query system is listening to changes and converting every new value into string, so it could appear as part of the URL. That's why you get two changed events.