mercredi 13 avril 2016

Sparse Fieldsets or Reload from Component, for Ember Data 2.0+

We're working on a charting application that, for performance reasons, needs a way to split the chart data from some meta data to render charts to select from.

There are probably more options, but the design that's most intuitive to us right now is to use JSONAPI's sparse fieldsets, and create a single Chart endpoint that is sparse when queried in a collection:

GET ../charts/

{"data": [{
  "type": "charts",
  "id": "1",
  "attributes": {
    "type": "A",
    "precision": "10",
    "average": "22.2",
    "minimum": "20.4",
    "maximum": "25.3",
  },
  {
  "type": "charts",
  "id": "2",
  "attributes": {
    "type": "A",
    "precision": "100",
    "average": "20.0",
    "minimum": "10.0",
    "maximum": "30.0",
  },
  ...
]}

and dense when queried by ID:

GET ../charts/1

{"data": {
  "type": "charts",
  "id": "1",
  "attributes": {
    "type": "A",
    "precision": "10",
    "average": "22.2",
    "minimum": "20.4",
    "maximum": "25.3",
    "chart": [
      ["100","21.0"],
      ["200","20.4"],
      ["300","25.3"],
      ...
    ]
  }
}

But we haven't found a way to force EmberData to reload the data from the backend service from a Component. We'd like to use the backgroundReload functionality, as we believe that would provide the best visual results, but all documentation about it is done using model hooks from a Route.

Is there a preferred way to do this from a Component's action?




Aucun commentaire:

Enregistrer un commentaire