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

pass init data to Link when available and avoid a server request #35

Closed
ioRekz opened this issue Jun 20, 2014 · 2 comments
Closed

pass init data to Link when available and avoid a server request #35

ioRekz opened this issue Jun 20, 2014 · 2 comments

Comments

@ioRekz
Copy link

ioRekz commented Jun 20, 2014

In the master/details example, we already have the full contact object available in the master component.
When linking to the detail component, we pass the id then fetch back the contact.

My current project has a similar use case and I would like to optionally add exra data to the Link (e.g. a full contact) so I avoid a request when I already have needed data.

Any idea ?

@ryanflorence
Copy link
Member

Great question.

The store in that example keeps the data cached, so it doesn't make new server requests for data it already fetched.

I have found in ember, (which typically works like {{#link-to "user" userData}}) that devs think their user route works if you land there, but it doesn't if their model hook is broken so it only works when you start one route above (the route that gets the data).

In other words:

  1. Land at /
  2. Data is fetched
  3. User clicks link that passes data in
  4. Route renders perfectly, model hook ignored

Now consider:

  1. Land at /users/123
  2. Data has not fetched yet from the parent route
  3. Model hook doesn't work
  4. Route is broken.

In my experience this happens a lot in ember, so I designed this router to just pass the parameters and not data objects so that your code always runs the same way (instead of two code paths). It is the store's job to avoid server requests, not the incidental hierarchy of your components and their data.

@ryanflorence ryanflorence changed the title pass init data when available and avoid a server request pass init data to Link when available and avoid a server request Jun 20, 2014
@ioRekz
Copy link
Author

ioRekz commented Jun 22, 2014

Ok thank you. That make sense! 

@lock lock bot locked as resolved and limited conversation to collaborators Jan 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants