Loading entire modules at once using backbone.js (multiple views, models, collections)

安稳与你 提交于 2019-12-08 08:07:59

问题


I've been toying with the idea of rebuilding a very antiquated in-house CMS using backbone.js so that I build more of an app than a website. So far I'm comfortable with backbone and I've added in require.js to break the application into modules but there's one small thing that's bothering me.

My impression of backbone is that it would be possible to deliver the application to the user in a single initial payload but since adding require.js all models, collections, views, and templates are fetched individually on an ad-hoc basis.

Is it possible to break my application into modular payloads? For instance if the user enters the news section of the CMS they are delivered all the views, models etc. required for that module? The only solution I can think of is wrapping all the pieces of a module in a single define function call but this seems to break the paradigm of uncoupling the pieces of the application as a whole.

Any suggestions?


回答1:


Short answer:

try using requirejs modules

Long answer:

Check this out

https://github.com/ravihamsa/base-example/ 

I made an boiler-plate using requirejs, I call every module as an app, you can compile one JS file per module, and coupled with coupled with

https://github.com/ravihamsa/baseapp/ 

you can load each module on demand. But you got to follow the url pattern I do follow. like

http://yourapp.com/#appId/pageId/param1=value1;param2=value2

Whole app architecture is work in progress but you get enough insights




回答2:


I think I've figured this out for myself. It looks like it's possible to use r.js (http://requirejs.org/docs/download.html#rjs) to compile modules into a single script which is exactly what I need.



来源:https://stackoverflow.com/questions/19248495/loading-entire-modules-at-once-using-backbone-js-multiple-views-models-collec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!