@shull wrote:
Background: I personally can’t stand to see
this.model
in my route templates (or@model
). I’ve overriddensetupController
in my routes in order to set useful variable names on my route templates for years now and, lacking other options, it has been fine.Last night I went down a rabbit hole reading various RFC’s (lots of cool stuff coming soon!) and I noticed that
@model
in route templates got merged and this technique withsetupController
was mentioned as a downside—specifically that you can’t have@post
(for example) in your route template. But you could still use thesetupController
technique to makethis.post
accessible in your route templates.So I carried on in my Octane project and was dismayed to find an exception generated:
router.js:1214 Error while processing route: edit-post Assertion Failed: You attempted to update (generated edit-post controller).post to “[object Object]”, but it is being tracked by a tracking context, such as a template, computed property, or observer. In order to make sure the context updates properly, you must invalidate the property when updating it. You can mark the property as
@tracked
, or use@ember/object#set
to do this.As far as errors go, it’s very helpful (if not wordy). AFAICT, I’m left with a few sub-optimal choices:
- Define a minimal controller, just so I can add
@tracked post
- Use
controller.set('post', model)
in thesetupController
hook (orset(controller, 'post', model)
for better future-proofing)- Just use
@model
in my route template and wonder what’s actually in that variable every time I see the fileIt’s kind of a bummer to have to define a controller just to have a decent variable name in my template (#1). It’s a bummer to re-introduce
set()
in my Octane app, which has (up to this point) done completely without it. And it’s a bummer to use@model
in my template when I rely on informative variable names.I think I’m leaning toward #1 at the moment, but if there’s something else I’m missing here please enlighten me! I’m still new to Octane and learning every day.
Posts: 1
Participants: 1