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
cc081d11
Unverified
Commit
cc081d11
authored
May 26, 2020
by
Robert Knight
Committed by
GitHub
May 26, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2185 from hypothesis/remove-oauth-tokens-changed-event
Remove `OAUTH_TOKENS_CHANGED` event
parents
db3f3f17
5b140712
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
18 additions
and
52 deletions
+18
-52
events.js
src/sidebar/events.js
+0
-13
index.js
src/sidebar/index.js
+0
-10
oauth-auth.js
src/sidebar/services/oauth-auth.js
+9
-6
session.js
src/sidebar/services/session.js
+1
-3
oauth-auth-test.js
src/sidebar/services/test/oauth-auth-test.js
+5
-7
session-test.js
src/sidebar/services/test/session-test.js
+3
-13
No files found.
src/sidebar/events.js
deleted
100644 → 0
View file @
db3f3f17
/**
* This module defines the set of global events that are dispatched
* on $rootScope
*/
export
default
{
// Session state changes
/**
* API tokens were fetched and saved to local storage by another client
* instance.
*/
OAUTH_TOKENS_CHANGED
:
'oauthTokensChanged'
,
};
src/sidebar/index.js
View file @
cc081d11
...
...
@@ -138,7 +138,6 @@ import store from './store';
// Utilities.
import
{
Injector
}
from
'../shared/injector'
;
import
EventEmitter
from
'tiny-emitter'
;
function
startApp
(
config
)
{
const
container
=
new
Injector
();
...
...
@@ -172,15 +171,6 @@ function startApp(config) {
.
register
(
'viewFilter'
,
viewFilterService
)
.
register
(
'store'
,
store
);
// Register a dummy `$rootScope` pub-sub service for services that still
// use it.
const
emitter
=
new
EventEmitter
();
const
dummyRootScope
=
{
$on
:
(
event
,
callback
)
=>
emitter
.
on
(
event
,
data
=>
callback
({},
data
)),
$broadcast
:
(
event
,
data
)
=>
emitter
.
emit
(
event
,
data
),
};
container
.
register
(
'$rootScope'
,
{
value
:
dummyRootScope
});
// Register utility values/classes.
//
// nb. In many cases these can be replaced by direct imports in the services
...
...
src/sidebar/services/oauth-auth.js
View file @
cc081d11
import
events
from
'../events'
;
import
EventEmitter
from
'tiny-emitter'
;
import
serviceConfig
from
'../service-config'
;
import
OAuthClient
from
'../util/oauth-client'
;
import
{
resolve
}
from
'../util/url'
;
...
...
@@ -23,7 +24,6 @@ import { resolve } from '../util/url';
* the `OAuthClient` class.
*/
export
default
function
auth
(
$rootScope
,
$window
,
apiRoutes
,
localStorage
,
...
...
@@ -127,6 +127,8 @@ export default function auth(
});
}
const
emitter
=
new
EventEmitter
();
/**
* Listen for updated access & refresh tokens saved by other instances of the
* client.
...
...
@@ -137,7 +139,7 @@ export default function auth(
// Reset cached token information. Tokens will be reloaded from storage
// on the next call to `tokenGetter()`.
tokenInfoPromise
=
null
;
$rootScope
.
$broadcast
(
events
.
OAUTH_TOKENS_CHANGED
);
emitter
.
emit
(
'oauthTokensChanged'
);
}
});
}
...
...
@@ -290,18 +292,19 @@ export default function auth(
listenForTokenStorageEvents
();
return
{
// The returned object `extends` the EventEmitter. We could rework this
// service to be a class in future to do this more explicitly.
return
Object
.
assign
(
emitter
,
{
login
,
logout
,
tokenGetter
,
};
}
)
;
}
// `$inject` is added manually rather than using `@ngInject` to work around
// a conflict between the transform-async-to-promises and angularjs-annotate
// Babel plugins.
auth
.
$inject
=
[
'$rootScope'
,
'$window'
,
'apiRoutes'
,
'localStorage'
,
...
...
src/sidebar/services/session.js
View file @
cc081d11
import
events
from
'../events'
;
import
serviceConfig
from
'../service-config'
;
import
*
as
retryUtil
from
'../util/retry'
;
import
*
as
sentry
from
'../util/sentry'
;
...
...
@@ -21,7 +20,6 @@ const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
* @ngInject
*/
export
default
function
session
(
$rootScope
,
analytics
,
store
,
api
,
...
...
@@ -160,7 +158,7 @@ export default function session(
return
load
();
}
$rootScope
.
$on
(
events
.
OAUTH_TOKENS_CHANGED
,
()
=>
{
auth
.
on
(
'oauthTokensChanged'
,
()
=>
{
reload
();
});
...
...
src/sidebar/services/test/oauth-auth-test.js
View file @
cc081d11
import
events
from
'../../events'
;
import
{
Injector
}
from
'../../../shared/injector'
;
import
FakeWindow
from
'../../util/test/fake-window'
;
import
authFactory
,
{
$imports
}
from
'../oauth-auth'
;
...
...
@@ -6,8 +5,7 @@ import authFactory, { $imports } from '../oauth-auth';
const
DEFAULT_TOKEN_EXPIRES_IN_SECS
=
1000
;
const
TOKEN_KEY
=
'hypothesis.oauth.hypothes%2Eis.token'
;
describe
(
'sidebar.oauth-auth'
,
function
()
{
let
$rootScope
;
describe
(
'sidebar/services/oauth-auth'
,
function
()
{
let
FakeOAuthClient
;
let
auth
;
let
nowStub
;
...
...
@@ -92,10 +90,7 @@ describe('sidebar.oauth-auth', function () {
'../util/oauth-client'
:
FakeOAuthClient
,
});
$rootScope
=
{
$broadcast
:
sinon
.
stub
()
};
auth
=
new
Injector
()
.
register
(
'$rootScope'
,
{
value
:
$rootScope
})
.
register
(
'$window'
,
{
value
:
fakeWindow
})
.
register
(
'apiRoutes'
,
{
value
:
fakeApiRoutes
})
.
register
(
'localStorage'
,
{
value
:
fakeLocalStorage
})
...
...
@@ -516,9 +511,12 @@ describe('sidebar.oauth-auth', function () {
});
it
(
'notifies other services about the change'
,
()
=>
{
const
tokenChanged
=
sinon
.
stub
();
auth
.
on
(
'oauthTokensChanged'
,
tokenChanged
);
notifyStoredTokenChange
();
assert
.
called
With
(
$rootScope
.
$broadcast
,
events
.
OAUTH_TOKENS_CHANGED
);
assert
.
called
(
tokenChanged
);
});
});
...
...
src/sidebar/services/test/session-test.js
View file @
cc081d11
import
EventEmitter
from
'tiny-emitter'
;
import
events
from
'../../events'
;
import
{
events
as
analyticsEvents
}
from
'../analytics'
;
import
sessionFactory
from
'../session'
;
import
{
$imports
}
from
'../session'
;
import
{
Injector
}
from
'../../../shared/injector'
;
describe
(
'sidebar/services/session'
,
function
()
{
let
$rootScope
;
let
fakeAnalytics
;
let
fakeAuth
;
let
fakeSentry
;
...
...
@@ -39,10 +36,10 @@ describe('sidebar/services/session', function () {
currentProfile
=
newProfile
;
}),
};
fakeAuth
=
{
fakeAuth
=
Object
.
assign
(
new
EventEmitter
(),
{
login
:
sandbox
.
stub
().
returns
(
Promise
.
resolve
()),
logout
:
sinon
.
stub
().
resolves
(),
};
}
)
;
fakeSentry
=
{
setUserInfo
:
sandbox
.
spy
(),
};
...
...
@@ -63,14 +60,7 @@ describe('sidebar/services/session', function () {
'../util/sentry'
:
fakeSentry
,
});
const
emitter
=
new
EventEmitter
();
$rootScope
=
{
$on
:
(
event
,
cb
)
=>
emitter
.
on
(
event
,
data
=>
cb
(
null
,
data
)),
$broadcast
:
(
event
,
data
)
=>
emitter
.
emit
(
event
,
data
),
};
session
=
new
Injector
()
.
register
(
'$rootScope'
,
{
value
:
$rootScope
})
.
register
(
'analytics'
,
{
value
:
fakeAnalytics
})
.
register
(
'store'
,
{
value
:
fakeStore
})
.
register
(
'api'
,
{
value
:
fakeApi
})
...
...
@@ -328,7 +318,7 @@ describe('sidebar/services/session', function () {
userid
:
'acct:different_user@hypothes.is'
,
})
);
$rootScope
.
$broadcast
(
events
.
OAUTH_TOKENS_CHANGED
);
fakeAuth
.
emit
(
'oauthTokensChanged'
);
fakeStore
.
updateProfile
.
resetHistory
();
return
session
.
load
();
...
...
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