MVC 专家将如何处理这些模型属性更改及其控制器后果?
我正在开发一个 JavaScript 应用程序,该应用程序应该根据 URL 哈希中的设置或基于用户交互来呈现可视化效果。
(目前我正在使用 Backbone.js 进行 MVC,但我认为这些问题可能被认为与框架无关......?)
假设用户正在查看带有指示器 A 和指示器的应用程序状态选了B。 用户将指标 B 更改为 C,会发生什么?
那么,更改指示器应该会导致模型等待获取和操作新数据。
...然后,当然,更改指标将对不同视图产生许多影响:
- 要显示的可用实体将发生变化,
- 比例尺将发生变化,
- 指标标签将发生变化,等等...
此阶段的一个问题如何处理所有这些因变量/计算变量?
在这种情况下,模型现在还应该根据指标的变化跟踪数据可用性和规模等吗?因此,它是否也应该触发所有这些计算属性的更改事件?
在任何情况下,“主可视化控制器”现在都必须收到有关模型更新的通知,但它是如何进行的呢?
在这种情况下,指示器发生变化,这应该会导致添加和减去图标、更改标签等。
在另一种情况下,只有年份可能会改变。然后控制器应该运行另一条路径吗?
在第三种情况下,年份和指标都可能发生变化(例如,当设置初始 URL 哈希值时)……链中还要触发另一组函数?
我正在寻找一种强大的方法来处理这些不同的场景,以便我可以跟踪何时应该发生什么。我特别感兴趣的是您对模型中应保留哪些属性以及如何布局控制器功能以便能够呈现对模型的小型用户交互更改以及多属性更改的看法。
I'm developing a JavaScript application that should render a visualization based on either settings in the URL hash or based on user interaction.
(For the moment I'm using Backbone.js for MVC but I think these questions may be considered framework agnostic ...?)
Let's say a user is looking at an application state with indicator A and indicator B selected.
The user changes indicator B to C, what happens?
Well, changing indicator should cause the model to wait for new data to be fetched and manipulated.
... and then, of course, changing an indicator will have many effects on the different views:
- The available entities to show will change
- The scales will change
- The indicator label will change, etc, etc. ...
One question at this stage is what to do with all these dependent/computed variables?
Should the model, in this case, now also keep track of the data availability and the scale etc, based on the change of indicator? And should it hence also trigger change events for all these computed attributes?
In any case, "the main visualization controller" must now be notified about an update to the model, but how does it proceed?
In this case, there was an indicator change which should cause icons to be added and subtracted, labels to change etc. etc.
In another scenario, only the year might change. Should the Controller then run another pathway?
And in a third scenario, both year and indicators might change (for example when the initial URL hash is set) ... yet another set of functions to be triggered in chain?
I'm looking for a robust way of handling these different scenarios so that I can keep track of what should happen when. What I'm specifically interested in, is your opinion on what attributes to keep in the model and how to layout the controller functions in order to be able to render small user interaction changes to the model as well as multi-attribute changes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对backbone.js非常很陌生,所以请把我的建议当作所有的盐,其中有可能含有一些物质。
如果我正确理解您的担忧(其中之一),那么您不喜欢在进行更改时完全重新呈现视图的想法;但您仍然喜欢仅将一个视图附加到该模型的想法,如果是这种情况,您可以创建多个渲染事件并将它们与该特定属性更改绑定吗?
I'm VERY new to backbone.js, so take my suggestion as all salt, with a slight chance of having some substance in there.
If I am understanding (one of) your concerns correctly, you do not like the idea of having a view that re-renders completely when changes are made; but you still like the idea of having just one view attached to that one model, if that is the case, can you create multiple render events and have them tied to that specific attribute change?