ibm-js / delite

HTML Custom Element / Widget infrastructure
http://ibm-js.github.io/delite/
Other
68 stars 28 forks source link

ArrayQueryAdapter shouldn't require a "new-query-asked" listener #444

Closed wkeese closed 7 years ago

wkeese commented 8 years ago

If you setup a deliteful/PageableList based on an array, and the user pages to the end of the array, he gets an exception.

It's from this code in ArrayToStoreAdapter.js:

fetchRange: function (args) {
    var res = this.data.slice(args.start, args.end);
    if (res.length < (args.end - args.start)) {
        var promise;
        var evt = {start: args.start, end: args.end, resLength: res.length, setPromise: function (pro) {
            promise = pro;
        }};
        this.emit("_new-query-asked", evt);
        return promise;
    } else {
        return Promise.resolve(res);
    }
},

The "_new-query-asked" event cause delite/Store to fire a "new-query-asked" event (without the underscore), but if no one is listening for that event then fetchRange() returns undefined rather than a Promise (with the remaining data) like it should.

cc @harbalk