brianleroux / lawnchair

A lightweight clientside JSON document store,
http://brianleroux.github.com/lawnchair
MIT License
2.13k stars 246 forks source link

Query fails with Async Adapters #134

Open mattbryson opened 12 years ago

mattbryson commented 12 years ago

The Query plugin uses an Async method to lookup data, but assumes its Sync, so the where query returns (and executes callback) before it has actually looked-up any data.

To fix, I moved the setting of this.__results into the callback of the all lookup, and trigger the where callback there.

However, the drawback is that chaining (indicated in the docs) is not possible.


this.all(function(all){  //This is Async, so we have to update __results in the callback...
  for (var i = 0, l = all.length; i < l; i++) {
    var success = is(all[i]); 
      if (success) r.push(all[i])
    }

    // overwrite working results
    this.__results = r;

    // callback / chain
     if (args.length === 1) this.fn(this.name, last).call(this, this.__results)   
  })

  //Chaining wont work as the data loaded into __results is Async, so chained methods will execute before __results is populated
  return this 
AndrewBNZ commented 11 years ago

Well heck, I'd been going round in circles trying to figure out why I wasn't getting any query results back - until I stumbled across this issue!

transitive-bullshit commented 10 years ago

I was debugging where for awhile before stumbling on this issue as well. +1 to get it fixed in master!

MarkMYoung commented 10 years ago

@fisch0920, I believe that code was put in the trunk April 24, 2013.

transitive-bullshit commented 10 years ago

Yep; you're right. I think the real issue here is that the files linked off of http://brian.io/lawnchair/ are way outdated and don't include this fix.