-
-
Save v1valasvegan/47118c3465bb776f1b521c77f95da177 to your computer and use it in GitHub Desktop.
Keeping Ember Simple Part 1
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'; | |
import { computed } from '@ember/object'; | |
export default Ember.Controller.extend({ | |
queryParams: ['search'], | |
search: '' | |
}); |
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 Model from 'ember-data/model'; | |
import attr from 'ember-data/attr'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
export default Model.extend({ | |
name: attr('string') | |
}); |
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 EmberRouter from '@ember/routing/router'; | |
import config from './config/environment'; | |
const Router = EmberRouter.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route("home", { path: "/"}, function() { | |
this.route("list", { path: "/hamsters" }) | |
}); | |
}); | |
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
import Ember from 'ember'; | |
import { inject as service } from '@ember/service'; | |
const HAMSTERS = { | |
data: [{ | |
id: 1, | |
type: 'hamster', | |
attributes: { | |
name: 'tomster' | |
}, | |
relationships: {} | |
},{ | |
id: 2, | |
type: 'hamster', | |
attributes: { | |
name: 'zoey' | |
}, | |
relationships: {} | |
},{ | |
id: 3, | |
type: 'hamster', | |
attributes: { | |
name: 'alex' | |
}, | |
relationships: {} | |
}] | |
}; | |
export default Ember.Route.extend({ | |
queryParams: { search: { refreshModel: true } }, | |
store: service(), | |
init() { | |
this.store.push(HAMSTERS); | |
}, | |
beforeModel() { | |
this.replaceWith('home.list'); | |
} | |
}); |
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'; | |
import rsvp from 'rsvp'; | |
export default Ember.Route.extend({ | |
model(params, transition) { | |
// TODO: Implement backend | |
// this.get('store').query('hamster', transition.queryParams) | |
let hamsters = this.store.peekAll('hamster'); | |
let deferred = rsvp.defer(); | |
hamsters = hamsters.filter((hamster) => { | |
if(!transition.queryParams.search) { | |
return true; | |
} | |
return (hamster.name.indexOf(transition.queryParams.search) > -1); | |
}); | |
setTimeout(() => deferred.resolve(hamsters), 50000); | |
return deferred.promise; | |
} | |
}); |
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
{ | |
"version": "0.15.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"ember-data": "3.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment