page JavaScript web application?

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:

    http://boilerplatejs.org/

    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.

    链接地址: http://www.djcxy.com/p/17060.html

    上一篇: 这种定义JS对象的方式有什么用处吗?

    下一篇: 页面JavaScript Web应用程序?