Last active
April 2, 2016 13:53
-
-
Save jonpitch/9dceff8d40897c5e6077f0d4581916f1 to your computer and use it in GitHub Desktop.
Ember Theming - Service
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.Service.extend({ | |
base: 'default', | |
theme: 'first', | |
// the property used as a reference for styles | |
name: Ember.computed('base', function() { | |
const base = this.get('base'); | |
const theme = this.get('theme'); | |
return `${base}-${theme}`; | |
}), | |
// update things that may be using data-theme | |
themeChanged: Ember.observer('base', 'theme', function() { | |
this.notifyPropertyChange('name'); | |
}), | |
// set the base theme for the application | |
setBase: function(base) { | |
this.set('base', Ember.isEmpty(base) ? 'default' : base); | |
}, | |
// set theme to use within base theme | |
setTheme: function(theme) { | |
this.set('theme', Ember.isEmpty(theme) ? 'first' : theme); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment