Question

R:1

They are not mutually exclusive as stated in this SO Post

This is a specific question related to this more general SO Post

However a controller is suppose to route all calls from the User. I do this by initializing my elements ( setting the addEventListener ) and having them call the Model.

For example: ( from my control object )

signin_input.addEventListener( "keypress", function( event )
{ 
    if( event.keyCode === 13 )
    {
        new ModelType( 'signin' ).invoke();
        return false; 
    }

}, false );

But as my site grows my Controller is getting big.

One thing I could do is move initialization into it's respective module. For example my Sign In logic is in an object called ModelType. The initialization is in the object Control.

To reduce the size of Control I could move initialization into ModelSignIn.

Or I could just break up my Controller Object into multiple objects - ControlPage1, ControlPage2, etc.

Which way is best or what other way is best?

One benefit to moving initialization into the correlative object is that now the object is self contained and you can copy paste it into other applications. Downside is that this seems to break the MVC pattern.

Was it helpful?

Solution

Since it has been several days and no one else has offered an answer, I will give it a shot. While I haven't tried using an MVC pattern with JavaScript, I have used it for PHP, so perhaps it would work for your framework too.

For the MVC I designed in PHP, I use htaccess to route all php files through the index which loads the default controller (basic controller framework) and then uses the requested filename to see if there are any sub-controllers (which may or may not override certain functions or attributes of the default).

The controller will load the default model and view (and any sub-model/sub-view related to the requested page).

I use this as a way to keep the main controller from becoming cluttered. Perhaps it's not a true MVC pattern, but it has served me well for the past 5 years or so.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top