@microsoft/mgt-element
Advanced tools
Comparing version 2.2.0-preview.6e3772e to 2.2.0-preview.db82765
@@ -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,39 @@ * 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.state == ProviderState.SignedOut) { | ||
// Signed out, clear the component state | ||
this.clearState(); | ||
return Promise.resolve(); | ||
} | ||
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 +264,0 @@ } |
{ | ||
"name": "@microsoft/mgt-element", | ||
"version": "2.2.0-preview.6e3772e", | ||
"version": "2.2.0-preview.db82765", | ||
"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,41 @@ * 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.state == ProviderState.SignedOut) { | ||
// Signed out, clear the component state | ||
this.clearState(); | ||
return Promise.resolve(); | ||
} 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'); | ||
this.setLoadingState(false); | ||
this.fireCustomEvent('loadingCompleted'); | ||
resolve(); | ||
} catch (e) { | ||
this.setLoadingState(false); | ||
this.fireCustomEvent('loadingFailed'); | ||
reject(e); | ||
} | ||
}); | ||
await this.loadState(); | ||
// Return the load state promise. | ||
// If loading + forced, chain the promises. | ||
return (this._currentLoadStatePromise = | ||
this.isLoadingState && !!this._currentLoadStatePromise && force | ||
? this._currentLoadStatePromise.then(() => loadStatePromise) | ||
: loadStatePromise); | ||
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 +272,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
785449
6894