NOTE: In a larger app, it’s pretty common to place code that interacts with the backend in separate files, and not directly in the view models. But in our case, the connection code lives directly in the view model for simplicity—which is perfectly reasonable for small apps.
Could somebody show example what does it means? How to organize code more correctly for large app? What part of code should be contained in view model and what in separate file, and how they should be interact.
Your answer does not contain example of separating interacting with backend server from the view-model.
My question is about why in large apps view-model should not contain code that interacts with backend server? And how it should be organized (best practice).
Right it technically doesn’t But I was just trying to show you in a sample HOW you would go about that. Make a new file, put the code in there, import it from where you need it.
Don’t put too much stock in “should not contain code”, it perfectly well could. It’s just in an enterprise\large app you want abstraction to make testing easier, or more readable. This isn’t a nativescript concept, just general nicer way to handle things.
For ME (In a plain TS app) I have 3 root folders, /views, /scripts (or helpers), and /models. So views are my xml\ts view code, helpers or custom classes are in /scripts and /models are my… models.