Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d9d7371c
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d9d7371c
编写于
6月 25, 2015
作者:
J
Javan Makhmali
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Assume subscribers have an identifier
上级
53d0b22a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
26 addition
and
22 deletion
+26
-22
lib/assets/javascripts/cable.js.coffee
lib/assets/javascripts/cable.js.coffee
+2
-5
lib/assets/javascripts/cable/channel.js.coffee
lib/assets/javascripts/cable/channel.js.coffee
+3
-3
lib/assets/javascripts/cable/subscriber_manager.js.coffee
lib/assets/javascripts/cable/subscriber_manager.js.coffee
+21
-14
未找到文件。
lib/assets/javascripts/cable.js.coffee
浏览文件 @
d9d7371c
...
...
@@ -13,8 +13,5 @@ class @Cable
params
=
if
typeof
channel
is
"object"
then
channel
else
{
channel
}
new
Cable
.
Channel
this
,
params
,
mixin
sendMessage
:
(
identifier
,
data
)
->
@
sendCommand
(
identifier
,
"message"
,
data
)
sendCommand
:
(
identifier
,
command
,
data
)
->
@
connection
.
send
({
identifier
,
command
,
data
})
send
:
(
data
)
->
@
connection
.
send
(
data
)
lib/assets/javascripts/cable/channel.js.coffee
浏览文件 @
d9d7371c
...
...
@@ -2,7 +2,7 @@ class Cable.Channel
constructor
:
(
@
cable
,
params
=
{},
mixin
)
->
@
identifier
=
JSON
.
stringify
(
params
)
extend
(
this
,
mixin
)
@
cable
.
subscribers
.
add
(
@
identifier
,
this
)
@
cable
.
subscribers
.
add
(
this
)
# Perform a channel action with the optional data passed as an attribute
perform
:
(
action
,
data
=
{})
->
...
...
@@ -10,10 +10,10 @@ class Cable.Channel
@
send
(
data
)
send
:
(
data
)
->
@
cable
.
send
Message
(
@
identifier
,
JSON
.
stringify
(
data
))
@
cable
.
send
(
command
:
"message"
,
identifier
:
@
identifier
,
data
:
JSON
.
stringify
(
data
))
unsubscribe
:
->
@
cable
.
subscribers
.
remove
(
@
identifier
)
@
cable
.
subscribers
.
remove
(
this
)
extend
=
(
object
,
properties
)
->
if
properties
?
...
...
lib/assets/javascripts/cable/subscriber_manager.js.coffee
浏览文件 @
d9d7371c
...
...
@@ -2,25 +2,32 @@ class Cable.SubscriberManager
constructor
:
(
@
cable
)
->
@
subscribers
=
{}
add
:
(
identifier
,
subscriber
)
->
add
:
(
subscriber
)
->
{
identifier
}
=
subscriber
@
subscribers
[
identifier
]
=
subscriber
if
@
cable
.
sendCommand
(
identifier
,
"subscribe"
)
@
notify
(
identifi
er
,
"connected"
)
if
@
sendCommand
(
"subscribe"
,
identifier
)
@
notify
(
subscrib
er
,
"connected"
)
reload
:
->
for
identifier
in
Object
.
keys
(
@
subscribers
)
if
@
cable
.
sendCommand
(
identifier
,
"subscribe"
)
@
notify
(
identifi
er
,
"connected"
)
for
identifier
,
subscriber
of
@
subscribers
if
@
sendCommand
(
"subscribe"
,
identifier
)
@
notify
(
subscrib
er
,
"connected"
)
remove
:
(
identifi
er
)
->
if
subscriber
=
@
subscribers
[
identifier
]
@
cable
.
sendCommand
(
identifier
,
"unsubscribe"
)
delete
@
subscribers
[
identifier
]
remove
:
(
subscrib
er
)
->
{
identifier
}
=
subscriber
@
sendCommand
(
"unsubscribe"
,
identifier
)
delete
@
subscribers
[
identifier
]
notifyAll
:
(
event
,
args
...)
->
for
identifier
in
Object
.
keys
(
@
subscribers
)
@
notify
(
identifi
er
,
event
,
args
...)
for
identifier
,
subscriber
of
@
subscribers
@
notify
(
subscrib
er
,
event
,
args
...)
notify
:
(
identifier
,
event
,
args
...)
->
if
subscriber
=
@
subscribers
[
identifier
]
notify
:
(
subscriber
,
event
,
args
...)
->
if
typeof
subscriber
is
"string"
subscriber
=
@
subscribers
[
subscriber
]
if
subscriber
subscriber
[
event
]
?
(
args
...)
sendCommand
:
(
command
,
identifier
)
->
@
cable
.
send
({
command
,
identifier
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录