@microsoft/mgt-element
Advanced tools
Comparing version 2.2.0-preview.6e3772e to 2.2.0-preview.9dd9cdf
@@ -113,2 +113,3 @@ /** | ||
protected loadState(): Promise<void>; | ||
protected clearState(): void; | ||
/** | ||
@@ -115,0 +116,0 @@ * helps facilitate creation of events across components |
@@ -26,2 +26,3 @@ /** | ||
import { internalProperty, LitElement } from 'lit-element'; | ||
import { ProviderState } from '../providers/IProvider'; | ||
import { Providers } from '../providers/Providers'; | ||
@@ -169,2 +170,3 @@ import { LocalizationHelper } from '../utils/LocalizationHelper'; | ||
} | ||
clearState() { } | ||
/** | ||
@@ -223,23 +225,42 @@ * helps facilitate creation of events across components | ||
} | ||
const loadStatePromise = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
this.setLoadingState(true); | ||
this.fireCustomEvent('loadingInitiated'); | ||
yield this.loadState(); | ||
this.setLoadingState(false); | ||
this.fireCustomEvent('loadingCompleted'); | ||
resolve(); | ||
} | ||
catch (e) { | ||
this.setLoadingState(false); | ||
this.fireCustomEvent('loadingFailed'); | ||
reject(e); | ||
} | ||
})); | ||
// Return the load state promise. | ||
// If loading + forced, chain the promises. | ||
return (this._currentLoadStatePromise = | ||
this.isLoadingState && !!this._currentLoadStatePromise && force | ||
? this._currentLoadStatePromise.then(() => loadStatePromise) | ||
: loadStatePromise); | ||
const provider = Providers.globalProvider; | ||
if (!provider) { | ||
return Promise.resolve(); | ||
} | ||
if (provider.state === ProviderState.SignedOut) { | ||
// Signed out, clear the component state | ||
this.clearState(); | ||
return; | ||
} | ||
else if (provider.state === ProviderState.Loading) { | ||
// The provider state is indeterminate. Do nothing. | ||
return Promise.resolve(); | ||
} | ||
else { | ||
// Signed in, load the internal component state | ||
const loadStatePromise = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
this.setLoadingState(true); | ||
this.fireCustomEvent('loadingInitiated'); | ||
yield this.loadState(); | ||
this.setLoadingState(false); | ||
this.fireCustomEvent('loadingCompleted'); | ||
resolve(); | ||
} | ||
catch (e) { | ||
// Loading failed. Clear any partially set data. | ||
this.clearState(); | ||
this.setLoadingState(false); | ||
this.fireCustomEvent('loadingFailed'); | ||
reject(e); | ||
} | ||
// Return the load state promise. | ||
// If loading + forced, chain the promises. | ||
// This is to account for the lack of a cancellation token concept. | ||
return (this._currentLoadStatePromise = | ||
this.isLoadingState && !!this._currentLoadStatePromise && force | ||
? this._currentLoadStatePromise.then(() => loadStatePromise) | ||
: loadStatePromise); | ||
})); | ||
} | ||
}); | ||
@@ -246,0 +267,0 @@ } |
{ | ||
"name": "@microsoft/mgt-element", | ||
"version": "2.2.0-preview.6e3772e", | ||
"version": "2.2.0-preview.9dd9cdf", | ||
"description": "Microsoft Graph Toolkit base classes", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/microsoftgraph/microsoft-graph-toolkit", |
@@ -9,2 +9,3 @@ /** | ||
import { internalProperty, LitElement, PropertyValues } from 'lit-element'; | ||
import { ProviderState } from '../providers/IProvider'; | ||
import { Providers } from '../providers/Providers'; | ||
@@ -166,2 +167,4 @@ import { LocalizationHelper } from '../utils/LocalizationHelper'; | ||
protected clearState(): void {} | ||
/** | ||
@@ -228,25 +231,45 @@ * helps facilitate creation of events across components | ||
const loadStatePromise = new Promise(async (resolve, reject) => { | ||
try { | ||
this.setLoadingState(true); | ||
this.fireCustomEvent('loadingInitiated'); | ||
const provider = Providers.globalProvider; | ||
await this.loadState(); | ||
if (!provider) { | ||
return Promise.resolve(); | ||
} | ||
this.setLoadingState(false); | ||
this.fireCustomEvent('loadingCompleted'); | ||
resolve(); | ||
} catch (e) { | ||
this.setLoadingState(false); | ||
this.fireCustomEvent('loadingFailed'); | ||
reject(e); | ||
} | ||
}); | ||
if (provider.state === ProviderState.SignedOut) { | ||
// Signed out, clear the component state | ||
this.clearState(); | ||
return; | ||
} else if (provider.state === ProviderState.Loading) { | ||
// The provider state is indeterminate. Do nothing. | ||
return Promise.resolve(); | ||
} else { | ||
// Signed in, load the internal component state | ||
const loadStatePromise = new Promise(async (resolve, reject) => { | ||
try { | ||
this.setLoadingState(true); | ||
this.fireCustomEvent('loadingInitiated'); | ||
// Return the load state promise. | ||
// If loading + forced, chain the promises. | ||
return (this._currentLoadStatePromise = | ||
this.isLoadingState && !!this._currentLoadStatePromise && force | ||
? this._currentLoadStatePromise.then(() => loadStatePromise) | ||
: loadStatePromise); | ||
await this.loadState(); | ||
this.setLoadingState(false); | ||
this.fireCustomEvent('loadingCompleted'); | ||
resolve(); | ||
} catch (e) { | ||
// Loading failed. Clear any partially set data. | ||
this.clearState(); | ||
this.setLoadingState(false); | ||
this.fireCustomEvent('loadingFailed'); | ||
reject(e); | ||
} | ||
// Return the load state promise. | ||
// If loading + forced, chain the promises. | ||
// This is to account for the lack of a cancellation token concept. | ||
return (this._currentLoadStatePromise = | ||
this.isLoadingState && !!this._currentLoadStatePromise && force | ||
? this._currentLoadStatePromise.then(() => loadStatePromise) | ||
: loadStatePromise); | ||
}); | ||
} | ||
} | ||
@@ -253,0 +276,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
785651
6900