How to change a view if state is equal to


#1

Hello, there I’ve recently started learning Ember.js , and I’m writing a game “hangman”. I’m having trouble with Ember.js’s templates, I have a “state” defined inside component, and I want to switch between templates if state = won , so it won’t be so messy , right now all game is written in 2 files, a component and it’s template. Currently I’m attempting to refactor it.

I’d like to have different view for state = won || lost || provideWord . Tried to work it out with routes , but didn’t manage to either.


#2

Do an if in your template and then display two different components depending on which path gets taken. That way you can skip routes.

This used to be done with partials, but those are heading toward being deprecated …


#3

I am sorry for so late reply! It’s that I am a minor programmer, and I am also working during vacation. Thank you for your advice, it worked! I should have done that before tho.

But why is it going to get deprecated, is it inefficient ?


#4

It will get deprecated because partials “leak context”. Meaning your partial works differently depending on what other template it gets called from. Unlike a component where the inputs are all defined, partials get messier. Ember is steadily moving toward APIs that encourage explicit inputs as it makes life better for all of us (framework authors included) :wink:


#5

That gives me an overall insight in direction Ember is taking. But still , I think I don’t really understand what that means, except that it will be more friendly to Developers.

My code is depending on ‘state’ defined in service, and components are changing it’s state via actions, it also gives me a notification in browser’s console "DEPRECATION: You modified ShouldDisplay((eq playGame.state “provideWord”)) twice in a single render. This was unreliable in Ember 1.x and will be removed in Ember 3.0 [deprecation id: ember-views.render-double-modify]"

Is that what you mean?