Created
July 23, 2015 01:21
-
-
Save katzenbar/edcd01e35f331d733f67 to your computer and use it in GitHub Desktop.
Computed Properties Quirk Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default Ember.Component.extend({ | |
selection: 'Cat', | |
isCatFavorite: Ember.computed.equal('selection', 'Cat'), | |
isDogFavorite: Ember.computed.equal('selection', 'Dog'), | |
isMonkeyFavorite: Ember.computed.equal('selection', 'Monkey'), | |
isBearFavorite: Ember.computed.equal('selection', 'Bear'), | |
catButtonClass: Ember.computed('isCatFavorite', { | |
get() { | |
return this._getSelectionClassFor('Cat'); | |
} | |
}), | |
dogButtonClass: Ember.computed('isDogFavorite', { | |
get() { | |
return this._getSelectionClassFor('Dog'); | |
} | |
}), | |
monkeyButtonClass: Ember.computed('isMonkeyFavorite', { | |
get() { | |
return this._getSelectionClassFor('Monkey'); | |
} | |
}), | |
bearButtonClass: Ember.computed('isBearFavorite', { | |
get() { | |
return this._getSelectionClassFor('Bear'); | |
} | |
}), | |
_getSelectionClassFor(type) { | |
return this.get('selection') === type ? 'selected' : ''; | |
}, | |
actions: { | |
selectFavorite(typeOfAnimal) { | |
this.set('selection', typeOfAnimal); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SELECTION_CLASS = 'selected'; | |
export default Ember.Component.extend({ | |
selection: 'Cat', | |
isCatFavorite: Ember.computed.equal('selection', 'Cat'), | |
isDogFavorite: Ember.computed.equal('selection', 'Dog'), | |
isMonkeyFavorite: Ember.computed.equal('selection', 'Monkey'), | |
isBearFavorite: Ember.computed.equal('selection', 'Bear'), | |
catButtonClass: Ember.computed('isCatFavorite', { | |
get() { | |
return this.get('isCatFavorite') ? SELECTION_CLASS : ''; | |
} | |
}), | |
dogButtonClass: Ember.computed('isDogFavorite', { | |
get() { | |
return this.get('isDogFavorite') ? SELECTION_CLASS : ''; | |
} | |
}), | |
monkeyButtonClass: Ember.computed('isMonkeyFavorite', { | |
get() { | |
return this.get('isMonkeyFavorite') ? SELECTION_CLASS : ''; | |
} | |
}), | |
bearButtonClass: Ember.computed('isBearFavorite', { | |
get() { | |
return this.get('isBearFavorite') ? SELECTION_CLASS : ''; | |
} | |
}), | |
actions: { | |
selectFavorite(typeOfAnimal) { | |
this.set('selection', typeOfAnimal); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default Ember.Component.extend({ | |
selection: 'Cat', | |
catButtonClass: Ember.computed('selection', { | |
get() { | |
return this._getSelectionClassFor('Cat'); | |
} | |
}), | |
dogButtonClass: Ember.computed('selection', { | |
get() { | |
return this._getSelectionClassFor('Dog'); | |
} | |
}), | |
monkeyButtonClass: Ember.computed('selection', { | |
get() { | |
return this._getSelectionClassFor('Monkey'); | |
} | |
}), | |
bearButtonClass: Ember.computed('selection', { | |
get() { | |
return this._getSelectionClassFor('Bear'); | |
} | |
}), | |
_getSelectionClassFor(type) { | |
return this.get('selection') === type ? 'selected' : ''; | |
}, | |
actions: { | |
selectFavorite(typeOfAnimal) { | |
this.set('selection', typeOfAnimal); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
var Router = Ember.Router.extend({ | |
location: 'none' | |
}); | |
Router.map(function() { | |
}); | |
export default Router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
font-family: Arial; | |
} | |
.selected { | |
background-color: #3498db; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment