ReefPointsBlog

Simple Property Enum Cycling in Ember

Brian Cardarella

This is a quick one. I needed to cycle between the values in a set. Toggling between true and false in Ember is easy enough with the toggleProperty function but I had several properties I wanted to cycle between. So last night I wrote a simple function poorly named: cycleEnumProperty. You pass it the property you want to act upon and the enum set to cycle. If the property is currently empty or if the property matches the last value in the set the property will be set to the first value, otherwise the property will be set to the next value. Try it out:

Ember Starter Kit