Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with RSVP? #192

Closed
peavers opened this issue Nov 9, 2016 · 2 comments
Closed

Doesn't work with RSVP? #192

peavers opened this issue Nov 9, 2016 · 2 comments

Comments

@peavers
Copy link

peavers commented Nov 9, 2016

export default Ember.Route.extend(InfinityRoute, {

  perPageParam: "limit",
  pageParam: "page",

  model() {
    this.store.unloadAll('post');

    return RSVP.hash({
      posts: this.infinityModel("post", {perPage: 2, startingPage: 1}),
    });
  },

  setupController(controller, models) {
    controller.setProperties(models);
  },

});

and in the template

{{#each posts as |post|}}
  {{post.content}}
{{/each}}

{{infinity-loader infinityModel=posts}}

Will load the first page, but then doesn't attempt to load anything else. No errors in the console, and no requests to the backend server.

However everything works if I use a standard

  model() {
    return this.infinityModel("post", { perPage: 12, startingPage: 1 });
  }

The response from the server looks like this

{
  "data": [
    {
      "type": "post",
      "id": "58234f35835a3e49843a245a",
      "attributes": {
       //removed
      },
      "relationships": {
        "account": {
          "data": {
            "type": "accounts",
            "id": "5822dc39835a3e252019c9be"
          }
        }
      }
    },
    {
      "type": "post",
      "id": "5822e491835a3e49843a00b3",
      "attributes": {
       //removed
      },
      "relationships": {
        "account": {
          "data": {
            "type": "accounts",
            "id": "5822dc39835a3e252019c9be"
          }
        }
      }
    }
  ],
  "meta": {
    "total_pages": "54"
  },
  "links": {
    "next": {
      "href": "http://localhost:8080/api/posts/page?limit=2&page=4"
    },
    "self": {
      "href": "http://localhost:8080/api/posts/page?limit=2&page=3"
    },
    "last": {
      "href": "http://localhost:8080/api/posts/page?limit=2&page=54"
    },
    "first": {
      "href": "http://localhost:8080/api/posts/page?limit=2&page=0"
    },
    "prev": {
      "href": "http://localhost:8080/api/posts/page?limit=2&page=2"
    }
  }
}

Am I missing something here?

@hhff
Copy link
Collaborator

hhff commented Nov 9, 2016

hi @peavers !

In your above setup, your "infinity model" lives on your controller as controller.posts. Try

this.infinityModel("post", {perPage: 2, startingPage: 1, modelPath: 'controller.posts'})

@peavers
Copy link
Author

peavers commented Nov 10, 2016

Nailed it! Thanks champ

@peavers peavers closed this as completed Nov 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants