客户端 MVC 框架适合构建 UI 控件吗
最近我一直在考虑开发类似于 Extjs 或 YUI 的 UI 控件套件,但使用像 Backbone 或 Spine 这样的 MVC 框架。我的这个决定有错吗? mvc框架适合这样的开发目的吗?维护这样一个项目的意义和成本是什么?
Lately i have been thinking of developing UI controls suite similar to Extjs or YUI but using a MVC framework like Backbone or Spine. Am i wrong in taking this decision? Will a mvc framework suit the purpose of such development? What would the significance, cost of maintaining such a project would be.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从技术上讲,我不明白为什么你不能这样做。您将放弃 Backbone 的“路由器”部分并坚持使用模型、集合和视图。您可能还会放弃集合和模型的所有后端同步功能,转而使用自己与客户端应用程序的界面。您还必须想出一种方法来普遍应用 Backbone 渲染模式,以允许客户端应用程序托管您的小部件。您仍然可以得到一些关注点分离,并且您的小部件工具包可以工作。
但是,我不知道我是否会推荐它。通过围绕 Backbone 构建小部件工具包,您需要将用户绑定到 Backbone、Underscore 以及可能的 jQuery。您会这样做,但会放弃 Backbone 必须提供的许多功能(例如路由和同步)。如果客户端应用程序也使用 Backbone,您还可能会遇到版本不兼容问题,因此您必须使用
noConflict
来处理该问题。总而言之,在我看来,您将一整套工具硬塞进您的小部件套件中,以获得最小的收益。你的小部件套件很快就会变得又胖又臃肿。相反,我会尝试让我的小部件套件更加轻量。使用您在 Backbone 中学到的模式,但不要使用 Backbone 本身。甚至考虑删除一些 Backbone 代码来作为基础设施的基础,但对其进行修改以消除您不会使用的功能并使其成为您自己的功能。
Technically, I don't see why you can't do this. You would forgo the "router" portion of Backbone and stick with Models, Collections and Views. You would probably also forgo all of the backend syncing capabilities of the Collections and Models in favor of your own interface with the client application. You would also have to come up with a way to apply the Backbone render pattern generically to allow the client app to host your widgets. You would get some separation of concerns still and your widget kit would work.
But, I don't know if I would recommend it. By building a widget kit around Backbone, you are requiring that your users be bound to Backbone, Underscore and probably jQuery as well. You'd be doing this but throwing out many of the features that Backbone has to offer (like routing and syncing). If the client application is also using Backbone, you might also get into version incompatibility issues, so you'd have to deal with that by using
noConflict
.In all, it would feel to me like you are shoehorning a whole suite of tools into your widget kit for minimal gain. Your widget kit would be fat and bloated right off the bat. Instead, I would try to make my widget kit more lightweight. Use the patterns you've learned in Backbone but don't use backbone itself. Even consider ripping some of the Backbone code out to base your infrastructure off of, but modify it to eliminate the features that you won't be using and make it your own.