Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
562f28f4
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,发现更多精彩内容 >>
提交
562f28f4
编写于
4月 14, 2017
作者:
A
Alex Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More EventEmitter cleanup
上级
a9c372aa
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
54 addition
and
65 deletion
+54
-65
src/vs/base/common/eventEmitter.ts
src/vs/base/common/eventEmitter.ts
+26
-37
src/vs/base/parts/tree/browser/treeModel.ts
src/vs/base/parts/tree/browser/treeModel.ts
+1
-1
src/vs/base/test/common/eventEmitter.test.ts
src/vs/base/test/common/eventEmitter.test.ts
+2
-2
src/vs/editor/browser/widget/diffEditorWidget.ts
src/vs/editor/browser/widget/diffEditorWidget.ts
+5
-5
src/vs/editor/common/commonCodeEditor.ts
src/vs/editor/common/commonCodeEditor.ts
+6
-6
src/vs/editor/common/controller/cursor.ts
src/vs/editor/common/controller/cursor.ts
+2
-2
src/vs/editor/common/services/modelServiceImpl.ts
src/vs/editor/common/services/modelServiceImpl.ts
+3
-3
src/vs/editor/common/viewModel/viewModelImpl.ts
src/vs/editor/common/viewModel/viewModelImpl.ts
+4
-4
src/vs/editor/contrib/codelens/browser/codelens.ts
src/vs/editor/contrib/codelens/browser/codelens.ts
+1
-1
src/vs/workbench/parts/debug/electron-browser/debugService.ts
...vs/workbench/parts/debug/electron-browser/debugService.ts
+1
-1
src/vs/workbench/parts/debug/electron-browser/debugViews.ts
src/vs/workbench/parts/debug/electron-browser/debugViews.ts
+3
-3
未找到文件。
src/vs/base/common/eventEmitter.ts
浏览文件 @
562f28f4
...
...
@@ -9,20 +9,12 @@ import { IDisposable } from 'vs/base/common/lifecycle';
export
class
EmitterEvent
{
p
rivate
_
type
:
string
;
p
rivate
_
data
:
any
;
p
ublic
readonly
type
:
string
;
p
ublic
readonly
data
:
any
;
constructor
(
eventType
:
string
=
null
,
data
:
any
=
null
)
{
this
.
_type
=
eventType
;
this
.
_data
=
data
;
}
public
getType
():
string
{
return
this
.
_type
;
}
public
getData
():
any
{
return
this
.
_data
;
this
.
type
=
eventType
;
this
.
data
=
data
;
}
}
...
...
@@ -36,7 +28,7 @@ export interface BulkListenerCallback {
export
interface
IEventEmitter
extends
IDisposable
{
addListener
(
eventType
:
string
,
listener
:
ListenerCallback
):
IDisposable
;
addOneTime
Disposable
Listener
(
eventType
:
string
,
listener
:
ListenerCallback
):
IDisposable
;
addOneTimeListener
(
eventType
:
string
,
listener
:
ListenerCallback
):
IDisposable
;
addBulkListener
(
listener
:
BulkListenerCallback
):
IDisposable
;
addEmitter
(
eventEmitter
:
IEventEmitter
):
IDisposable
;
}
...
...
@@ -60,7 +52,7 @@ export class EventEmitter implements IEventEmitter {
this
.
_deferredCnt
=
0
;
if
(
allowedEventTypes
)
{
this
.
_allowedEventTypes
=
{};
for
(
var
i
=
0
;
i
<
allowedEventTypes
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
allowedEventTypes
.
length
;
i
++
)
{
this
.
_allowedEventTypes
[
allowedEventTypes
[
i
]]
=
true
;
}
}
else
{
...
...
@@ -91,7 +83,7 @@ export class EventEmitter implements IEventEmitter {
this
.
_listeners
[
eventType
]
=
[
listener
];
}
var
bound
=
this
;
let
bound
=
this
;
return
{
dispose
:
()
=>
{
if
(
!
bound
)
{
...
...
@@ -108,7 +100,7 @@ export class EventEmitter implements IEventEmitter {
};
}
public
addOneTime
Disposable
Listener
(
eventType
:
string
,
listener
:
ListenerCallback
):
IDisposable
{
public
addOneTimeListener
(
eventType
:
string
,
listener
:
ListenerCallback
):
IDisposable
{
const
disposable
=
this
.
addListener
(
eventType
,
value
=>
{
disposable
.
dispose
();
listener
(
value
);
...
...
@@ -130,32 +122,29 @@ export class EventEmitter implements IEventEmitter {
public
addEmitter
(
eventEmitter
:
IEventEmitter
):
IDisposable
{
return
eventEmitter
.
addBulkListener
((
events
:
EmitterEvent
[]):
void
=>
{
var
newEvents
=
events
;
if
(
this
.
_deferredCnt
===
0
)
{
this
.
_emitEvents
(
<
EmitterEvent
[]
>
newE
vents
);
this
.
_emitEvents
(
e
vents
);
}
else
{
// Collect for later
this
.
_collectedEvents
.
push
.
apply
(
this
.
_collectedEvents
,
newE
vents
);
this
.
_collectedEvents
.
push
.
apply
(
this
.
_collectedEvents
,
e
vents
);
}
});
}
private
_removeListener
(
eventType
:
string
,
listener
:
ListenerCallback
):
void
{
if
(
this
.
_listeners
.
hasOwnProperty
(
eventType
))
{
var
listeners
=
this
.
_listeners
[
eventType
];
for
(
var
i
=
0
,
len
=
listeners
.
length
;
i
<
len
;
i
++
)
{
let
listeners
=
this
.
_listeners
[
eventType
];
for
(
let
i
=
0
,
len
=
listeners
.
length
;
i
<
len
;
i
++
)
{
if
(
listeners
[
i
]
===
listener
)
{
listeners
.
splice
(
i
,
1
);
break
;
}
}
}
}
private
_removeBulkListener
(
listener
:
BulkListenerCallback
):
void
{
for
(
var
i
=
0
,
len
=
this
.
_bulkListeners
.
length
;
i
<
len
;
i
++
)
{
for
(
let
i
=
0
,
len
=
this
.
_bulkListeners
.
length
;
i
<
len
;
i
++
)
{
if
(
this
.
_bulkListeners
[
i
]
===
listener
)
{
this
.
_bulkListeners
.
splice
(
i
,
1
);
break
;
...
...
@@ -165,16 +154,16 @@ export class EventEmitter implements IEventEmitter {
protected
_emitToSpecificTypeListeners
(
eventType
:
string
,
data
:
any
):
void
{
if
(
this
.
_listeners
.
hasOwnProperty
(
eventType
))
{
var
listeners
=
this
.
_listeners
[
eventType
].
slice
(
0
);
for
(
var
i
=
0
,
len
=
listeners
.
length
;
i
<
len
;
i
++
)
{
const
listeners
=
this
.
_listeners
[
eventType
].
slice
(
0
);
for
(
let
i
=
0
,
len
=
listeners
.
length
;
i
<
len
;
i
++
)
{
safeInvoke1Arg
(
listeners
[
i
],
data
);
}
}
}
protected
_emitToBulkListeners
(
events
:
EmitterEvent
[]):
void
{
var
bulkListeners
=
this
.
_bulkListeners
.
slice
(
0
);
for
(
var
i
=
0
,
len
=
bulkListeners
.
length
;
i
<
len
;
i
++
)
{
const
bulkListeners
=
this
.
_bulkListeners
.
slice
(
0
);
for
(
let
i
=
0
,
len
=
bulkListeners
.
length
;
i
<
len
;
i
++
)
{
safeInvoke1Arg
(
bulkListeners
[
i
],
events
);
}
}
...
...
@@ -183,10 +172,10 @@ export class EventEmitter implements IEventEmitter {
if
(
this
.
_bulkListeners
.
length
>
0
)
{
this
.
_emitToBulkListeners
(
events
);
}
for
(
var
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
var
e
=
events
[
i
];
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
const
e
=
events
[
i
];
this
.
_emitToSpecificTypeListeners
(
e
.
getType
(),
e
.
getData
()
);
this
.
_emitToSpecificTypeListeners
(
e
.
type
,
e
.
data
);
}
}
...
...
@@ -198,7 +187,7 @@ export class EventEmitter implements IEventEmitter {
if
(
!
this
.
_listeners
.
hasOwnProperty
(
eventType
)
&&
this
.
_bulkListeners
.
length
===
0
)
{
return
;
}
var
emitterEvent
=
new
EmitterEvent
(
eventType
,
data
);
const
emitterEvent
=
new
EmitterEvent
(
eventType
,
data
);
if
(
this
.
_deferredCnt
===
0
)
{
this
.
_emitEvents
([
emitterEvent
]);
...
...
@@ -231,13 +220,13 @@ export class EventEmitter implements IEventEmitter {
}
private
_emitCollected
():
void
{
if
(
this
.
_collectedEvents
.
length
===
0
)
{
return
;
}
// Flush collected events
var
events
=
this
.
_collectedEvents
;
const
events
=
this
.
_collectedEvents
;
this
.
_collectedEvents
=
[];
if
(
events
.
length
>
0
)
{
this
.
_emitEvents
(
events
);
}
this
.
_emitEvents
(
events
);
}
}
...
...
src/vs/base/parts/tree/browser/treeModel.ts
浏览文件 @
562f28f4
...
...
@@ -84,7 +84,7 @@ export class Lock {
var
unbindListener
:
IDisposable
;
return
new
WinJS
.
Promise
((
c
,
e
)
=>
{
unbindListener
=
lock
.
addOneTime
Disposable
Listener
(
'
unlock
'
,
()
=>
{
unbindListener
=
lock
.
addOneTimeListener
(
'
unlock
'
,
()
=>
{
return
this
.
run
(
item
,
fn
).
then
(
c
,
e
);
});
},
()
=>
{
unbindListener
.
dispose
();
});
...
...
src/vs/base/test/common/eventEmitter.test.ts
浏览文件 @
562f28f4
...
...
@@ -121,8 +121,8 @@ suite('EventEmitter', () => {
test
(
'
deferred emit maintains events order for bulk listeners
'
,
function
()
{
let
count
=
0
;
eventEmitter
.
addBulkListener
(
function
(
events
)
{
assert
.
equal
(
events
[
0
].
getType
()
,
'
eventType2
'
);
assert
.
equal
(
events
[
1
].
getType
()
,
'
eventType1
'
);
assert
.
equal
(
events
[
0
].
type
,
'
eventType2
'
);
assert
.
equal
(
events
[
1
].
type
,
'
eventType1
'
);
count
++
;
});
eventEmitter
.
deferredEmit
(
function
()
{
...
...
src/vs/editor/browser/widget/diffEditorWidget.ts
浏览文件 @
562f28f4
...
...
@@ -753,7 +753,7 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif
private
_recomputeIfNecessary
(
events
:
EmitterEvent
[]):
void
{
let
changed
=
false
;
for
(
let
i
=
0
;
!
changed
&&
i
<
events
.
length
;
i
++
)
{
let
type
=
events
[
i
].
getType
()
;
let
type
=
events
[
i
].
type
;
changed
=
changed
||
type
===
editorCommon
.
EventType
.
ModelRawContentChanged
;
}
if
(
changed
&&
this
.
_isVisible
)
{
...
...
@@ -768,8 +768,8 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif
private
_onOriginalEditorEvents
(
events
:
EmitterEvent
[]):
void
{
for
(
let
i
=
0
;
i
<
events
.
length
;
i
++
)
{
let
type
=
events
[
i
].
getType
()
;
let
data
=
events
[
i
].
getData
()
;
let
type
=
events
[
i
].
type
;
let
data
=
events
[
i
].
data
;
if
(
type
===
'
scroll
'
)
{
this
.
_onOriginalEditorScroll
(
data
);
...
...
@@ -783,8 +783,8 @@ export class DiffEditorWidget extends EventEmitter implements editorBrowser.IDif
private
_onModifiedEditorEvents
(
events
:
EmitterEvent
[]):
void
{
for
(
let
i
=
0
;
i
<
events
.
length
;
i
++
)
{
let
type
=
events
[
i
].
getType
()
;
let
data
=
events
[
i
].
getData
()
;
let
type
=
events
[
i
].
type
;
let
data
=
events
[
i
].
data
;
if
(
type
===
'
scroll
'
)
{
this
.
_onModifiedEditorScroll
(
data
);
...
...
src/vs/editor/common/commonCodeEditor.ts
浏览文件 @
562f28f4
...
...
@@ -768,8 +768,8 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom
this
.
listenersToRemove
.
push
(
this
.
model
.
addBulkListener
((
events
)
=>
{
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
let
eventType
=
events
[
i
].
getType
()
;
let
e
=
events
[
i
].
getData
()
;
let
eventType
=
events
[
i
].
type
;
let
e
=
events
[
i
].
data
;
switch
(
eventType
)
{
case
editorCommon
.
EventType
.
ModelDecorationsChanged
:
...
...
@@ -817,8 +817,8 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom
this
.
listenersToRemove
.
push
(
this
.
_getViewInternalEventBus
().
addBulkListener
((
events
)
=>
{
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
let
eventType
=
events
[
i
].
getType
()
;
let
e
=
events
[
i
].
getData
()
;
let
eventType
=
events
[
i
].
type
;
let
e
=
events
[
i
].
data
;
switch
(
eventType
)
{
case
editorCommon
.
EventType
.
ViewFocusGained
:
...
...
@@ -879,8 +879,8 @@ export abstract class CommonCodeEditor extends EventEmitter implements editorCom
this
.
listenersToRemove
.
push
(
this
.
cursor
.
addBulkListener
((
events
)
=>
{
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
let
eventType
=
events
[
i
].
getType
()
;
let
e
=
events
[
i
].
getData
()
;
let
eventType
=
events
[
i
].
type
;
let
e
=
events
[
i
].
data
;
switch
(
eventType
)
{
case
editorCommon
.
EventType
.
CursorPositionChanged
:
...
...
src/vs/editor/common/controller/cursor.ts
浏览文件 @
562f28f4
...
...
@@ -139,11 +139,11 @@ export class Cursor extends EventEmitter {
let
hadFlushEvent
=
false
;
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
const
event
=
events
[
i
];
const
eventType
=
event
.
getType
()
;
const
eventType
=
event
.
type
;
if
(
eventType
===
editorCommon
.
EventType
.
ModelRawContentChanged
)
{
hadContentChange
=
true
;
const
changeEvent
=
<
editorCommon
.
IModelRawContentChangedEvent
>
event
.
getData
()
;
const
changeEvent
=
<
editorCommon
.
IModelRawContentChangedEvent
>
event
.
data
;
if
(
changeEvent
.
changeType
===
editorCommon
.
EventType
.
ModelRawContentChangedFlush
)
{
hadFlushEvent
=
true
;
...
...
src/vs/editor/common/services/modelServiceImpl.ts
浏览文件 @
562f28f4
...
...
@@ -468,7 +468,7 @@ export class ModelServiceImpl implements IModelService {
// First look for dispose
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
let
e
=
events
[
i
];
if
(
e
.
getType
()
===
editorCommon
.
EventType
.
ModelDispose
)
{
if
(
e
.
type
===
editorCommon
.
EventType
.
ModelDispose
)
{
this
.
_onModelDisposing
(
modelData
.
model
);
// no more processing since model got disposed
return
;
...
...
@@ -478,9 +478,9 @@ export class ModelServiceImpl implements IModelService {
// Second, look for mode change
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
let
e
=
events
[
i
];
if
(
e
.
getType
()
===
editorCommon
.
EventType
.
ModelLanguageChanged
)
{
if
(
e
.
type
===
editorCommon
.
EventType
.
ModelLanguageChanged
)
{
const
model
=
modelData
.
model
;
const
oldModeId
=
(
<
editorCommon
.
IModelLanguageChangedEvent
>
e
.
getData
()
).
oldLanguage
;
const
oldModeId
=
(
<
editorCommon
.
IModelLanguageChangedEvent
>
e
.
data
).
oldLanguage
;
const
newModeId
=
model
.
getLanguageIdentifier
().
language
;
const
oldOptions
=
this
.
getCreationOptions
(
oldModeId
);
const
newOptions
=
this
.
getCreationOptions
(
newModeId
);
...
...
src/vs/editor/common/viewModel/viewModelImpl.ts
浏览文件 @
562f28f4
...
...
@@ -236,7 +236,7 @@ export class ViewModel implements IViewModel {
private
static
_containsModelContentChangeEvent
(
events
:
EmitterEvent
[]):
boolean
{
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
let
eventType
=
events
[
i
].
getType
()
;
let
eventType
=
events
[
i
].
type
;
if
(
eventType
===
editorCommon
.
EventType
.
ModelRawContentChanged
)
{
return
true
;
}
...
...
@@ -246,7 +246,7 @@ export class ViewModel implements IViewModel {
private
static
_containsWrappingRelatedEvents
(
events
:
EmitterEvent
[]):
boolean
{
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
let
eventType
=
events
[
i
].
getType
()
;
let
eventType
=
events
[
i
].
type
;
if
(
eventType
===
editorCommon
.
EventType
.
ModelOptionsChanged
)
{
return
true
;
}
...
...
@@ -295,9 +295,9 @@ export class ViewModel implements IViewModel {
for
(
let
i
=
0
,
len
=
events
.
length
;
i
<
len
;
i
++
)
{
let
e
=
events
[
i
];
let
data
=
e
.
getData
()
;
let
data
=
e
.
data
;
switch
(
e
.
getType
()
)
{
switch
(
e
.
type
)
{
case
editorCommon
.
EventType
.
ModelRawContentChanged
:
let
modelContentChangedEvent
=
<
editorCommon
.
IModelRawContentChangedEvent
>
data
;
...
...
src/vs/editor/contrib/codelens/browser/codelens.ts
浏览文件 @
562f28f4
...
...
@@ -448,7 +448,7 @@ export class CodeLensContribution implements editorCommon.IEditorContribution {
this
.
_localToDispose
.
push
(
model
.
addBulkListener
((
events
)
=>
{
let
hadChange
=
false
;
for
(
let
i
=
0
;
i
<
events
.
length
;
i
++
)
{
const
eventType
=
events
[
i
].
getType
()
;
const
eventType
=
events
[
i
].
type
;
if
(
eventType
===
editorCommon
.
EventType
.
ModelRawContentChanged
)
{
hadChange
=
true
;
break
;
...
...
src/vs/workbench/parts/debug/electron-browser/debugService.ts
浏览文件 @
562f28f4
...
...
@@ -845,7 +845,7 @@ export class DebugService implements debug.IDebugService {
});
if
(
filteredTasks
[
0
].
isBackground
)
{
return
new
TPromise
((
c
,
e
)
=>
this
.
taskService
.
addOneTime
Disposable
Listener
(
TaskServiceEvents
.
Inactive
,
()
=>
c
(
null
)));
return
new
TPromise
((
c
,
e
)
=>
this
.
taskService
.
addOneTimeListener
(
TaskServiceEvents
.
Inactive
,
()
=>
c
(
null
)));
}
return
taskPromise
;
...
...
src/vs/workbench/parts/debug/electron-browser/debugViews.ts
浏览文件 @
562f28f4
...
...
@@ -135,7 +135,7 @@ export class VariablesView extends CollapsibleViewletView {
this
.
tree
.
refresh
(
expression
,
false
).
then
(()
=>
{
this
.
tree
.
setHighlight
(
expression
);
this
.
tree
.
addOneTime
Disposable
Listener
(
EventType
.
HIGHLIGHT
,
(
e
:
IHighlightEvent
)
=>
{
this
.
tree
.
addOneTimeListener
(
EventType
.
HIGHLIGHT
,
(
e
:
IHighlightEvent
)
=>
{
if
(
!
e
.
highlight
)
{
this
.
debugService
.
getViewModel
().
setSelectedExpression
(
null
);
}
...
...
@@ -234,7 +234,7 @@ export class WatchExpressionsView extends CollapsibleViewletView {
this
.
tree
.
refresh
(
expression
,
false
).
then
(()
=>
{
this
.
tree
.
setHighlight
(
expression
);
this
.
tree
.
addOneTime
Disposable
Listener
(
EventType
.
HIGHLIGHT
,
(
e
:
IHighlightEvent
)
=>
{
this
.
tree
.
addOneTimeListener
(
EventType
.
HIGHLIGHT
,
(
e
:
IHighlightEvent
)
=>
{
if
(
!
e
.
highlight
)
{
this
.
debugService
.
getViewModel
().
setSelectedExpression
(
null
);
}
...
...
@@ -480,7 +480,7 @@ export class BreakpointsView extends AdaptiveCollapsibleViewletView {
this
.
tree
.
refresh
(
fbp
,
false
).
then
(()
=>
{
this
.
tree
.
setHighlight
(
fbp
);
this
.
tree
.
addOneTime
Disposable
Listener
(
EventType
.
HIGHLIGHT
,
(
e
:
IHighlightEvent
)
=>
{
this
.
tree
.
addOneTimeListener
(
EventType
.
HIGHLIGHT
,
(
e
:
IHighlightEvent
)
=>
{
if
(
!
e
.
highlight
)
{
this
.
debugService
.
getViewModel
().
setSelectedFunctionBreakpoint
(
null
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录