Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : CanJS CRUD example with a RESTful API backend - think-a-doo.net

$
0
0
Couple bigger picture things:

1) Split up the app into multiple files/controls

The tutorial kept everything in one file because it's easier to teach that way in a tutorial format. In a real world app, this app would be split into a bunch of smaller files.

It also looks like the Wines control is dealing with listing wines and displaying a detail view. I would separate these into two separate Controls and use routing to communicate between the two. This way, if a user clicks on a wine in the list control, the route is updated and the detail control responds to that update by getting the wine and displaying it. You also get to split up that mammoth EJS file into two files.

2) Live binding is great...but
So it is really, really great, but copying the attributes from a model instance (which is an observable itself!!) to another observable just to use live binding is madness.

If you are following my suggestion from #1, the detail control will exist, have it's own DOM element and will be using a smaller detail EJS file to render the selected wine. When the route changes and you retrieve the newly selected wine, just re-render all the HTML once by passing the model instance to the view.

3) Dependency management
You should be using Steal, RequireJS or your favorite AMD loader for building your app. It is great for organizing apps with multiple files and allows you to do things like creating a single JS and CSS file for your entire app for example.

Viewing all articles
Browse latest Browse all 3491

Trending Articles