I'm staring with Knockout.js and I didn't find much documentation about how to properly structure a knockout application.
It is easy to follow the tutorial from the docs and its multiple examples in them or in other pages, but there's no much about the good practices regarding the file structure.
I've seen some videos of Steve Sanderson talking about how to architect a big project but they seem to be going a bit too far me. He mentions the Yeoman tool to generate a basic KO structure, but I'm using Node.js with Express.js and I already have another structure I'm working with and I'm not quite sure about how to mix both.
What I'm having at the moment is 3 main files:
- functions.js
- viewmodels.js (ko viewmodels and domain classes)
- events.js (for jQuery events)
As you can see, the viewmodels.js
file will become bigger and bigger so I was thinking about separating each viewmodel with its associated domain classes in different files.
The problem I found is that some of my viewmodels are related with each other as they have to access to each other data at some point.
I'm making use of a mastermodel at the moment for it:
var MasterModel = function(){
this.user = new UserViewModel();
this.department = new DepartmentViewModel();
}
var mm = new MasterModel();
ko.applyBindings(mm);
So I can do things such as mm.user.sayHi()
from a departmentViewModel
Any suggestions regarding the structure issue?