Simple Property Enum Cycling in Ember

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

Contact us about our design & engineering services!
Tweet

Stay in the know.

Introducing the DockYard Newsletter. Our best design and engineering articles, conveniently delivered to your inbox each month. Sign up below!