My webapp allows its users to interact with items. These items can be put in the trash bin, and thus be removed from regular items. I have a dedicated sub-menu called "trash bin" where users can recycle or delete the items previously put in the trash bin.
I want to conditionally display the trash bin menu, only if there are items in the trash bin depending on the user rights.
However, I don't want to publish the items in the trash bin before the user goes to the trash bin sub-menu.
What I currently do is calling a method which returns a flag (is there or not items in the user trash bin?). But this is not reactive: if another user trash an item, the sub-menu will only appear once the page has been reloaded.
How can I publish a reactive boolean flag?
I considered using one cursor.Observe()
per menu/user and notify the creation (via update) or deletion (via remove) of an item using a publication.changed()
on a fake published collection with one item (with one boolean field) but it seems overkill considering the resources used for the task.
I also considered updating a dedicated field in every user profile when an item status change. Here again, this is too much operations for a simple feature: I would need to assess every user right for each operation involving an item status change, and each time a user rights change, re-assess his right to recycle every item.
The less consuming alternative would be to wrap my method call in the menu template.Autorun()
. However, this is not a reactive solution since it triggers only when the menu is re-rendered.
Have you faced the same kind of issue? Do you have a possible alternative solution in mind (performance-wise)?
答案 0 :(得分:0)
TrashBinState
,其中包含一个包含垃圾箱(可能是共享)状态的文档