Created
July 13, 2016 18:12
-
-
Save phillipkregg/71b2efe286acf8877f15efc63c16c1cc to your computer and use it in GitHub Desktop.
Services in SubFolders
This file contains hidden or 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.Component.extend({ | |
movieService: Ember.inject.service('movie-displayer-service'), | |
actions: { | |
selectMovie: function(movie) { | |
// Instead of saving state in the component itself, let's | |
// save it in a service that can be consumed anywhere | |
// in the application. | |
this.get('movieService').setupCurrentSelectedMovie(movie); | |
} | |
} | |
}); | |
This file contains hidden or 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: 'Component Backed by Service' | |
}); |
This file contains hidden or 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'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('movies'); | |
this.route('test-my-service-state'); | |
}); | |
export default Router; |
This file contains hidden or 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.Route.extend({ | |
movieService: Ember.inject.service('movie-displayer-service'), | |
model: function() { | |
return ['Captain America: Civil War', 'Guardians of the Galaxy', 'Ant Man'] | |
}, | |
actions: { | |
showServiceState: function() { | |
this.get('movieService').showSelectedMovie(); | |
} | |
} | |
}); |
This file contains hidden or 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.Route.extend({ | |
// Inject the service here to have access to this components state | |
movieService: Ember.inject.service('movie-displayer-service'), | |
renderTemplate: function() { | |
// My template has a different name from the route, | |
// so I can specify the exact template I want to render here. | |
this.render('my-current-service-state') | |
}, | |
actions: { | |
checkServiceState: function() { | |
this.get('movieService').showSelectedMovie(); | |
} | |
} | |
}); |
This file contains hidden or 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({ | |
currentSelectedMovie: undefined, | |
setupCurrentSelectedMovie: function(movie) { | |
this.set('currentSelectedMovie', movie); | |
}, | |
showSelectedMovie: function() { | |
if (this.get('currentSelectedMovie')) { | |
alert("The current selected movie of the movie-displayer component is: \n" + this.get('currentSelectedMovie')); | |
} else { | |
alert('Please Select a Movie First'); | |
} | |
} | |
}); |
This file contains hidden or 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 url(https://fonts.googleapis.com/css?family=Muli); | |
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-family: 'Muli'; | |
font-size: 16px; | |
color: #333; | |
} | |
p { | |
font-size: 20px; | |
} | |
a { | |
padding: 10px 15px; | |
background: #4479BA; | |
color: #FFF; | |
text-decoration: none; | |
} | |
button { | |
color: white; | |
border: none; | |
backgroudn: none; | |
border-radius: 4px; | |
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2); | |
background: rgb(28, 184, 65); /* this is a green */ | |
height: 35px; | |
margin: 10px 0; | |
width: 100%; | |
font-size: 20px; | |
} | |
button:active { | |
background: rgb(28, 184, 55); /* this is a green */ | |
} | |
.movie-list-container { | |
border: 1px solid #e5e5e5; | |
border-radius: 4px; | |
padding: 10px; | |
box-shadow: 0px 2px 3px 0px #e5e5e5; | |
} | |
.movie-list-title { | |
border-bottom: 1px solid #ccc; | |
color: #aaa; | |
} | |
.movie-list-container ul { | |
padding: 0; | |
margin: 0; | |
list-style-type: none; | |
} | |
.movie-list-container ul li { | |
padding: 10px; | |
margin: 10px; | |
background: #f5f5f5; | |
border: 1px solid #e5e5e5; | |
border-radius: 2px; | |
cursor: pointer; | |
} | |
.movie-list-container ul li:active { | |
background: #4479BA; | |
color: white; | |
} |
This file contains hidden or 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
{ | |
"version": "0.10.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.6.0", | |
"ember-data": "2.6.1", | |
"ember-template-compiler": "2.6.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment