jeudi 14 décembre 2017

What does the key param do in an computed properties set and get?

import Ember from 'ember';
export default Ember.Component.extend({
  firstName: '',
  lastName: '',
  fullName: Ember.computed('firstName', 'lastName', {
    get(key) {
        return `${this.get('firstName')} ${this.get('lastName')}`;
    },
    set(key, value) {
        let [firstName, lastName] = value.split(/\s+/);
        this.set('firstName', firstName);
        this.set('lastName', lastName);
        return value;
    }
  })
});

Considering this example, why would one have a need for the key param?




Aucun commentaire:

Enregistrer un commentaire