3

The CachingActivityMapper will return the same activity instance if asked for the same Place twice or more. However, PlaceController will not fire a PlaceChangeRequestEvent (and ultimately no PlaceChangeEvent) if I was to goTo(...) a place that equals the current one. As a result, the ActivityManager listening to those events will not do anything, that is, it won't even ask the CachingActivityMapper for an activity in this case.

So, I don't really see the point of CachingActivityMapper. Am I missing something?

tur
  • 328
  • 1
  • 8

1 Answers1

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).

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • Thanks for your detailed answer, Thomas! – tur Sep 03 '15 at 13:44
  • I lost the count of how many times your answers helped me. Thank you again. My screen flickered every time upon a place switch, because my HeaderView, ContentView, FooterView etc. were attached to MainView, which in turn had to be detached/attached every single time. Regardless how fast the computer running the app was, flickering was noticeable anyway. By filtering places I finally managed to solve this issue. – vitrums Jan 08 '16 at 21:39