Your Front end is not your back end

Or, don't let your database design your app

Andre Malan
http://andremalan.net
@ramcio

Red Rover
http://getredrover.com

Default thinking


Model-> Serializer-> Em Model-> Em Controller-> EM View


Front End Thinking

Template->Em View-> Em Controller-> Em Model -> Controller -> Model 


REsult

Simple Ember Code... especially around persistence

Example

Real life code


Design by Database

(not even going to begin to try pseudocode it)

  • create + save user  .then
  • create+save network .then
  • create+save profile .then
  • create + save bot

Transactions, promises, prayers to the Ember Data gods


Design by UX



  • Create BotSignup... save

 


App.SignupController = Ember.Controller.extend({
  ownerName: '',
  email: '',
  save: function() {
    var bot = App.BotSignup.createRecord({
      ownerName: this.get('ownerName'),
      email: this.get('email')
      botType: ths.get('botType')
    });
    bot.save().then(saveOK,saveError);
  }
});



 class BotSignupsController < ApplicationController
  def create
    bot_signup = BotSignup.create! json_response: params[:bot_signup]
    bot_signup.process_create!
    render json: bot_signup
  end

  def update
    bot_signup = BotSignup.find(params[:id])
    bot_signup.process_update!(params[:bot_signup])
    render json: bot_signup
  end
end
 App.BotSignup = DS.Model.extend({
  ownerName: DS.attr('string'),
  email: DS.attr('string'),
  botName: DS.attr('string'),
  botType: DS.attr('string')
});


Is it The RIght thing to do?



  • Separation of Concerns: 
    Ember => UX.
    Rails => Persistence, state of the world.
  • Single Responsibility:  
    One reason to change... UX.
  • Tell, Don't ask:
    Signup just cares about user input... tells API about it.


The ROUter is our world

Let something else deal with the database

 Redbot.Router.map ->
  @route "intro"
  @resource "directory", ->
    @route 'members'
    @route 'robots'
    @route 'contacts'
  @route "invite"
  @route "settings"
  @route "delete"

  @resource "bots", path: "/bots", ->
    @route "new"
  @resource "posts", path: "/posts", ->
    @route "new"
    @route "newArticle"
    @route "newLink"
    @route "newPhoto"
    @route "newFile"


YOUR FRONT END IS NOT YOUR BACK END

Or, don't let your database design your app

Andre Malan
http://andremalan.net
@ramcio

Red Rover
http://getredrover.com

Your Front end is not your back end.

By Andre Malan

Your Front end is not your back end.

  • 8,989