Skip to content

Instantly share code, notes, and snippets.

@ahawkins
Last active December 11, 2015 22:08
Show Gist options
  • Save ahawkins/4666885 to your computer and use it in GitHub Desktop.
Save ahawkins/4666885 to your computer and use it in GitHub Desktop.
I'll try to summarize succinctly. In the old router we had /messges/:folder
where folder is passed into a find query in connectOutlets. Folder is a simple
string like: sent/received/read etc. We struggled to get this to work in the
new router.
We setup one route as /messages/:folder. We implementing the model hook to take
the folder and pass it to Email.find(folder: params.folder). This worked. In
our hbs we used {{linkTo emails "inbox"}}. This only worked in some cases.
Let me explain why. The model hook is only called when deserialize is called.
Deserialize is only called when entering a state via a URL. It's not called
when transitioning via linkTo. The only way to get it work as we implemented
befoe was to do someting like this: {{linkTo emails Email.find(folder: foo)}}.
That way the model property would be set correctly. Using {{linkTo emails "A"}}
would set an ArrayController's content to "A". This would raise an error
because it's not an array. We ended up just using an action to set the folder
and make the find CP.
I don't know if this is a problem or just the wrong way to do things. We could
override route.setup and see what the context is and act accordingly, but that
just feels wrong. I think there are some pain points around using parameters
that are used to load models, but not models themselves.
We got around this problem by using action and a CP, but I'm sure we'll need
persistant state at some point.
EDIT: I think what was most confusing to us that the `model` hook was not called
via {{linkTo}}, only when we type: `/messages/inbox` into the URL bar.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment