Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no suggested "model" folder in a Durandal app?

Tags:

mvvm

durandal

I'm working on a Durandal SPA, and I've setup some views and viewmodels. However, I thought the MVVM architecture would also involve a "model" segment (Model, View, ViewModel--right?).

However, the Durandal Getting Started page says this under the "Organization" section:

If you expand the App folder, you will find the source for the entire SPA sample. Here's the high level organization you will find:

  • App
    • durandal/
    • viewmodels/
    • views/
    • main.js

Absent from this structure is a "models" folder. Where are you supposed to put your models in a Durandal app?

I've looked at some other sample apps, and I can't find a "models" folder (or anywhere that models are residing) for any of the sample apps I've reviewed.

The "models" folder (which isn't there) seems to me to be a critical part of a Durandal app. However, it's not there--and therefore, I am questioning my understanding of how Durandal (and MVVM apps) are designed. There is surely something I am not understanding... can someone fill me in on the intended structure of a Durandal app, and where to put your model objects?

like image 226
Josh Avatar asked Dec 07 '25 10:12

Josh


2 Answers

The answer is that Durandal only gives you the structure necessary to run, and nothing more. It uses a viewmodels and views folder, so it tells you to make one. Durandal doesn't use a models folder, you do.

I make one in my projects. If you feel like it fits your dev style, you can and should make one yourself.

Notice that it also leaves no place for code that is not a viewmodel, which surely will exists in any application. I highly recommend making a modules folder for this purpose.

Don't think that the only things you can or should do are the ones you see done in the Durandal tutorials. You are the developer. You will have to build on top of what Durandal provides, and this means making your own choices.

like image 102
Kyeotic Avatar answered Dec 12 '25 00:12

Kyeotic


In my applications, the models have always been defined by the REST services or WebAPIs that the app makes requests against. I haven't had a need to define those models in the application code. The models are defined by the server/service side.

When using something like Breeze, the model is just a JSON representation of your entity models in your database.

If you feel more comfortable defining those models in your application code, you are more than welcome to. If I did something like that, I would put it in a App\models folder as you suggested. I don't think you will need to do this most of the time, though.

like image 40
blachniet Avatar answered Dec 11 '25 23:12

blachniet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!