Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #22056
    Carme
    Participant

    Hello there,

    In the 1.6.10 video (Building the View Menu), the createMenuItem and the createLink methods are added to the helpers.js file. Would it be correct to have the createLink method in the model instead?

    The idea I had of the model is that it would be used for methods that work with the data we have at hand, whereas the helpers file is for all the functionality that does not fit neatly in either the view, the model or the controller… Is this “mental model” OK or should I look at it differently?

    Thanks!

    #22074
    Zac Gordon
    Keymaster

    Hi Carme!

    This is a really good question.

    The reason the createMenuItem function went in the helpers file is because it really just server to create HTML markup. It is tied to the menu data, but really it should be written (and maybe even named) to be agnostic to whatever data is passed to it. Really it just creates link or menu markup.

    Technically though since this code has to do with displaying the data, if it were to go somewhere else it would belong in the view. The view contains all the code for what is displayed in the browser. Since this code focuses on markup it could be argued it belongs in the view. The reason I didn’t put it there is that in the future we won’t need to write code like this thanks to libraries. This helper file is meant to mimic a library in that case so the code for creating markup was pulled out of the view.

    You made a really good point though that this code has to do with the data so it should go in the model. Code dealing with data that you will see in the model is more like Get Post X or Set Post X or GetAllPosts and things like that. This model code creates collections or returns individual pieces of data.

    View code also deals with data. It deals with displaying data (data that we get from our models). Since these functions deal with displaying data they technically belong to the view. Since this code for DOM creation can be extracted into it’s own helper “library” it was placed in the helper file.

    Hope this helps explain things better! Again, a really good question!!!

    #22081
    Carme
    Participant

    Thank you Zac, really useful explanation too!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.