GWT的历史和地点之间有什么区别/关系?

时间:2023-01-24 00:07:24

Based on my observation, the History is used in a single html page with multiple AJAX interactions. It just assigns each state to a specific token to distinguish(or mark) them. While for the Places, it's used for different html pages. It assigns each html page to a string token.

根据我的观察,历史记录用于具有多个AJAX交互的单个html页面。它只是将每个状态分配给特定标记以区分(或标记)它们。而对于Places,它用于不同的html页面。它将每个html页面分配给字符串标记。

Is there any relationship between them? And do I understand correctly?

他们之间有什么关系吗?我理解正确吗?

1 个解决方案

#1


4  

As stated in the official documentation:

如官方文件中所述:

A place is a Java object representing a particular state of the UI. A Place can be converted to and from a URL history token (see GWT’s History mechanism) by defining a PlaceTokenizer for each Place, and GWT’s PlaceHistoryHandler automatically updates the browser URL corresponding to each Place in your app.

位置是表示UI的特定状态的Java对象。通过为每个场所定义PlaceTokenizer,可以将场所转换为URL历史令牌(请参阅GWT的历史记录机制),并且GWT的PlaceHistoryHandler会自动更新与应用中每个场所对应的浏览器URL。

So you can think of Places and Activities a higher level above History. For example, you can go to a new "place" in your application by changing the history token with History.newItem("token"). But you can use PlaceController to do the same: placeController.goTo(new TokenPlace()). TokenPlace is explicitly associated with the history token token, has an Activity class instantiated when this place is reached, etc. Under the hoods, History.newItem("token") will still be called, but you don't have to worry about managing history tokens manually. As a bonus, your application will probably become less coupled, because now Activity1 doesn't have to know anything about Activity2 - Activity1 just triggers a move to a new Place. It doesn't care which activity it's associated with.

因此,您可以将地点和活动视为比历史更高级别。例如,您可以通过使用History.newItem(“token”)更改历史记录来转到应用程序中的新“位置”。但您可以使用PlaceController执行相同的操作:placeController.goTo(new TokenPlace())。 TokenPlace与历史令牌令牌显式关联,在到达此位置时实例化Activity类等。在引擎盖下,仍将调用History.newItem(“token”),但您不必担心管理手动历史令牌。作为奖励,您的应用程序可能会变得更少耦合,因为现在Activity1不必知道有关Activity2的任何信息 - Activity1只是触发移动到新的Place。它并不关心它与之相关的活动。

#1


4  

As stated in the official documentation:

如官方文件中所述:

A place is a Java object representing a particular state of the UI. A Place can be converted to and from a URL history token (see GWT’s History mechanism) by defining a PlaceTokenizer for each Place, and GWT’s PlaceHistoryHandler automatically updates the browser URL corresponding to each Place in your app.

位置是表示UI的特定状态的Java对象。通过为每个场所定义PlaceTokenizer,可以将场所转换为URL历史令牌(请参阅GWT的历史记录机制),并且GWT的PlaceHistoryHandler会自动更新与应用中每个场所对应的浏览器URL。

So you can think of Places and Activities a higher level above History. For example, you can go to a new "place" in your application by changing the history token with History.newItem("token"). But you can use PlaceController to do the same: placeController.goTo(new TokenPlace()). TokenPlace is explicitly associated with the history token token, has an Activity class instantiated when this place is reached, etc. Under the hoods, History.newItem("token") will still be called, but you don't have to worry about managing history tokens manually. As a bonus, your application will probably become less coupled, because now Activity1 doesn't have to know anything about Activity2 - Activity1 just triggers a move to a new Place. It doesn't care which activity it's associated with.

因此,您可以将地点和活动视为比历史更高级别。例如,您可以通过使用History.newItem(“token”)更改历史记录来转到应用程序中的新“位置”。但您可以使用PlaceController执行相同的操作:placeController.goTo(new TokenPlace())。 TokenPlace与历史令牌令牌显式关联,在到达此位置时实例化Activity类等。在引擎盖下,仍将调用History.newItem(“token”),但您不必担心管理手动历史令牌。作为奖励,您的应用程序可能会变得更少耦合,因为现在Activity1不必知道有关Activity2的任何信息 - Activity1只是触发移动到新的Place。它并不关心它与之相关的活动。