Skip to content

Instantly share code, notes, and snippets.

@eccegordo
Last active August 29, 2015 14:23
Show Gist options
  • Save eccegordo/afe9ad2bac4d13f2f06c to your computer and use it in GitHub Desktop.
Save eccegordo/afe9ad2bac4d13f2f06c to your computer and use it in GitHub Desktop.
// A service object for managing access to static data.
// How to inject this service
// staticData: Ember.inject.service('static-data'),
import Ember from 'ember';
export default Ember.Service.extend({
// Setup the service with some data the first time it loads
setup: Ember.on('init', function() {
var usaStates = Ember.A([
{name: "Alabama", code: "AL"},
{name: "Montana", code: "MT"},
{name: "Alaska", code: "AK"},
{name: "Nebraska", code: "NE"},
{name: "Arizona", code: "AZ"},
{name: "Nevada", code: "NV"},
{name: "Arkansas", code: "AR"},
{name: "New Hampshire", code: "NH"},
{name: "California", code: "CA"},
{name: "New Jersey", code: "NJ"},
{name: "Colorado", code: "CO"},
{name: "New Mexico", code: "NM"},
{name: "Connecticut", code: "CT"},
{name: "New York", code: "NY"},
{name: "Delaware", code: "DE"},
{name: "North Carolina", code: "NC"},
{name: "Florida", code: "FL"},
{name: "North Dakota", code: "ND"},
{name: "Georgia", code: "GA"},
{name: "Ohio", code: "OH"},
{name: "Hawaii", code: "HI"},
{name: "Oklahoma", code: "OK"},
{name: "Idaho", code: "ID"},
{name: "Oregon", code: "OR"},
{name: "Illinois", code: "IL"},
{name: "Pennsylvania", code: "PA"},
{name: "Indiana", code: "IN"},
{name: "Rhode Island", code: "RI"},
{name: "Iowa", code: "IA"},
{name: "South Carolina", code: "SC"},
{name: "Kansas", code: "KS"},
{name: "South Dakota", code: "SD"},
{name: "Kentucky", code: "KY"},
{name: "Tennessee", code: "TN"},
{name: "Louisiana", code: "LA"},
{name: "Texas", code: "TX"},
{name: "Maine", code: "ME"},
{name: "Utah", code: "UT"},
{name: "Maryland", code: "MD"},
{name: "Vermont", code: "VT"},
{name: "Massachusetts", code: "MA"},
{name: "Virginia", code: "VA"},
{name: "Michigan", code: "MI"},
{name: "Washington", code: "WA"},
{name: "Minnesota", code: "MN"},
{name: "West Virginia", code: "WV"},
{name: "Mississippi", code: "MS"},
{name: "Wisconsin", code: "WI"},
{name: "Missouri", code: "MO"},
{name: "Wyoming", code: "WY"},
]);
this.set('usaStates', usaStates);
}),
usaStates: Ember.A([]),
lookupStateByCode: function(code){
// implement method that finds state in usaStates and returns it
},
preferredStateCode: null, // set this somewhere when a user selects a state
userSelectedState: Ember.computed('preferredStateCode', function() {
var preferredStateCode = this.get('preferredStateCode');
return this.lookupStateByCode(preferredStateCode);
}),
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment