如何编写模块化的 JavaScript 应用程序?
我计划使用 HTML、JavaScript 和 CSS 重写现有的 Silverlight 应用程序。这将是一个富互联网应用程序,仅连接到服务器以获取数据(基于 JSON 的 Web 服务),因此不会有服务器端表示框架,例如 JSP 或 ASP.NET。该应用程序由大约 8 个屏幕组成,其中大部分采用选项卡式布局。问题是......
以模块化方式编写此类应用程序的最佳方法是什么?我想将各个屏幕编写为仅通过事件相互通信的独立模块。我还想使用某种 MVC 框架来将表示层与模型分离。
关于我应该考虑哪些框架有什么想法吗?您使用它们有良好的体验吗?我开始查看 Backbone.js,JavaScriptMVC 和 SproutCore。我是否错过了任何值得考虑的事情?
预先感谢您的宝贵时间。
PS 如果您想查看我尝试重写的应用程序,可以使用在线演示 这里 - 这是一个为学习和比较技术而构建的现实交易应用程序。
I am planning to rewrite an existing Silverlight application using HTML, JavaScript and CSS. This will be a rich internet application connecting to a server only for data (JSON based web services) - so there will be no server-side presentation framework such as JSP or ASP.NET. The application consists of about 8 screens, most of them in a tabbed layout. The question is...
What is the best way to write such an application in a modular fashion? I would like to write the individual screens as standalone modules communicating with each other only via events. I would also like to use some sort of an MVC framework to decouple the presentation layer from the model.
Any thoughts on which frameworks I should look at? Have you had a good experience using them? I am starting to look at Backbone.js, JavaScriptMVC and SproutCore. Am I missing anything that is worth considering?
Thanks in advance for your time.
P.S. If you'd like to see the application that I am trying to rewrite, an online demo is available here - it is a realistic trading application built for learning and comparing technologies.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我还没有机会尝试 SproutCore,但我听到了一些关于它的好消息,并且想在某个时候研究一下它。我建议至少尝试一下 Backbone 和 Sproutcore,看看两者中哪一个更适合您的需求和您的编程风格。
我用 Backbone 做了很多工作,你的建议听起来很容易与 Backbone 配合。我的主干应用程序遵循事件驱动的架构,我发现它工作得很好。它使代码保持干净和分离,并允许我通过绑定到我的对象引发的事件来轻松添加功能。
那里也有很多很棒的骨干教程和截屏视频。这里有一些希望能为您提供一些您需要的信息(包括我自己的博客文章):
,不要只选择一个就不再回头。如果不是额外的框架,至少值得您花时间在主干和 sproutcore 中做一些简单的试用应用程序。
希望有帮助。
I haven't yet had a chance to try SproutCore, but I hear good things about it and want to look into it at some point. I would recommend trying out at least Backbone and Sproutcore to see which of the two fits your needs and your programming style better.
I do a lot of work with Backbone, and what your suggesting sounds like it would be a very easy fit with backbone. I follow an event-driven architecture with my backbone apps and I find it works very well. it keeps code clean and separated, and allows me to add functionality easily by binding to events that my objects raise.
there are a lot of great tutorials and screencasts for backbone out there, too. here a few of them that should hopefully give you some of the information you need (including my own blog posts):
again, don't just pick one and never look back. it's worth your time to at least do some simple trial applications in backbone and sproutcore, if not additional frameworks.
hope that helps.
使用 Sproutcore,您可以创建所谓的框架来分离您的应用程序。每个 SC 项目都有一个
frameworks
目录,您只需为自定义框架添加一个目录,并将框架包含在构建文件中。对于 SC,至少将模型层分离到它自己的框架中并不是一个坏主意,出于松散耦合和测试的目的(SC 很大程度上是 MVC)。将您的屏幕分成自己的框架可能是有意义的,具体取决于它们的强大程度。这种方法的好处之一是,如果需要,您可以在其他项目中重用您的框架。
SC 还包括一个强大的状态图机制,因此使用自定义事件是非常自然的,并且由于状态图,确保仅当应用程序处于正确状态时才处理事件相对容易。
With Sproutcore, you can create so-called frameworks so separate your application. Every SC project has a
frameworks
directory, you just add a directory for your custom frameworks, and include the frameworks in your buildfile.It's not a bad idea with SC to at least separate your Model layer into its own framework, for loose coupling and testing purposes (SC is heavily MVC). It might make sense to separate your screens into their own frameworks, depending on how beefy they are. One of the benefits of this approach is you can reuse your frameworks in other projects if needed.
SC also includes a robust Statechart mechanism, so using custom events is quite natural, and because of the statecharts its relatively easy to insure that the events are handled only when the app is in the right state.
您尝试过 Relay 框架吗?您将各个屏幕编写为独立模块,并使用中继的事件系统将它们链接在一起。
http://relay.github.com
Have you tried the Relay framework? Your write your individual screens as standalone modules and use relay's event system to link them together.
http://relay.github.com