Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
e02573f0
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e02573f0
编写于
9月 15, 2016
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
event buffer, nextTick, tests
上级
2a8bab87
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
159 addition
and
98 deletion
+159
-98
src/vs/base/common/event.ts
src/vs/base/common/event.ts
+11
-3
src/vs/base/test/common/event.test.ts
src/vs/base/test/common/event.test.ts
+148
-95
未找到文件。
src/vs/base/common/event.ts
浏览文件 @
e02573f0
...
...
@@ -375,7 +375,7 @@ export function stopwatch<T>(event: Event<T>): Event<number> {
* // 4
* ```
*/
export
function
buffer
<
T
>
(
event
:
Event
<
T
>
):
Event
<
T
>
{
export
function
buffer
<
T
>
(
event
:
Event
<
T
>
,
nextTick
=
false
):
Event
<
T
>
{
let
buffer
:
T
[]
=
[];
let
listener
=
event
(
e
=>
{
if
(
buffer
)
{
...
...
@@ -385,6 +385,11 @@ export function buffer<T>(event: Event<T>): Event<T> {
}
});
const
flush
=
()
=>
{
buffer
.
forEach
(
e
=>
emitter
.
fire
(
e
));
buffer
=
null
;
};
const
emitter
=
new
Emitter
<
T
>
({
onFirstListenerAdd
()
{
if
(
!
listener
)
{
...
...
@@ -394,8 +399,11 @@ export function buffer<T>(event: Event<T>): Event<T> {
onFirstListenerDidAdd
()
{
if
(
buffer
)
{
buffer
.
forEach
(
e
=>
emitter
.
fire
(
e
));
buffer
=
null
;
if
(
nextTick
)
{
setTimeout
(
flush
);
}
else
{
flush
();
}
}
},
...
...
src/vs/base/test/common/event.test.ts
浏览文件 @
e02573f0
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
Event
,
{
Emitter
,
fromEventEmitter
,
debounceEvent
,
EventBufferer
,
once
,
fromPromise
,
stopwatch
}
from
'
vs/base/common/event
'
;
import
Event
,
{
Emitter
,
fromEventEmitter
,
debounceEvent
,
EventBufferer
,
once
,
fromPromise
,
stopwatch
,
buffer
}
from
'
vs/base/common/event
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
EventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
Errors
=
require
(
'
vs/base/common/errors
'
);
...
...
@@ -211,7 +211,9 @@ suite('Event',function(){
});
});
suite
(
'
EventBufferer
'
,
()
=>
{
suite
(
'
Event utils
'
,
()
=>
{
suite
(
'
EventBufferer
'
,
()
=>
{
test
(
'
should not buffer when not wrapped
'
,
()
=>
{
const
bufferer
=
new
EventBufferer
();
...
...
@@ -283,9 +285,9 @@ suite('EventBufferer', () => {
listener1
.
dispose
();
listener2
.
dispose
();
});
});
});
suite
(
'
fromPromise
'
,
()
=>
{
suite
(
'
fromPromise
'
,
()
=>
{
test
(
'
should emit when done
'
,
()
=>
{
let
count
=
0
;
...
...
@@ -329,9 +331,9 @@ suite('fromPromise', () => {
});
});
});
});
});
suite
(
'
stopwatch
'
,
()
=>
{
suite
(
'
stopwatch
'
,
()
=>
{
test
(
'
should emit
'
,
()
=>
{
const
emitter
=
new
Emitter
<
void
>
();
...
...
@@ -351,4 +353,55 @@ suite('stopwatch', () => {
setTimeout
(()
=>
emitter
.
fire
(),
10
);
});
});
});
suite
(
'
buffer
'
,
()
=>
{
test
(
'
should buffer events
'
,
()
=>
{
const
result
=
[];
const
emitter
=
new
Emitter
<
number
>
();
const
event
=
emitter
.
event
;
const
bufferedEvent
=
buffer
(
event
);
emitter
.
fire
(
1
);
emitter
.
fire
(
2
);
emitter
.
fire
(
3
);
assert
.
deepEqual
(
result
,
[]);
const
listener
=
bufferedEvent
(
num
=>
result
.
push
(
num
));
assert
.
deepEqual
(
result
,
[
1
,
2
,
3
]);
emitter
.
fire
(
4
);
assert
.
deepEqual
(
result
,
[
1
,
2
,
3
,
4
]);
listener
.
dispose
();
emitter
.
fire
(
5
);
assert
.
deepEqual
(
result
,
[
1
,
2
,
3
,
4
]);
});
test
(
'
should buffer events on next tick
'
,
()
=>
{
const
result
=
[];
const
emitter
=
new
Emitter
<
number
>
();
const
event
=
emitter
.
event
;
const
bufferedEvent
=
buffer
(
event
,
true
);
emitter
.
fire
(
1
);
emitter
.
fire
(
2
);
emitter
.
fire
(
3
);
assert
.
deepEqual
(
result
,
[]);
const
listener
=
bufferedEvent
(
num
=>
result
.
push
(
num
));
assert
.
deepEqual
(
result
,
[]);
return
TPromise
.
timeout
(
10
).
then
(()
=>
{
emitter
.
fire
(
4
);
assert
.
deepEqual
(
result
,
[
1
,
2
,
3
,
4
]);
listener
.
dispose
();
emitter
.
fire
(
5
);
assert
.
deepEqual
(
result
,
[
1
,
2
,
3
,
4
]);
});
});
});
});
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录