I built hangman game with emberjs, quick prevew. The game deals with more of view stuffs than other parts, I would like to share some thoughts and tricks I learned during the process.
I am not an ember expert so the way I have done may not be the optimal way of doing things in ember. Instead of walking through each steps, the code is well commented you can easily walk through, here I will describe striking stuffs.
View and Controller back-and-forth
As you can see in the UI we have buttons with alphabets through which we capture user input. For this, I created my own input view that extended from Ember.TextField.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
We get the current controller via
@get('targetObject') then we can call action of controller with send.
We also need to be able to trigger view action ‘reset’ from the controller. The reset action resets the the input panel.
The trick is well described here using Ember.Evented mixin.
Controller properties sortable
I have set scores in the setupConctroller of IndexRoute. What I want to do it, for each game session I create a Score model and push it to scores but I want to be auto sorted by latest ‘id’. For this we can do something like this
1 2 3 4 5 6 7 8 9 10 11
I wrote a helper to display the green bars that represents the life.
1 2 3 4 5 6 7 8 9 10
And from template we could do something like
1 2 3
life is a property in the controller.
Now what happens is by default life here is not bound to the life property in controller. So the trick is register helper with ‘Ember.Handlebars.registerBoundHelper’
Rest others are pretty straight forward.
I have used brunch with tapas-with-ember. I found brunch better than grunt.
I would love to hear feedback and corrections where necessary.