我在章节示例代码中看到了这些事件,但文档或源代码中没有任何解释.似乎这意味着它是一个全局事件,触发一个动作.那是对的吗?它们只是一种惯例,还是以某种方式强制执行?
# Handle login
@subscribeEvent 'logout',@logout
@subscribeEvent 'userData',@userData
# Handler events which trigger an action
# Show the login dialog
@subscribeEvent '!showLogin',@showLoginView
# Try to login with a service provider
@subscribeEvent '!login',@triggerLogin
# Initiate logout
@subscribeEvent '!logout',@triggerlogout
最佳答案
引自GitHub issue regarding the same question:
!logout
is more a inter-module message or command. It allows one
module to trigger the logout (for example a view with a logout
button). The actual logout process is then handled by another module
(for example the session controller). This module invalidates the
session on the server,for example. When successful,it emits alogout
event which means thelogout
has happened. All modules which are
interested in login/logout should subscribe tologout
.
我认为这很好地解释了它.基本上是!启动操作时触发事件,并在操作成功时触发正常事件.