Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
4801e9a7
Commit
4801e9a7
authored
May 02, 2020
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused `scope-timeout` module
parent
47c8ea91
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
85 deletions
+0
-85
scope-timeout.js
src/sidebar/util/scope-timeout.js
+0
-32
scope-timeout-test.js
src/sidebar/util/test/scope-timeout-test.js
+0
-53
No files found.
src/sidebar/util/scope-timeout.js
deleted
100644 → 0
View file @
47c8ea91
/**
* Sets a timeout which is linked to the lifetime of an Angular scope.
*
* When the scope is destroyed, the timeout will be cleared if it has
* not already fired.
*
* The callback is not invoked within a $scope.$apply() context. It is up
* to the caller to do that if necessary.
*
* @param {Scope} $scope - An Angular scope
* @param {Function} fn - Callback to invoke with setTimeout
* @param {number} delay - Delay argument to pass to setTimeout
*/
export
default
function
scopeTimeout
(
$scope
,
fn
,
delay
,
setTimeoutFn
,
clearTimeoutFn
)
{
setTimeoutFn
=
setTimeoutFn
||
setTimeout
;
clearTimeoutFn
=
clearTimeoutFn
||
clearTimeout
;
let
removeDestroyHandler
;
const
id
=
setTimeoutFn
(
function
()
{
removeDestroyHandler
();
fn
();
},
delay
);
removeDestroyHandler
=
$scope
.
$on
(
'$destroy'
,
function
()
{
clearTimeoutFn
(
id
);
});
}
src/sidebar/util/test/scope-timeout-test.js
deleted
100644 → 0
View file @
47c8ea91
import
scopeTimeout
from
'../scope-timeout'
;
function
FakeScope
()
{
this
.
listeners
=
{};
this
.
$on
=
function
(
event
,
fn
)
{
this
.
listeners
[
event
]
=
this
.
listeners
[
event
]
||
[];
this
.
listeners
[
event
].
push
(
fn
);
return
function
()
{
this
.
listeners
[
event
]
=
this
.
listeners
[
event
].
filter
(
function
(
otherFn
)
{
return
otherFn
!==
fn
;
});
}.
bind
(
this
);
};
}
describe
(
'scope-timeout'
,
function
()
{
let
fakeSetTimeout
;
let
fakeClearTimeout
;
beforeEach
(
function
()
{
fakeSetTimeout
=
sinon
.
stub
().
returns
(
42
);
fakeClearTimeout
=
sinon
.
stub
();
});
it
(
'schedules a timeout'
,
function
()
{
const
$scope
=
new
FakeScope
();
const
callback
=
sinon
.
stub
();
scopeTimeout
(
$scope
,
callback
,
0
,
fakeSetTimeout
,
fakeClearTimeout
);
assert
.
calledOnce
(
fakeSetTimeout
);
const
timeoutFn
=
fakeSetTimeout
.
args
[
0
][
0
];
timeoutFn
();
assert
.
called
(
callback
);
});
it
(
'removes the scope listener when the timeout fires'
,
function
()
{
const
$scope
=
new
FakeScope
();
const
callback
=
sinon
.
stub
();
scopeTimeout
(
$scope
,
callback
,
0
,
fakeSetTimeout
,
fakeClearTimeout
);
assert
.
equal
(
$scope
.
listeners
.
$destroy
.
length
,
1
);
const
timeoutFn
=
fakeSetTimeout
.
args
[
0
][
0
];
timeoutFn
();
assert
.
equal
(
$scope
.
listeners
.
$destroy
.
length
,
0
);
});
it
(
'clears the timeout when the scope is destroyed'
,
function
()
{
const
$scope
=
new
FakeScope
();
const
callback
=
sinon
.
stub
();
scopeTimeout
(
$scope
,
callback
,
0
,
fakeSetTimeout
,
fakeClearTimeout
);
const
destroyFn
=
$scope
.
listeners
.
$destroy
[
0
];
destroyFn
();
assert
.
calledWith
(
fakeClearTimeout
,
42
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment