问题描述
如何在客户端上构造复杂的单页JS Web应用程序?具体来说,我很好奇如何根据其模型对象,UI组件,任何控制器和对象处理服务器持久性的方式清洁应用程序.
MVC起初似乎很合适.但是,随着UI组件在各个深度嵌套(每个组件都采用自己的作用/反应模型数据,并且每个生成事件都可以直接处理或可能不会直接处理),似乎MVC无法清晰地应用. (但是,如果不是这样,请纠正我.)
-
(这个问题提出了两个建议,提出了两个建议,以使用Ajax,Ajax,显然,除了最琐碎的一页应用外,其他任何东西都需要.)
推荐答案
PUREMVC/JS 最优雅的IMO.我从中学到了很多.我还找到了 Nicholas Zakas撰写的可伸缩JavaScript应用程序架构 nicholas Zakas撰写的帮助,有助于研究客户端体系结构选项.
其他两个提示
- 我发现视图,焦点和输入管理是需要在单页网络应用中特别关注的领域
- 我还发现抽象JS图书馆很有帮助,让门开放以改变您使用的内容,或者在需要时混合匹配.
其他推荐答案
尼古拉斯·扎卡斯(Nicholas Zakas)的演讲由迪恩(Dean)共享,是一个很好的起点.一段时间以来,我也一直在努力回答同样的问题.在制作了几个大规模的JavaScript产品之后,考虑到某人需要,将这些学习作为参考架构进行了考虑.看看:
http://boilerplatejs.org/
它解决了常见的JavaScript开发问题,例如:
- 解决方案结构
- 创建复杂的模块层次结构
- 自我包含的UI组件
- 基于事件的间模块通信
- 路由,历史,书签
- 单元测试
- 本地化
- 文档生成
等.
其他推荐答案
我构建应用程序的方式:
- extjs框架,单页应用程序,在单独的JS文件中定义的每个组件,按需加载
- 每个组件都会联系自己的专用Web服务(有时不止一个),将数据获取到Extjs商店或特殊用途的数据结构
- 渲染使用标准的ExtJS组件,因此我可以将存储店与网格,从记录中加载表格,...
只需选择一个JavaScript框架,然后遵循其最佳实践即可.我最喜欢的是extjs和gwt,但是ymmv.
不要为此滚动自己的解决方案.复制现代JavaScript框架所需的努力太大了.适应现有的东西总是比从头开始构建所有物品更快.
问题描述
How should a complex single-page JS web application be structured on the client-side? Specifically I'm curious about how to cleanly structure the application in terms of its model objects, UI components, any controllers, and objects handling server persistence.
MVC seemed like a fit at first. But with UI components nested at various depths (each with their own way of acting on/reacting to model data, and each generating events which they themselves may or may not handle directly), it doesn't seem like MVC can be cleanly applied. (But please correct me if that's not the case.)
--
(This question resulted in two suggestions of using ajax, which is obviously needed for anything other than the most trivial one-page app.)
推荐答案
MVC architecture of PureMVC/JS is the most elegant IMO. I learned a lot from it. I also found Scalable JavaScript Application Architecture by Nicholas Zakas helpful in researching client side architecture options.
Two other tips
- I've found view, focus, and input management are areas that need special attention in single page web apps
- I also found it helpful to abstract away the JS library, leaving door open to change mind on what you use, or mix & match should the need arise.
其他推荐答案
Nicholas Zakas's presentation as shared by Dean is a very good place to start with. I was also struggling to answer the same question for a while. After doing couple of large scale Javascript products, thought of sharing the learnings as a reference architecture in case someone needs it. Have a look at:
It addresses common Javascript development concerns such as:
- Solution structuring
- Creating complex module hierarchy
- Self contained UI components
- Event based inter module communication
- Routing, History, Bookmarking
- Unit Testing
- Localization
- Document Generation
etc.
其他推荐答案
The way I build apps:
- ExtJS framework, single page app, every component defined in a separate JS file, loaded on-demand
- Every component contacts its own dedicated web service (sometimes more than one), fetching data into ExtJS stores or special-purpose data structures
- The rendering uses standard ExtJS components, so I can bind stores to grids, load forms from records, ...
Just choose a javascript framework, and follow its best practices. My favorites are ExtJS and GWT, but YMMV.
Do NOT roll your own solution for this. The effort required to duplicate what modern javascript frameworks do is too big. It is always faster to adapt something existing than to build it all from scratch.