Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action handlers implemented directly on controllers are deprecated -how to correct this?

Tags:

ember.js

I just upgraded from ember.js RC7 to RC8 and found that a simple template (shown below) would throw a deprecated warning

"Action handlers implemented directly on controllers are deprecated"

{{input class="firstName" type="text" placeholder="first name" value=firstName }}                                      
{{input class="lastName" type="text" placeholder="last name" value=lastName }}                                         
<button class="submit" {{action addPerson}}>Add</button>                                                               
<br />                                                                                                                 
<table>                                                                                                                
{{#each person in controller}}                                                                                         
<tr>                                                                                                                   
  <td class="name">{{person.fullName}}</td>                                                                            
  <td><button class="delete" {{action deletePerson person}}>Delete</button></td>                                       
</tr>                                                                                                                  
{{/each}}                                                                                                              
</table>

How should I modify the above template to correct this?

like image 264
Toran Billups Avatar asked Aug 29 '13 12:08

Toran Billups


1 Answers

It looks like I just needed to give the PR a look that changed this :)

In my controller I just needed to move the addPerson / deletePerson under actions like so

App.PeopleController = Ember.ArrayController.extend({                                                                  
    actions: {                                                                                                         
        addPerson: function() {                                                                                        
            var person = {                                                                                             
                firstName: this.get('firstName'),                                                                      
                lastName: this.get('lastName')                                                                         
            };                                                                                                         
            App.Person.add(person);                                                                                    
        },                                                                                                             
        deletePerson: function(person) {                                                                               
            App.Person.remove(person);                                                                                 
        }                                                                                                              
    }                                                                                                                  
});
like image 54
Toran Billups Avatar answered Oct 30 '22 17:10

Toran Billups