Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

Octane & route templates with sane variable names

$
0
0

@shull wrote:

Background: I personally can’t stand to see this.model in my route templates (or @model). I’ve overridden setupController 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 with setupController was mentioned as a downside—specifically that you can’t have @post (for example) in your route template. But you could still use the setupController technique to make this.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:

  1. Define a minimal controller, just so I can add @tracked post
  2. Use controller.set('post', model) in the setupController hook (or set(controller, 'post', model) for better future-proofing)
  3. Just use @model in my route template and wonder what’s actually in that variable every time I see the file

It’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

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles