mercredi 23 septembre 2015

Ember (Computed?) Property that runs a function on .set()

I have something similar to this code below:

import Ember from 'ember';

export default Ember.mixin.create({
    maxPosition: 100,
    minPosition: 0,
    position: 0,
    updatePosition: function(increment){
        this.set('position', increment);
    }
});

This code is super simplified for clarity, but I want to put bounds of minPosition and maxPosition on position

For Example:

If I run: this.updatePosition(150);

and then run this.get('position')

it should return 100

Can I make position into a computed property that will be bound by these values when I run this.set() ?




Aucun commentaire:

Enregistrer un commentaire