3

如果两次或更多次CachingActivityMapper要求相同的活动实例,则将返回相同的活动实例。Place但是,如果我要去一个与当前位置相等的地方,PlaceController则不会触发PlaceChangeRequestEvent(最终不会触发)。结果,监听那些事件不会做任何事情,也就是说,它甚至不会询问PlaceChangeEventgoTo(...)ActivityManagerCachingActivityMapper在这种情况下它甚至不会请求活动。

所以,我真的不明白CachingActivityMapper. 我错过了什么吗?

4

1 回答 1

4

CachingActivityMapper is of little (to no) use when used alone. It's really meant to be between something like a FilteredActivityMapper and your ActivityMapper.

The original usecase was master-detail; for example, for a mail app, with 2 ActivityManagers, one for the list of mails (master) and the other for a specific message (detail), and we could imagine a third one with a menu or treeview; let's concentrate on the master:

  1. The current place is MailBox("inbox")
    1. the FilteredActivityMapper passes the place as-is to the underlying CachingActivityMapper
    2. the actual ActivityMapper returns an activity for the list of mails in the "inbox"
  2. the user clicks on a mail in the list, going to a new place Message(box="inbox", id="123")
    1. the FilteredActivityMapper transforms the place to MailBox("inbox")
    2. the CachingActivityMapper returns the cached activity, without actually calling the wrapped ActivityMapper; so the ActivityManager won't stop and start the activity, or touch the HasOneWidget it's managing.

There can be variants, for example, the detail mapper could cache the last Message place it seen (where that Message place wouldn't contain the "mail box" information, i.e. Message("123")), and when it receives a MailBox place, it would pass the Message place to the underlying CachingActivityMapper, which would return the cached activity; that would allow the master to change to a new mail box while still displaying the same message in the detail panel (GMail with split display behaves more or less like this).

于 2015-09-03T13:02:53.740 回答