Skip to content

Commit

Permalink
use inject to access store in service
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrpalek committed Jan 29, 2016
1 parent ec9e0c2 commit cf874a2
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/gist/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export default Ember.Controller.extend({
}

fileProperties.filePath = filePath;
let file = this.store.createRecord('gistFile', fileProperties);
let file = this.get('store').createRecord('gistFile', fileProperties);

this.get('model.files').pushObject(file);
this.get('notify').info(`File ${file.get('filePath')} was added`);
Expand Down
4 changes: 2 additions & 2 deletions app/gist/edit/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import GistRoute from "ember-twiddle/routes/gist-base-route";

export default GistRoute.extend({
model (params) {
this.store.unloadAll('gistFile');
this.get('store').unloadAll('gistFile');

return this.store.find('gist', params.id);
return this.get('store').find('gist', params.id);
},

setupController() {
Expand Down
6 changes: 3 additions & 3 deletions app/gist/new/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ export default GistRoute.extend({
emberCli: Ember.inject.service('ember-cli'),

model (params) {
var model = this.store.createRecord('gist', {description: 'New Twiddle'});
var model = this.get('store').createRecord('gist', {description: 'New Twiddle'});

if (params.copyCurrentTwiddle) {
this.store.peekAll('gistFile').setEach('gist', model);
this.get('store').peekAll('gistFile').setEach('gist', model);
} else {
this.store.unloadAll('gistFile');
this.get('store').unloadAll('gistFile');

model.get('files').pushObject(this.get('emberCli').generate('controllers/application'));
model.get('files').pushObject(this.get('emberCli').generate('templates/application'));
Expand Down
2 changes: 1 addition & 1 deletion app/gist/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default Ember.Route.extend({
deactivate () {
var gist = this.controller.get('model');
if (gist.get('isNew')) {
this.store.unloadRecord(gist);
this.get('store').unloadRecord(gist);
}
},

Expand Down
13 changes: 5 additions & 8 deletions app/services/ember-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import config from '../config/environment';
import Ember from 'ember';
import moment from 'moment';

const { inject } = Ember;
const twiddleAppName = 'demo-app';

// These files will be included if not present
Expand Down Expand Up @@ -106,15 +107,11 @@ const requiredDependencies = [
* source code at https://github.com/ember-cli/ember-cli
*/
export default Ember.Service.extend({
dependencyResolver: Ember.inject.service(),

init (...args) {
this._super(...args);
this.set('store', this.container.lookup("service:store"));
},
dependencyResolver: inject.service(),
store: inject.service(),

generate(type) {
return this.store.createRecord('gistFile', this.buildProperties(type));
return this.get('store').createRecord('gistFile', this.buildProperties(type));
},

buildProperties(type, replacements) {
Expand Down Expand Up @@ -270,7 +267,7 @@ export default Ember.Service.extend({
requiredFiles.forEach(filePath => {
var file = gist.get('files').findBy('filePath', filePath);
if(!file) {
gist.get('files').pushObject(this.store.createRecord('gistFile', {
gist.get('files').pushObject(this.get('store').createRecord('gistFile', {
filePath: filePath,
content: blueprints[filePath]
}));
Expand Down
2 changes: 1 addition & 1 deletion app/torii-adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default Ember.Object.extend({ /**
*/
resolveUser (token) {
config.TMP_TORII_TOKEN = token;
return this.store.find('user', 'current').then((user) => {
return this.get('store').find('user', 'current').then((user) => {
config.TMP_TORII_TOKEN = null;
localStorage.setItem('fiddle_gh_session', token);
return { currentUser: user, token: token };
Expand Down
2 changes: 1 addition & 1 deletion app/twiddles/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default Ember.Route.extend({
},

model() {
return this.store.findAll('gist');
return this.get('store').findAll('gist');
},

actions: {
Expand Down

0 comments on commit cf874a2

Please sign in to comment.