-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Comments for methods, classes and interface. #254
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,31 +2,39 @@ import React, {Component} from 'react'; | |
|
||
import {SDK} from '@ringcentral/sdk'; | ||
|
||
// Utility function to get display name | ||
function getDisplayName(WrappedComponent) { | ||
return WrappedComponent.displayName || WrappedComponent.name || 'Component'; | ||
} | ||
|
||
// Utility function for delaying execution | ||
const delay = () => new Promise(res => setTimeout(res, 0)); | ||
|
||
// Interface for the state of AuthGate component | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need param description |
||
export interface AuthGateState { | ||
isAuthorized: boolean; | ||
authorizing: boolean; | ||
authError: null | Error; | ||
} | ||
|
||
// Interface for the render props provided by AuthGate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need param description |
||
export interface AuthGateRenderProps extends AuthGateState { | ||
loginUrl: (options: any) => string; | ||
parseRedirect: (search: string) => Promise<any>; | ||
logout: () => Promise<any>; | ||
} | ||
|
||
// Interface for the props of AuthGate component | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need param description |
||
export interface AuthGateProps { | ||
sdk: SDK; | ||
ensure?: boolean; | ||
children: (props: AuthGateRenderProps) => any; | ||
} | ||
|
||
// AuthGate component definition | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does AuthGate do in general? |
||
export class AuthGate extends Component<AuthGateProps, AuthGateState> { | ||
|
||
// Initial state | ||
public state = { | ||
isAuthorized: false, | ||
authorizing: true, | ||
|
@@ -51,6 +59,7 @@ export class AuthGate extends Component<AuthGateProps, AuthGateState> { | |
const {sdk, ensure} = this.props; | ||
const platform = sdk.platform(); | ||
|
||
// Event listeners for various platform events | ||
platform.on(platform.events.beforeRefresh, this.before); | ||
platform.on(platform.events.beforeLogin, this.before); | ||
platform.on(platform.events.refreshError, this.error); | ||
|
@@ -73,6 +82,7 @@ export class AuthGate extends Component<AuthGateProps, AuthGateState> { | |
this.mounted = false; | ||
const {sdk} = this.props; | ||
const platform = sdk.platform(); | ||
// Removing event listeners | ||
platform.removeListener(platform.events.beforeRefresh, this.before); | ||
platform.removeListener(platform.events.beforeLogin, this.before); | ||
platform.removeListener(platform.events.refreshError, this.error); | ||
|
@@ -82,19 +92,25 @@ export class AuthGate extends Component<AuthGateProps, AuthGateState> { | |
platform.removeListener(platform.events.refreshSuccess, this.success); | ||
} | ||
|
||
// Handler for before event | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do in the handler? |
||
public before = () => this.mounted && this.setState({authorizing: true}); | ||
|
||
// Handler for error event | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do in the handler? |
||
public error = async e => this.updateState(e); | ||
|
||
// Handler for success event | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do in the handler? |
||
public success = async () => this.updateState(null); | ||
|
||
// Method to get login URL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's in options? |
||
public loginUrl = options => this.props.sdk.platform().loginUrl(options); | ||
|
||
// Method to logout | ||
public logout = async () => { | ||
const platform = this.props.sdk.platform(); | ||
return platform.logout(); | ||
}; | ||
|
||
// Method to parse redirect | ||
public parseRedirect = async search => { | ||
try { | ||
const platform = this.props.sdk.platform(); | ||
|
@@ -107,6 +123,7 @@ export class AuthGate extends Component<AuthGateProps, AuthGateState> { | |
} | ||
}; | ||
|
||
// Method to update state | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need more description of this method. This looks a bit like an unauth, which is confusing. Why is authorizing set to false? |
||
public updateState = async (authError = null) => { | ||
await delay(); | ||
this.mounted && | ||
|
@@ -120,6 +137,7 @@ export class AuthGate extends Component<AuthGateProps, AuthGateState> { | |
}); | ||
}; | ||
|
||
// Render method | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not this one, but the one below if you expand the hidden code for Line 153 ~162. There's a clear comment saying TODO Definition there. That's a very clear sign that we want to add its definition there. |
||
public render() { | ||
const {sdk, ensure, children, ...props} = this.props; | ||
return children({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is a display name? Who's name? A user? A service? Or something else