Giter VIP home page Giter VIP logo

Comments (3)

wyuenho avatar wyuenho commented on August 17, 2024

Judging from your response structure, the correct parse method should be something like this:

parse: function (resp) {

  // make sure the response structure is acceptable
  if (!_.isObject(resp) || !resp.results) {
    return new TypeError("The incoming data format did not match the format we expected.");
  }

  // update pageable states by translating server states to pageable states.
  var queryParams = this.queryParams;
  var newState = _.clone(this.state);
  var serverState = resp;

  _.each(_.pairs(_.omit(queryParams, "directions")), function (kvp) {
    var k = kvp[0], v = kvp[1];
    newState[k] = serverState[v];
  });

  if (serverState.order) {
    newState.order = _.invert(queryParams.directions)[serverState.order] * 1;
  }

  // make sure the state is sane
  this.state = this._checkState(newState);

  return resp.results;
}

I suppose the really confusing part is when to call _checkState and how to translate server state back to pageable state. Maybe extracting the translation into a helper method will make customizing parse easier. A few words in the README on what a parse method is expected to do at the beginning and end would be good too.

Care to submit a PR?

from backbone-pageable.

robcolburn avatar robcolburn commented on August 17, 2024

There's a lot of logic there I don't quite understand. I'm going write my own Paginator, I'm hoping to release this/week next week. Pageable seems more focused on backends with a degree of control.

from backbone-pageable.

wyuenho avatar wyuenho commented on August 17, 2024

What "magic" you don't understand? It's pretty well documented and highly flexible and customizable. Most of the time it just works. Let me know so I can improve it.

from backbone-pageable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.