javascript – 在Chaplin js框架中,事件前缀是什么!意思?

前端之家收集整理的这篇文章主要介绍了javascript – 在Chaplin js框架中,事件前缀是什么!意思?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

我认为这很好地解释了它.基本上是!启动操作时触发事件,并在操作成功时触发正常事件.

原文链接:https://www.f2er.com/js/429707.html

猜你在找的JavaScript相关文章