Skip to content

Instantly share code, notes, and snippets.

View alexspeller's full-sized avatar
🏁

Alex Speller alexspeller

🏁
View GitHub Profile
App.CommentsRoute = Em.Route.extend
model: ->
post = @modelFor 'post'
@store.filter 'comment', (comment) ->
comment.get('post') == post
App.CommentsRoute = Em.Route.extend
model: ->
post = @modelFor 'post'
post.get('comments').then (loadedComments) ->
@store.filter 'comment', (comment) ->
comment.get('post') == post
App.Router.map ->
@resource "foo"
@resource "bar", ->
@resource "baz"
@resource "login"
App.FancyLayoutView = Em.View.extend
layoutName: "fancy"
App.FooView = App.FancyLayoutView.extend()
def index
# use whatever AR scopes you want to make your sql query
relation = Post.find(1).comments.recent.where(author: params[:author_id])
# Then convert to sql to get an array of arrays back - way faster than
# full-on ActiveRecord objects
result = ActiveRecord::Base.connection.execute(relation.to_sql).map do |row|
{
author_id: row[0],
something: row[1],
App.MyRoute = Em.Route.extend
model: ->
@store.filter 'foo', param: 'something', (foo) ->
# return true if should include foo
{"user":"~Hannah21","host":"67.221.255.55","realname":null,"authname":null,"idle":0,"signed_on_at":null,"unknown?":false,"online?":true,"channels":[],"secure?":false,"away":null,"oper?":false,"raw":":Hannah21!~Hannah21@67.221.255.55 PRIVMSG #emberjs : Hi! I give you some videos. I hope you like! http://bit.do/my_videos69"}
{"user":"~Daniella2","host":"95.141.20.196","realname":null,"authname":null,"idle":0,"signed_on_at":null,"unknown?":false,"online?":true,"channels":[],"secure?":false,"away":null,"oper?":false,"raw":":Daniella29!~Daniella2@95.141.20.196 PRIVMSG #emberjs : Hi! I give you some videos. I hope you like! http://bit.do/my_videos69"}
{"user":"~Natalia18","host":"95.141.20.196","realname":null,"authname":null,"idle":0,"signed_on_at":null,"unknown?":false,"online?":true,"channels":[],"secure?":false,"away":null,"oper?":false,"raw":":Natalia18!~Natalia18@95.141.20.196 PRIVMSG #emberjs : Here some videos. I hope you like them! http://bit.do/my_videos69"}
{"user":"~Renee21","host":"95.141.20.196","real
App.initializer
name: 'someInitializer'
after: 'store'
initialize: (container, application) ->
container.register 'authManager:main', App.AuthManager
application.inject 'route', 'authManager', 'authManager:main'
application.inject 'authManager', 'store', 'store:main'
function getFeedsList() {
return new RSVP.Promise(function(resolve, reject) {
function getFeedsKeys() {
client.smembers("feeds", function(error, obj) {
if (error) throw(error);
return obj;
});
}
function getFeedsMetadata(feedsKeys) {

From http://madhatted.com/2013/8/31/emberfest-presentation-complex-architectures-in-ember

I find that most successful Ember projects follow a simple pattern for application design:

  • Controllers present information to templates. And not much else, ideally.
  • Actions are handled on routes. This makes routes (which can access models and arbitrary controllers via controllerFor) and controllers each responsible for a different set of concerns.
App.CommentsController = Em.ArrayController.extend({
needs: ['user'],
showDeleteCommentButton: Em.computed.alias('controllers.user.isAdmin')
});