-
Notifications
You must be signed in to change notification settings - Fork 2
/
es6-plus.js
60 lines (55 loc) · 1.73 KB
/
es6-plus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Here is an example ES6+ implementation of the interface. If you
* have any questions about the code below, feel free to reach out.
* This implementation assumes an API-based workflow.
*/
class ES6PlusExample {
id = 2;
loginStrategy = 1;
isLoggedIn() {
return window.MyLoginSystem.isLoggedIn ? this._loginData : null;
}
requestLogin() {
window.MyLoginSystem.showLoginModal();
return window.MyLoginSystem.isLoginModalVisible;
}
addLoginHandler(fn) {
if (this._loginHandlers.includes(fn)) { return; }
this._loginHandlers.push(fn);
}
addLoginCanceledHandler(fn) {
if (this._loginCanceledHandlers.includes(fn)) { return; }
this._loginCanceledHandlers.push(fn);
}
addLogoutHandler(fn) {
if (this._logoutHandlers.includes(fn)) { return; }
this._logoutHandlers.push(fn);
}
constructor() {
const callLogoutHandlers = () =>
this._logoutHandlers.forEach(fn => fn(this._logoutData));
const callLoginHandlers = () =>
this._loginHandlers.forEach(fn => fn(this._loginData));
const callLoginCanceledHandlers = () =>
this._loginCanceledHandlers.forEach(fn => fn(this._logoutData));
window.MyLoginSystem.on('login', callLoginHandlers);
window.MyLoginSystem.on('logout', callLogoutHandlers);
window.MyLoginSystem.on('userSessionExpired', callLogoutHandlers);
window.MyLoginSystem.on('loginModalAborted', callLoginCanceledHandlers);
}
_loginHandlers = [];
_logoutHandlers = [];
_loginCanceledHandlers = [];
get _loginData() {
return {
thirdPartyId: this.id,
uuid: window.MyLoginSystem.currentUser.uuid
};
}
get _logoutData() {
return {
thirdPartyId: this.id
};
}
}
window.SecondStreetThirdPartyAuth = new ES6PlusExample();