2

The project I'm working on is a single page web application developed using MVVM as design pattern.

Aside the first request for the entire page every other transaction is JSON-based, every JSON is binded using Knockout at presentation level.

At the moment we're developing the whole application using a single Knockout-viewModel, every single JSON is being parsed inside the viewModel and binded to the presentation level.

Now, considering how big is the viewModel at the moment I'm wondering if it's a good practice to split the whole thing in different (smaller) viewModels specifically binded to a single element in a page (like it's described in this article), making heavy use of the mapping plugin of Knockout to generate the empty structure (and refresh the datas).

In case this isn't the best practice, how do you suggest to manage the JSON binding? At the moment we're using $.jsonparse() to obtain an object then we push the different datas inside some observable array. But I don't think this is the best way to approach this problem.

Thank you.

Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212
Abaco
  • 525
  • 7
  • 26
  • 1
    This answer might help a bit: http://stackoverflow.com/questions/8676988/example-of-knockoutjs-pattern-for-multi-view-applications/8680668#8680668. Currently, I mainly use require.js to load a view model and a template to populate an area of the page (somewhat similar to the last option in the answer) – RP Niemeyer Dec 12 '12 at 19:55

1 Answers1

3

I'm a big fan of fanning out complexity across lots of smaller modules, rather than a single monolithic module with all the complexity.

I tend to have multiple view models and communicate between them using the Knockout.Postbox library.

Judah Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212