jeudi 3 novembre 2016

Emberjs CRUD templates and logic confusion for Route Handlers and Components

I am very confused with Emberjs.

If I have a CRUD for User entity, I will have index, create, show, update and delete operations and their pages.

For the templates, do we use Route Handler templates or do we use Components?

For example, the Update logic, I have placed it inside my routes/users/update.js file:

import Ember from 'ember';

export default Ember.Route.extend({
    renderTemplate: function() {
        this.render('users/new');
    }

    actions: {
        update: function(id) {
            const user = this.modelFor('users.update');
            user.save();
            this.transitionTo('users');
        },

        willTransition: function(transition) {
            const user = this.modelFor('users.update');
            return user.rollbackAttributes();            
        }
    }
});

screenshot of update page

My folder structure is like this:

folder structure

This is pretty straight forward right?

But someone in the Ember Gitter channel asked me why I put my logic inside the Route Handler instead of inside Components, making me think I'm doing it wrong?

My initial understanding was:

  • Route Handler templates for full pages like CRUD forms
  • Route Handler javascript logic files for CRUD forms submit, delete logic
  • Component templates for small resuable UI like slideshow gallery
  • Component javascript logic files for handling slideshow gallery drag and drop functionality

Isn't that how it is?




Aucun commentaire:

Enregistrer un commentaire