To help me answer your specific questions, let me talk a little bit about JavaScriptMVC :
The controller will improve your jQuery widgets, taking care of customization / separation, extensibility.
The view adds client-side templates that can be embedded in your application.
The model abstracts the service / data layer, minimizing and localizing JS changes if your server changes.
Steal performs dependency management, compression, and code cleanup. It will even take all of your scripts on all of your pages, identify common dependencies, and combine scripts into optimal payloads.
FuncUnit makes testing your applications as easy as possible.
DocumentJS ... well ... documents your code
.
Now about your specific questions:
How to work with the logic used in several places?
I use the StealJS dependency management system to upload the features I need to my page. Dependency management is absolutely essential for applications of a certain size. RequireJS is a good choice if you can easily build it.
How do you arrange page-specific code
The page code should be as small as possible. This usually involves loading dependencies and the "MainController". This master controller customizes the page to meet the functional / business requirements of this page. It is usually referred to as something like:
App.Controllers.Main
how to stop writing the same patterns
Well, I suggest using a framework that has stable development patterns. In addition, your modules / plugins / widgets should be as small as possible (and verifiable). This will greatly reduce the likelihood of these parts changing.
Finally....
It seems your biggest tension in the fight between:
- general functionality
- several pages
- timely loading time
Therefore, choosing a solid dependency management tool is extremely critical. StealJS can help you get a very optimal load time, but you will have to deviate from the standard JavaScriptMVC directory organization due to your more pages.
RequireJS is more flexible, but you will have to upload many files. This will not only be slow, but the creation of a large number of large JS files that are not very organized will begin.
If you are happy with the download time and feel that they will not force you to compress the code into files that it does not belong to, your current solution looks like it will work.
I believe that the secret to supporting development is how easily your system / structure can isolate problems. It is important to break the application into the smallest parts. In addition, you should test these parts. People get side tracks when they think about the functionality of their pages. But for really large-scale development, you really need something that allows you to break the application into small parts, easily download these parts and somehow make the application continue to work quickly in the production process.