gpt4 book ai didi

javascript - 在 Chaplin js 框架中,以 ! 为前缀的事件是做什么的?意思?

转载 作者:搜寻专家 更新时间:2023-11-01 04:18:39 32 4
gpt4 key购买 nike

我看到这些事件散布在 chaplin 示例代码中,但在文档或源代码中没有任何解释。似乎这意味着它是一个全局事件,触发了一个 Action 。那是对的吗?它们只是一个惯例,还是以某种方式强制执行?

# 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 a logout event which means the logout has happened. All modules which are interested in login/logout should subscribe to logout.

我认为这解释得很好。基本上 ! 事件在 Action 开始时触发,普通事件在 Action 成功时触发。

关于javascript - 在 Chaplin js 框架中,以 ! 为前缀的事件是做什么的?意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15008754/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com