@microsoft/sp-component-base 1.23.1 → 1.24.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/467dc675-7cc5-4709-8aac-78e3b71bd2f6.manifest.json +136 -141
- package/dist/{chunk.legacy-third-party-fabric-core-localfont_none_9e84ea19c68fdc8b9094.js → chunk.legacy-third-party-fabric-core-localfont_none_b7f7978a3e90166c361b.js} +1 -1
- package/dist/chunk.teams-apps-client_none_27d3c7c1d01080e4f131.js +2 -0
- package/dist/index-internal-beta.d.ts +30 -8
- package/dist/index-internal-public.d.ts +30 -8
- package/dist/index-internal.d.ts +30 -8
- package/dist/sp-component-base_default_8d535b51fa18aa47002b.js +22 -0
- package/dist/sp-component-base_en-us_8ce25dfb69a7786caece.js +22 -0
- package/dist/sp-component-base_qps-ploc_4fec831895d90df8aa7a.js +22 -0
- package/dist/sp-component-base_qps-ploca_b80610c8dff04dcec755.js +22 -0
- package/dist/tsdoc-metadata.json +1 -1
- package/lib-commonjs/BaseComponent.js +110 -145
- package/lib-commonjs/BaseComponentContext.js +126 -183
- package/lib-commonjs/DynamicDataProvider.js +251 -268
- package/lib-commonjs/DynamicDataSourceManager.js +218 -241
- package/lib-commonjs/DynamicProperty.js +232 -280
- package/lib-commonjs/EnsureIsolatedDomainUrl.js +14 -14
- package/lib-commonjs/IComponentPosition.js +8 -3
- package/lib-commonjs/IComponentPropertyMetadata.js +10 -3
- package/lib-commonjs/ISerializedServerProcessedData.js +24 -21
- package/lib-commonjs/LegacyThirdPartyFabricCoreLoader.js +53 -87
- package/lib-commonjs/PropertyMetadataProcessor.js +117 -150
- package/lib-commonjs/RenderableComponentContext.js +37 -0
- package/lib-commonjs/ShimmerFactory.js +66 -51
- package/lib-commonjs/chunks/legacy-third-party-fabric-core/FabricLocalFont.js +6 -4
- package/lib-commonjs/common/Flights.js +22 -10
- package/lib-commonjs/common/KillSwitches.js +13 -6
- package/lib-commonjs/dataCollector/IWebPartLoadData.js +35 -30
- package/lib-commonjs/dataCollector/WebPartLoadDataCollector.js +82 -91
- package/lib-commonjs/index.js +78 -38
- package/lib-commonjs/teams/DeferredTeamsAppsClient.js +30 -52
- package/lib-commonjs/teams/ITeamsAppCatalog.js +10 -3
- package/lib-commonjs/teams/TeamsAppsClient.js +189 -231
- package/lib-commonjs/test-api/MockComponent.js +38 -23
- package/lib-commonjs/test-api/MockComponentContext.js +21 -14
- package/lib-commonjs/test-api/index.js +21 -7
- package/lib-commonjs/themeProvider/ThemeProvider.js +68 -82
- package/lib-commonjs/themeProvider/themeInterfaces/IFontStyles.js +5 -2
- package/lib-commonjs/themeProvider/themeInterfaces/IPalette.js +10 -3
- package/lib-commonjs/themeProvider/themeInterfaces/ISemanticColors.js +59 -3
- package/lib-commonjs/themeProvider/themeInterfaces/ISemanticTextColors.js +10 -3
- package/lib-commonjs/themeProvider/themeInterfaces/ITheme.js +5 -2
- package/{lib → lib-dts}/BaseComponent.d.ts +8 -8
- package/{lib → lib-dts}/BaseComponentContext.d.ts +5 -5
- package/lib-dts/RenderableComponentContext.d.ts +35 -0
- package/{lib → lib-dts}/index.d.ts +1 -0
- package/lib-esm/BaseComponent.js +123 -0
- package/lib-esm/BaseComponentContext.js +157 -0
- package/lib-esm/DynamicDataProvider.js +401 -0
- package/lib-esm/DynamicDataSourceManager.js +358 -0
- package/lib-esm/DynamicProperty.js +344 -0
- package/{lib → lib-esm}/EnsureIsolatedDomainUrl.js +6 -6
- package/lib-esm/IComponentPosition.js +5 -0
- package/lib-esm/IComponentPropertyMetadata.js +7 -0
- package/lib-esm/ISerializedServerProcessedData.js +24 -0
- package/lib-esm/LegacyThirdPartyFabricCoreLoader.js +76 -0
- package/{lib → lib-esm}/PropertyMetadataProcessor.js +92 -127
- package/lib-esm/RenderableComponentContext.js +26 -0
- package/lib-esm/ShimmerFactory.js +74 -0
- package/{lib → lib-esm}/chunks/legacy-third-party-fabric-core/FabricLocalFont.js +3 -3
- package/{lib → lib-esm}/common/Flights.js +4 -3
- package/{lib → lib-esm}/common/KillSwitches.js +3 -2
- package/lib-esm/dataCollector/IWebPartLoadData.js +33 -0
- package/lib-esm/dataCollector/WebPartLoadDataCollector.js +125 -0
- package/{lib → lib-esm}/index.js +4 -3
- package/lib-esm/teams/DeferredTeamsAppsClient.js +32 -0
- package/lib-esm/teams/ITeamsAppCatalog.js +9 -0
- package/lib-esm/teams/TeamsAppsClient.js +395 -0
- package/lib-esm/test-api/MockComponent.js +38 -0
- package/{lib → lib-esm}/test-api/MockComponentContext.js +10 -11
- package/{lib → lib-esm}/test-api/index.js +2 -1
- package/lib-esm/themeProvider/ThemeProvider.js +79 -0
- package/lib-esm/themeProvider/themeInterfaces/IFontStyles.js +7 -0
- package/lib-esm/themeProvider/themeInterfaces/IPalette.js +7 -0
- package/lib-esm/themeProvider/themeInterfaces/ISemanticColors.js +56 -0
- package/lib-esm/themeProvider/themeInterfaces/ISemanticTextColors.js +7 -0
- package/lib-esm/themeProvider/themeInterfaces/ITheme.js +7 -0
- package/package.json +41 -14
- package/dist/chunk.teams-apps-client_none_f9872389cb6ea9ad28e2.js +0 -2
- package/dist/sp-component-base_default_5ba07be39b0dc8968f7b.js +0 -2
- package/dist/sp-component-base_en-us_eb9bebb3acce0ae83f1c.js +0 -2
- package/dist/sp-component-base_qps-ploc_45f37623d87c3d848f2a.js +0 -2
- package/dist/sp-component-base_qps-ploca_b3f3b7bf97c4185b0fd6.js +0 -2
- package/lib/BaseComponent.d.ts.map +0 -1
- package/lib/BaseComponent.js +0 -161
- package/lib/BaseComponentContext.d.ts.map +0 -1
- package/lib/BaseComponentContext.js +0 -222
- package/lib/DynamicDataProvider.d.ts.map +0 -1
- package/lib/DynamicDataProvider.js +0 -420
- package/lib/DynamicDataSourceManager.d.ts.map +0 -1
- package/lib/DynamicDataSourceManager.js +0 -382
- package/lib/DynamicProperty.d.ts.map +0 -1
- package/lib/DynamicProperty.js +0 -390
- package/lib/EnsureIsolatedDomainUrl.d.ts.map +0 -1
- package/lib/IComponentPosition.d.ts.map +0 -1
- package/lib/IComponentPosition.js +0 -2
- package/lib/IComponentPropertyMetadata.d.ts.map +0 -1
- package/lib/IComponentPropertyMetadata.js +0 -2
- package/lib/ISerializedServerProcessedData.d.ts.map +0 -1
- package/lib/ISerializedServerProcessedData.js +0 -28
- package/lib/LegacyThirdPartyFabricCoreLoader.d.ts.map +0 -1
- package/lib/LegacyThirdPartyFabricCoreLoader.js +0 -90
- package/lib/PropertyMetadataProcessor.d.ts.map +0 -1
- package/lib/ShimmerFactory.d.ts.map +0 -1
- package/lib/ShimmerFactory.js +0 -62
- package/lib/chunks/legacy-third-party-fabric-core/FabricLocalFont.d.ts.map +0 -1
- package/lib/common/Flights.d.ts.map +0 -1
- package/lib/common/KillSwitches.d.ts.map +0 -1
- package/lib/dataCollector/IWebPartLoadData.d.ts.map +0 -1
- package/lib/dataCollector/IWebPartLoadData.js +0 -40
- package/lib/dataCollector/WebPartLoadDataCollector.d.ts.map +0 -1
- package/lib/dataCollector/WebPartLoadDataCollector.js +0 -137
- package/lib/index.d.ts.map +0 -1
- package/lib/teams/DeferredTeamsAppsClient.d.ts.map +0 -1
- package/lib/teams/DeferredTeamsAppsClient.js +0 -39
- package/lib/teams/ITeamsAppCatalog.d.ts.map +0 -1
- package/lib/teams/ITeamsAppCatalog.js +0 -2
- package/lib/teams/TeamsAppsClient.d.ts.map +0 -1
- package/lib/teams/TeamsAppsClient.js +0 -440
- package/lib/test-api/MockComponent.d.ts.map +0 -1
- package/lib/test-api/MockComponent.js +0 -31
- package/lib/test-api/MockComponentContext.d.ts.map +0 -1
- package/lib/test-api/index.d.ts.map +0 -1
- package/lib/themeProvider/ThemeProvider.d.ts.map +0 -1
- package/lib/themeProvider/ThemeProvider.js +0 -99
- package/lib/themeProvider/themeInterfaces/IFontStyles.d.ts.map +0 -1
- package/lib/themeProvider/themeInterfaces/IFontStyles.js +0 -2
- package/lib/themeProvider/themeInterfaces/IPalette.d.ts.map +0 -1
- package/lib/themeProvider/themeInterfaces/IPalette.js +0 -2
- package/lib/themeProvider/themeInterfaces/ISemanticColors.d.ts.map +0 -1
- package/lib/themeProvider/themeInterfaces/ISemanticColors.js +0 -2
- package/lib/themeProvider/themeInterfaces/ISemanticTextColors.d.ts.map +0 -1
- package/lib/themeProvider/themeInterfaces/ISemanticTextColors.js +0 -2
- package/lib/themeProvider/themeInterfaces/ITheme.d.ts.map +0 -1
- package/lib/themeProvider/themeInterfaces/ITheme.js +0 -2
- /package/{lib → lib-dts}/DynamicDataProvider.d.ts +0 -0
- /package/{lib → lib-dts}/DynamicDataSourceManager.d.ts +0 -0
- /package/{lib → lib-dts}/DynamicProperty.d.ts +0 -0
- /package/{lib → lib-dts}/EnsureIsolatedDomainUrl.d.ts +0 -0
- /package/{lib → lib-dts}/IComponentPosition.d.ts +0 -0
- /package/{lib → lib-dts}/IComponentPropertyMetadata.d.ts +0 -0
- /package/{lib → lib-dts}/ISerializedServerProcessedData.d.ts +0 -0
- /package/{lib → lib-dts}/LegacyThirdPartyFabricCoreLoader.d.ts +0 -0
- /package/{lib → lib-dts}/PropertyMetadataProcessor.d.ts +0 -0
- /package/{lib → lib-dts}/ShimmerFactory.d.ts +0 -0
- /package/{lib → lib-dts}/chunks/legacy-third-party-fabric-core/FabricLocalFont.d.ts +0 -0
- /package/{lib → lib-dts}/common/Flights.d.ts +0 -0
- /package/{lib → lib-dts}/common/KillSwitches.d.ts +0 -0
- /package/{lib → lib-dts}/dataCollector/IWebPartLoadData.d.ts +0 -0
- /package/{lib → lib-dts}/dataCollector/WebPartLoadDataCollector.d.ts +0 -0
- /package/{lib → lib-dts}/loc/Strings.resx.d.ts +0 -0
- /package/{lib → lib-dts}/teams/DeferredTeamsAppsClient.d.ts +0 -0
- /package/{lib → lib-dts}/teams/ITeamsAppCatalog.d.ts +0 -0
- /package/{lib → lib-dts}/teams/TeamsAppsClient.d.ts +0 -0
- /package/{lib → lib-dts}/test-api/MockComponent.d.ts +0 -0
- /package/{lib → lib-dts}/test-api/MockComponentContext.d.ts +0 -0
- /package/{lib → lib-dts}/test-api/index.d.ts +0 -0
- /package/{lib → lib-dts}/themeProvider/ThemeProvider.d.ts +0 -0
- /package/{lib → lib-dts}/themeProvider/themeInterfaces/IFontStyles.d.ts +0 -0
- /package/{lib → lib-dts}/themeProvider/themeInterfaces/IPalette.d.ts +0 -0
- /package/{lib → lib-dts}/themeProvider/themeInterfaces/ISemanticColors.d.ts +0 -0
- /package/{lib → lib-dts}/themeProvider/themeInterfaces/ISemanticTextColors.d.ts +0 -0
- /package/{lib → lib-dts}/themeProvider/themeInterfaces/ITheme.d.ts +0 -0
- /package/{lib → lib-esm}/chunks/legacy-third-party-fabric-core/fabric-core-sass/Fabric.LocalFont.global.scss.css +0 -0
- /package/{lib → lib-esm}/chunks/legacy-third-party-fabric-core/fabric-core-sass/Fabric.LocalFontKillSwitchActivated.scss.css +0 -0
- /package/{lib → lib-esm}/chunks/legacy-third-party-fabric-core/fabric-core-shim.global.scss.css +0 -0
- /package/{lib → lib-esm}/chunks/legacy-third-party-fabric-core/fabric-core-shimKillSwitchActivated.scss.css +0 -0
- /package/{lib → lib-esm}/chunks/legacy-third-party-fabric-core/iconDefinitions.css +0 -0
- /package/{lib → lib-esm}/loc/Strings.resx.json +0 -0
- /package/{lib → lib-esm}/sp-component-base.manifest.json +0 -0
- /package/{lib → lib-esm}/styles/shimmer.module.scss.css +0 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { _ES5CompatibleClass } from '@microsoft/sp-core-library';
|
|
2
|
+
class BaseComponent {
|
|
3
|
+
/**
|
|
4
|
+
* Returns the dynamic data source id for the current instance of the component.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/ get _dynamicDataSourceId() {
|
|
8
|
+
return `${this.manifest.componentType}.${this.manifest.id}.${this.instanceId}`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Disposes the component.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Third-party code generally does not need to call this method; it's invoked
|
|
15
|
+
* automatically when the lifecycle ends for a web part or extension. To perform
|
|
16
|
+
* custom cleanup when your component is disposed, override the {@link BaseComponent.onDispose}
|
|
17
|
+
* method.
|
|
18
|
+
*/ dispose() {
|
|
19
|
+
if (!this._isDisposed) {
|
|
20
|
+
this.onDispose();
|
|
21
|
+
this.context.dispose();
|
|
22
|
+
delete this.context;
|
|
23
|
+
this._isDisposed = true;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns whether or not this component contains a dynamic data source.
|
|
28
|
+
* @internal
|
|
29
|
+
*/ get _containsDynamicDataSource() {
|
|
30
|
+
return this._isWebPartAndContainsDynamicDataSource;
|
|
31
|
+
}
|
|
32
|
+
set _containsDynamicDataSource(val) {
|
|
33
|
+
this._isWebPartAndContainsDynamicDataSource = this.manifest.componentType === 'WebPart' ? val : false;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns true if the component has been already disposed.
|
|
37
|
+
*/ get isDisposed() {
|
|
38
|
+
return this._isDisposed;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Provides access to the manifest for the client-side component.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* The manifest type is determined by the `TClientSideComponentManifest` generic parameter.
|
|
45
|
+
*/ get manifest() {
|
|
46
|
+
return this.context.manifest;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* This event method is called at the end of the component's lifecycle.
|
|
50
|
+
* It provides an opportunity to release any associated resources, cancel any
|
|
51
|
+
* outstanding requests, etc.
|
|
52
|
+
* @virtual
|
|
53
|
+
*/ onDispose() {
|
|
54
|
+
// (empty block)
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A unique identifier for the instance of the component.
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* A component implementation can be loaded multiple times on the page.
|
|
61
|
+
* For example, if the component is a charting web part, multiple instances of this web part
|
|
62
|
+
* could be added to the SharePoint canvas. The instanceId uniquely identifies each
|
|
63
|
+
* of these instances.
|
|
64
|
+
*/ get instanceId() {
|
|
65
|
+
return this.context.instanceId;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns the component identifier as defined in the component's associated manifest.
|
|
69
|
+
*
|
|
70
|
+
* @remarks
|
|
71
|
+
* Each client-side component has an associated manifest that is used by the sp-loader to load its scripts,
|
|
72
|
+
* and which may include additional metadata about the component. The manifest is uniquely identified using
|
|
73
|
+
* a text string containing a lower case GUID value.
|
|
74
|
+
*/ get componentId() {
|
|
75
|
+
return this.context.manifest.id;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @internal
|
|
79
|
+
*/ _initializeContext(context) {
|
|
80
|
+
this.context = context;
|
|
81
|
+
this.onProvideServices(context.serviceScope);
|
|
82
|
+
/*
|
|
83
|
+
* Calling finish on an already finished servicescope will throw.
|
|
84
|
+
* Hence, checking it before finishing the servicescope.
|
|
85
|
+
*
|
|
86
|
+
* In the case of ApplicationCustomizers, it's context is calling 'finish'
|
|
87
|
+
* on the service scope. Hence, it is required to have the below check.
|
|
88
|
+
*/ if (!context.serviceScope._isFinished) {
|
|
89
|
+
context.serviceScope.finish();
|
|
90
|
+
}
|
|
91
|
+
this.context._initializeDynamicData(this, context.serviceScope);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* This event method allows a component to add custom services to its
|
|
95
|
+
* {@link @microsoft/sp-core-library#ServiceScope}.
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* This event method is fired before {@link @microsoft/sp-core-library#ServiceScope | ServiceScope.finish()}
|
|
99
|
+
* is called, allowing the component to provide custom services.
|
|
100
|
+
*
|
|
101
|
+
* @virtual
|
|
102
|
+
*
|
|
103
|
+
* @alpha
|
|
104
|
+
*/ onProvideServices(serviceScope) {
|
|
105
|
+
// empty block
|
|
106
|
+
}
|
|
107
|
+
/** @internal */ constructor(){
|
|
108
|
+
/**
|
|
109
|
+
* Stores whether or not this component has a dynamic data source.
|
|
110
|
+
* @internal
|
|
111
|
+
*/ this._isWebPartAndContainsDynamicDataSource = false;
|
|
112
|
+
this._isDisposed = false;
|
|
113
|
+
// empty block
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* The base class for client-side components such as BaseClientSideWebPart or BaseExtension.
|
|
118
|
+
*
|
|
119
|
+
* @public
|
|
120
|
+
*/ export { BaseComponent as default };
|
|
121
|
+
_ES5CompatibleClass(BaseComponent);
|
|
122
|
+
|
|
123
|
+
//# sourceMappingURL=./BaseComponent.js.map
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Validate, _ClientManifestData, _ES5CompatibleClass } from '@microsoft/sp-core-library';
|
|
2
|
+
import { _LogSource, _logSourceServiceKey } from '@microsoft/sp-diagnostics';
|
|
3
|
+
import { PageContext } from '@microsoft/sp-page-context';
|
|
4
|
+
import { HttpClient, SPHttpClient, AadHttpClientFactory, AadTokenProviderFactory, MSGraphClientFactory } from '@microsoft/sp-http';
|
|
5
|
+
import DynamicDataProvider from './DynamicDataProvider';
|
|
6
|
+
import DynamicDataSourceManager from './DynamicDataSourceManager';
|
|
7
|
+
/**
|
|
8
|
+
* The base class for context objects for client-side components.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* A "context" object is a collection of well-known services and other
|
|
12
|
+
* objects that are likely to be needed by business logic that interacts with a
|
|
13
|
+
* associated component. Each component type has its own specialized subclass
|
|
14
|
+
* of BaseComponentContext, e.g. WebPartContext for web parts, ExtensionContext for
|
|
15
|
+
* client-side extensions, and so on.
|
|
16
|
+
*
|
|
17
|
+
* @privateRemarks
|
|
18
|
+
*
|
|
19
|
+
* NOTE: The context object is a convenience that avoids the overhead of
|
|
20
|
+
* properly factoring the dependencies for every class in a project.
|
|
21
|
+
* If lots of members are added to the context without discipline, it can
|
|
22
|
+
* easily devolve into a poor engineering practice (where "everything depends
|
|
23
|
+
* on everything else"). Think carefully before adding more objects to the context object.
|
|
24
|
+
* Is it really a core scenario? Is it unnecessarily coupling your package to another
|
|
25
|
+
* package? Is there a better place to put the object?
|
|
26
|
+
*
|
|
27
|
+
* Only add data properties or well-defined classes with ubiquitous applicability.
|
|
28
|
+
* Never add loose functions, callbacks, or settable properties to the context.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/ class BaseComponentContext {
|
|
32
|
+
/**
|
|
33
|
+
* Returns true if the context is disposed.
|
|
34
|
+
*/ get isDisposed() {
|
|
35
|
+
return this._isDisposed;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Disposes the base component context.
|
|
39
|
+
*/ dispose() {
|
|
40
|
+
if (!this._isDisposed) {
|
|
41
|
+
if (this._dynamicDataProvider) {
|
|
42
|
+
this._dynamicDataProvider.dispose();
|
|
43
|
+
}
|
|
44
|
+
if (this._dynamicDataSourceManager) {
|
|
45
|
+
this._dynamicDataSourceManager.dispose();
|
|
46
|
+
}
|
|
47
|
+
delete this._serviceScope;
|
|
48
|
+
delete this._pageContext;
|
|
49
|
+
delete this._dynamicDataProvider;
|
|
50
|
+
delete this._dynamicDataSourceManager;
|
|
51
|
+
this._isDisposed = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The associated {@link @microsoft/sp-core-library#ServiceScope} for this component.
|
|
56
|
+
* @remarks
|
|
57
|
+
* A child service scope is created for each client-side component.
|
|
58
|
+
*/ get serviceScope() {
|
|
59
|
+
return this._serviceScope;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* {@inheritDoc BaseComponent.instanceId}
|
|
63
|
+
*/ get instanceId() {
|
|
64
|
+
return this._instanceId;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The page context provides standard definitions for common SharePoint objects
|
|
68
|
+
* that need to be shared between the client-side application, web parts, and other
|
|
69
|
+
* components.
|
|
70
|
+
*/ get pageContext() {
|
|
71
|
+
return this._pageContext;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a Dynamic Data Provider for the component.
|
|
75
|
+
*
|
|
76
|
+
* @param component - Component tied to the Dynamic Data Provider
|
|
77
|
+
* @param serviceScope - ServiceScope to consume the Dynamic Data Manager from. Must be finished.
|
|
78
|
+
* @internal
|
|
79
|
+
*/ _initializeDynamicData(component, serviceScope) {
|
|
80
|
+
this._dynamicDataProvider._initialize(component, serviceScope);
|
|
81
|
+
this._dynamicDataSourceManager._initialize(component, serviceScope);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the Dynamic Data Provider associated with the component.
|
|
85
|
+
*/ get dynamicDataProvider() {
|
|
86
|
+
return this._dynamicDataProvider;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Returns the Dynamic Data Source Manager associated with the component.
|
|
90
|
+
*/ get dynamicDataSourceManager() {
|
|
91
|
+
return this._dynamicDataSourceManager;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The instance of AadHttpClientFactory created for this instance of component
|
|
95
|
+
*/ get aadHttpClientFactory() {
|
|
96
|
+
return this._aadClientFactory;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The instance of AadTokenProviderFactory created for this instance of component
|
|
100
|
+
*/ get aadTokenProviderFactory() {
|
|
101
|
+
return this._aadTokenFactory;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The instance of MSGraphClientFactory created for this instance of component
|
|
105
|
+
*/ get msGraphClientFactory() {
|
|
106
|
+
return this._msGraphClientFactory;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The instance of HttpClient created for this instance of component
|
|
110
|
+
*/ get httpClient() {
|
|
111
|
+
return this._httpClient;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The instance of SpHttpClient created for this instance of component
|
|
115
|
+
*/ get spHttpClient() {
|
|
116
|
+
return this._spHttpClient;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Returns true if the solution is being served from localhost
|
|
120
|
+
*/ get isServedFromLocalhost() {
|
|
121
|
+
return this._isServedFromLocalhost;
|
|
122
|
+
}
|
|
123
|
+
/** @internal */ constructor(parameters){
|
|
124
|
+
this._isDisposed = false;
|
|
125
|
+
this._isServedFromLocalhost = false;
|
|
126
|
+
Validate.isNotNullOrUndefined(parameters, 'parameters');
|
|
127
|
+
Validate.isNotNullOrUndefined(parameters.manifest, 'manifest');
|
|
128
|
+
this.manifest = parameters.manifest;
|
|
129
|
+
const { loaderConfig } = this.manifest;
|
|
130
|
+
if (loaderConfig && loaderConfig.internalModuleBaseUrls && loaderConfig.internalModuleBaseUrls.length) {
|
|
131
|
+
this._isServedFromLocalhost = /^http(s)?\:\/\/(localhost|127.0.0.1)/gim.test(loaderConfig.internalModuleBaseUrls[0]);
|
|
132
|
+
}
|
|
133
|
+
Validate.isNotNullOrUndefined(parameters.parentServiceScope, 'parentServiceScope');
|
|
134
|
+
this._serviceScope = parameters.parentServiceScope.startNewChild();
|
|
135
|
+
// TODO: VSO:507790 Reconcile this with ClientSideWebPartManager._createWebPartTag()
|
|
136
|
+
Validate.isNotNullOrUndefined(parameters.loggingTag, 'loggingTag');
|
|
137
|
+
this.serviceScope.provide(_logSourceServiceKey, _LogSource.create(parameters.loggingTag));
|
|
138
|
+
Validate.isNonemptyString(parameters.instanceId, 'instanceId');
|
|
139
|
+
this._instanceId = parameters.instanceId;
|
|
140
|
+
this._httpClient = this.serviceScope.createDefaultAndProvide(HttpClient.serviceKey);
|
|
141
|
+
this._spHttpClient = this.serviceScope.createDefaultAndProvide(SPHttpClient.serviceKey);
|
|
142
|
+
this._msGraphClientFactory = this.serviceScope.createDefaultAndProvide(MSGraphClientFactory.serviceKey);
|
|
143
|
+
this._aadClientFactory = this.serviceScope.createDefaultAndProvide(AadHttpClientFactory.serviceKey);
|
|
144
|
+
this._aadTokenFactory = this.serviceScope.createDefaultAndProvide(AadTokenProviderFactory.serviceKey);
|
|
145
|
+
this.serviceScope.provide(_ClientManifestData.serviceKey, new _ClientManifestData(this.serviceScope, this.manifest));
|
|
146
|
+
// Consume services
|
|
147
|
+
this.serviceScope.whenFinished(()=>{
|
|
148
|
+
this._pageContext = this.serviceScope.consume(PageContext.serviceKey);
|
|
149
|
+
});
|
|
150
|
+
this._dynamicDataProvider = new DynamicDataProvider();
|
|
151
|
+
this._dynamicDataSourceManager = new DynamicDataSourceManager();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
_ES5CompatibleClass(BaseComponentContext);
|
|
155
|
+
export default BaseComponentContext;
|
|
156
|
+
|
|
157
|
+
//# sourceMappingURL=./BaseComponentContext.js.map
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { Validate, Guid } from '@microsoft/sp-core-library';
|
|
2
|
+
import { _EngagementLogger, _LogEntry, _LogType } from '@microsoft/sp-diagnostics';
|
|
3
|
+
import { _DynamicDataUtilities } from '@microsoft/sp-dynamic-data';
|
|
4
|
+
import * as lodash from '@microsoft/sp-lodash-subset';
|
|
5
|
+
class DynamicDataProvider {
|
|
6
|
+
/**
|
|
7
|
+
* Initializes the Dynamic Data Provider for a specific component.
|
|
8
|
+
*
|
|
9
|
+
* @param component - Component that is going to use the Dynamic Data Provider.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/ _initialize(component, serviceScope) {
|
|
13
|
+
Validate.isNotNullOrUndefined(component, 'component');
|
|
14
|
+
Validate.isNotNullOrUndefined(serviceScope, 'serviceScope');
|
|
15
|
+
this._component = component;
|
|
16
|
+
// Initialize all the required datastructures
|
|
17
|
+
this._pendingRegistrations = new Map();
|
|
18
|
+
this._dynamicDataManager = serviceScope.consume(_DynamicDataUtilities.IDynamicDataManagerServiceKey);
|
|
19
|
+
this._isInitialized = true;
|
|
20
|
+
// Method bindings
|
|
21
|
+
this._onSourcesChanged = this._onSourcesChanged.bind(this);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Disposes the Dynamic Data Provider.
|
|
25
|
+
*/ dispose() {
|
|
26
|
+
if (!this._isDisposed) {
|
|
27
|
+
delete this._pendingRegistrations;
|
|
28
|
+
this._dynamicDataManager.sourcesChangedEvent.remove(this._component, this._onSourcesChanged);
|
|
29
|
+
delete this._dynamicDataManager;
|
|
30
|
+
delete this._component;
|
|
31
|
+
this._isInitialized = false;
|
|
32
|
+
this._isDisposed = true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns true if the Dynamic Data Provider is disposed.
|
|
37
|
+
*/ get isDisposed() {
|
|
38
|
+
return this._isDisposed;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns true if the Dynamic Data Provider is intialized.
|
|
42
|
+
* @internal
|
|
43
|
+
*/ get _isProviderInitialized() {
|
|
44
|
+
return this._isInitialized;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns the dynamic data source id for the current instance of the component.
|
|
48
|
+
* @internal
|
|
49
|
+
*/ get _dynamicDataSourceId() {
|
|
50
|
+
return this._component._dynamicDataSourceId;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Registers a callback for updates when a Dynamic Data source is changed.
|
|
54
|
+
* This happens when any property is updated within the source.
|
|
55
|
+
*
|
|
56
|
+
* @privateRemarks
|
|
57
|
+
* We register the source, only if the source is available else defer the registration
|
|
58
|
+
* to when the availableSources change.
|
|
59
|
+
*
|
|
60
|
+
* @param sourceId - Id of the Dynamic Data Source.
|
|
61
|
+
* @param callback - Function to execute when the source updates its data.
|
|
62
|
+
*/ registerSourceChanged(sourceId, callback) {
|
|
63
|
+
this._assertNotDisposed();
|
|
64
|
+
this._assertInitialized();
|
|
65
|
+
Validate.isNonemptyString(sourceId, 'sourceId');
|
|
66
|
+
Validate.isNotNullOrUndefined(callback, 'callback');
|
|
67
|
+
const availableSourceIds = this.getAvailableSources().map((source)=>source.id);
|
|
68
|
+
if (availableSourceIds.indexOf(sourceId) !== -1) {
|
|
69
|
+
// requested source is available
|
|
70
|
+
this._dynamicDataManager.registerSourceChanged(sourceId, this._component, callback);
|
|
71
|
+
this._logFeatureEntry('RegisterSourceChanged', {
|
|
72
|
+
sourceId: sourceId
|
|
73
|
+
});
|
|
74
|
+
} else {
|
|
75
|
+
// requested source is NOT available
|
|
76
|
+
this._addPendingRegistration({
|
|
77
|
+
id: sourceId,
|
|
78
|
+
callback: callback
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Unregisters a callback for updates when a Dynamic Data source is changed.
|
|
84
|
+
*
|
|
85
|
+
* @param sourceId - Id of the Dynamic Data Source.
|
|
86
|
+
* @param callback - Function to remove from the registration. Must be the same it was registered with.
|
|
87
|
+
*/ unregisterSourceChanged(sourceId, callback) {
|
|
88
|
+
this._assertNotDisposed();
|
|
89
|
+
this._assertInitialized();
|
|
90
|
+
Validate.isNonemptyString(sourceId, 'sourceId');
|
|
91
|
+
Validate.isNotNullOrUndefined(callback, 'callback');
|
|
92
|
+
const registration = {
|
|
93
|
+
id: sourceId,
|
|
94
|
+
callback: callback
|
|
95
|
+
};
|
|
96
|
+
if (!this._isRegistrationPending(registration)) {
|
|
97
|
+
// Source is already registered.
|
|
98
|
+
this._dynamicDataManager.unregisterSourceChanged(sourceId, this._component, callback);
|
|
99
|
+
this._logFeatureEntry('UnregisterSourceChanged', {
|
|
100
|
+
sourceId: sourceId
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
// Source is in pending state
|
|
104
|
+
this._removePendingRegistration(registration);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Registers a callback for updates when a property is changed in a Dynamic Data source.
|
|
109
|
+
*
|
|
110
|
+
* @privateRemarks
|
|
111
|
+
* We register the source, only if the source is available else defer the registration
|
|
112
|
+
* to when the availableSources change.
|
|
113
|
+
*
|
|
114
|
+
* @param sourceId - Id of the Dynamic Data Source.
|
|
115
|
+
* @param propertyId - Id of the property of the source.
|
|
116
|
+
* @param callback - Function to execute when the source updates its data.
|
|
117
|
+
*/ registerPropertyChanged(sourceId, propertyId, callback) {
|
|
118
|
+
this._assertNotDisposed();
|
|
119
|
+
this._assertInitialized();
|
|
120
|
+
Validate.isNonemptyString(sourceId, 'sourceId');
|
|
121
|
+
Validate.isNonemptyString(propertyId, 'propertyId');
|
|
122
|
+
Validate.isNotNullOrUndefined(callback, 'callback');
|
|
123
|
+
const availableSourceIds = this.getAvailableSources().map((source)=>source.id);
|
|
124
|
+
if (availableSourceIds.indexOf(sourceId) !== -1) {
|
|
125
|
+
// requested source is available
|
|
126
|
+
this._dynamicDataManager.registerPropertyChanged(sourceId, propertyId, this._component, callback);
|
|
127
|
+
this._logFeatureEntry('RegisterPropertyChanged', {
|
|
128
|
+
sourceId: sourceId,
|
|
129
|
+
propertyId: propertyId
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
// requested source is NOT available
|
|
133
|
+
this._addPendingRegistration({
|
|
134
|
+
id: sourceId,
|
|
135
|
+
propertyId: propertyId,
|
|
136
|
+
callback: callback
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Unregisters a callback for updates when a property is changed in a Dynamic Data source.
|
|
142
|
+
*
|
|
143
|
+
* @privateRemarks
|
|
144
|
+
* If the sourceId is present in _registeredSourcesForPropertyChanged then
|
|
145
|
+
* it removes from sourceID from the set _registeredSourcesForPropertyChanged and
|
|
146
|
+
* invokes unregisterPropertyChanged event on the DynamicDataManager
|
|
147
|
+
*
|
|
148
|
+
* else if the sourceId is present in _pendingSourcesForPropertyChanged then
|
|
149
|
+
* it just removes the sourceId from the set _pendingSourcesForPropertyChanged
|
|
150
|
+
*
|
|
151
|
+
* @param sourceId - Id of the Dynamic Data Source.
|
|
152
|
+
* @param propertyId - Id of the property of the source.
|
|
153
|
+
* @param callback - Function to remove from the registration. Must be the same it was registered with.
|
|
154
|
+
*/ unregisterPropertyChanged(sourceId, propertyId, callback) {
|
|
155
|
+
this._assertNotDisposed();
|
|
156
|
+
this._assertInitialized();
|
|
157
|
+
Validate.isNonemptyString(sourceId, 'sourceId');
|
|
158
|
+
Validate.isNonemptyString(propertyId, 'propertyId');
|
|
159
|
+
Validate.isNotNullOrUndefined(callback, 'callback');
|
|
160
|
+
const registration = {
|
|
161
|
+
id: sourceId,
|
|
162
|
+
callback: callback,
|
|
163
|
+
propertyId: propertyId
|
|
164
|
+
};
|
|
165
|
+
// registration is in pending state.
|
|
166
|
+
if (!this._isRegistrationPending(registration)) {
|
|
167
|
+
this._dynamicDataManager.unregisterPropertyChanged(sourceId, propertyId, this._component, callback);
|
|
168
|
+
this._logFeatureEntry('UnregisterPropertyChanged', {
|
|
169
|
+
sourceId: sourceId,
|
|
170
|
+
propertyId: propertyId
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
// Already registered.
|
|
174
|
+
this._removePendingRegistration(registration);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Registers a callback to an event that raises when the list of available Dynamic Data Sources is updated.
|
|
179
|
+
*
|
|
180
|
+
* @param callback - Function to execute when the sources are updated.
|
|
181
|
+
*/ registerAvailableSourcesChanged(callback) {
|
|
182
|
+
Validate.isNotNullOrUndefined(callback, 'callback');
|
|
183
|
+
this._assertNotDisposed();
|
|
184
|
+
this._assertInitialized();
|
|
185
|
+
this._dynamicDataManager.sourcesChangedEvent.add(this._component, callback);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Unregisters a callback to an event that raises when the list of available Dynamic Data Sources is updated.
|
|
189
|
+
*
|
|
190
|
+
* @privateRemarks
|
|
191
|
+
* This api is used by the consumer of the dynamic data.
|
|
192
|
+
*
|
|
193
|
+
* @param callback - Function to remove from the registration. Must be the same it was registered with.
|
|
194
|
+
*/ unregisterAvailableSourcesChanged(callback) {
|
|
195
|
+
Validate.isNotNullOrUndefined(callback, 'callback');
|
|
196
|
+
this._assertNotDisposed();
|
|
197
|
+
this._assertInitialized();
|
|
198
|
+
this._dynamicDataManager.sourcesChangedEvent.remove(this._component, callback);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Returns a list with all available Dynamic Data Sources.
|
|
202
|
+
*
|
|
203
|
+
* @returns Read-only array with all available sources.
|
|
204
|
+
*/ getAvailableSources() {
|
|
205
|
+
this._assertNotDisposed();
|
|
206
|
+
this._assertInitialized();
|
|
207
|
+
return this._dynamicDataManager.getSources();
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Returns a list of all the available Dynamic Data Sources which have same component id.
|
|
211
|
+
*
|
|
212
|
+
* @returns Read-only array of available sources with same component id.
|
|
213
|
+
* @alpha
|
|
214
|
+
*/ getAvailableSourcesByComponentId(componentId) {
|
|
215
|
+
this._assertNotDisposed();
|
|
216
|
+
this._assertInitialized();
|
|
217
|
+
const sources = [];
|
|
218
|
+
this._dynamicDataManager.getSources().forEach((source)=>{
|
|
219
|
+
if (componentId.equals(Guid.tryParse(source.metadata.componentId) || Guid.empty)) {
|
|
220
|
+
sources.push(source);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
return sources;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Returns a Dynamic Data Source, by its id.
|
|
227
|
+
* If the source is not present, it returns undefined.
|
|
228
|
+
*
|
|
229
|
+
* @param id - Id of the Dynamic Data Source.
|
|
230
|
+
*/ tryGetSource(id) {
|
|
231
|
+
this._assertNotDisposed();
|
|
232
|
+
this._assertInitialized();
|
|
233
|
+
Validate.isNotNullOrUndefined(id, 'id');
|
|
234
|
+
return this._dynamicDataManager.tryGetSource(id);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Returns specific data from a source based on a Dynamic Data reference.
|
|
238
|
+
*
|
|
239
|
+
* @param dataReference - Dynamic Data Reference.
|
|
240
|
+
* @internal
|
|
241
|
+
*/ _getData(dataReference) {
|
|
242
|
+
this._assertNotDisposed();
|
|
243
|
+
this._assertInitialized();
|
|
244
|
+
Validate.isNotNullOrUndefined(dataReference, 'dataReference');
|
|
245
|
+
const dataSource = this._dynamicDataManager.tryGetSource(dataReference.sourceId);
|
|
246
|
+
if (!dataSource) {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
let data = dataSource.getPropertyValue(dataReference.property);
|
|
250
|
+
if (data && dataReference.propertyPath) {
|
|
251
|
+
// multiple levels of sub-properties are separated by '.' in the property path.
|
|
252
|
+
const subpaths = dataReference.propertyPath.split('.');
|
|
253
|
+
subpaths.forEach((subpath)=>{
|
|
254
|
+
// If sub-property yields to an array value, then the path to the sub-property
|
|
255
|
+
// will have [*] appended after the name of the sub-property.
|
|
256
|
+
// Hence separating out to get the subPropertyName.
|
|
257
|
+
const subpathElements = subpath.split(DynamicDataProvider._jsonPathArrayRegex);
|
|
258
|
+
const subProperty = subpathElements[0];
|
|
259
|
+
// If the supplied reference has an array([*]) notation, then we extract the data
|
|
260
|
+
// accordingly. [*] means all the entries and if there is a number instead of the '*'
|
|
261
|
+
// then extract that specific entry.
|
|
262
|
+
if (data) {
|
|
263
|
+
if (Array.isArray(data)) {
|
|
264
|
+
let dataItems = [];
|
|
265
|
+
data.forEach((item)=>{
|
|
266
|
+
if (item.hasOwnProperty(subProperty)) {
|
|
267
|
+
dataItems.push(item[subProperty]);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
/*
|
|
271
|
+
* If a specific entry is asked, we return it else we return all the entries,
|
|
272
|
+
* essentially it is treated as [*].
|
|
273
|
+
*/ const index = subpathElements[1];
|
|
274
|
+
if (subpathElements.length > 1) {
|
|
275
|
+
/**
|
|
276
|
+
* This means that the current subpath element is an array type, an array inside an array.
|
|
277
|
+
* Since the subpath element is an array, we are normalizing the existing dataItems object
|
|
278
|
+
* i.e., dataItems will have an array of array objects.
|
|
279
|
+
*/ const tempDataItems = [];
|
|
280
|
+
dataItems.forEach((dataItem)=>{
|
|
281
|
+
dataItem.forEach((internalItem)=>tempDataItems.push(internalItem));
|
|
282
|
+
});
|
|
283
|
+
dataItems = tempDataItems;
|
|
284
|
+
}
|
|
285
|
+
if (!isNaN(parseInt(index, 10))) {
|
|
286
|
+
data = dataItems[index];
|
|
287
|
+
} else {
|
|
288
|
+
data = dataItems;
|
|
289
|
+
}
|
|
290
|
+
} else if (data.hasOwnProperty(subProperty)) {
|
|
291
|
+
// data is an object type
|
|
292
|
+
data = data[subProperty];
|
|
293
|
+
} else {
|
|
294
|
+
// If the control is here, it means that the subProperty was not found in data.
|
|
295
|
+
// Hence the next iteration would get data as undefined.
|
|
296
|
+
data = undefined;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
return data;
|
|
302
|
+
}
|
|
303
|
+
_onSourcesChanged() {
|
|
304
|
+
const availableSourceIds = this.getAvailableSources().map((source)=>source.id);
|
|
305
|
+
// Registering to sourceChanged event
|
|
306
|
+
this._pendingRegistrations.forEach((src)=>{
|
|
307
|
+
// register to sourceChanged event, if the source is available.
|
|
308
|
+
if (availableSourceIds.indexOf(src.id) !== -1) {
|
|
309
|
+
// Source is available
|
|
310
|
+
if (!src.propertyId) {
|
|
311
|
+
// No propertyId, means register to sourceChanged event.
|
|
312
|
+
this._dynamicDataManager.registerSourceChanged(src.id, this._component, src.callback);
|
|
313
|
+
this._logFeatureEntry('RegisterSourceChanged', {
|
|
314
|
+
sourceId: src.id
|
|
315
|
+
});
|
|
316
|
+
} else {
|
|
317
|
+
// With propertyId, means register to propertyChanged event.
|
|
318
|
+
this._dynamicDataManager.registerPropertyChanged(src.id, src.propertyId, this._component, src.callback);
|
|
319
|
+
this._logFeatureEntry('RegisterPropertyChanged', {
|
|
320
|
+
sourceId: src.id,
|
|
321
|
+
propertyId: src.propertyId
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
this._removePendingRegistration(src);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
_assertNotDisposed() {
|
|
329
|
+
if (this.isDisposed) {
|
|
330
|
+
throw new Error('Dynamic Data Provider has been disposed');
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
_assertInitialized() {
|
|
334
|
+
if (!this._isInitialized) {
|
|
335
|
+
throw new Error('Dynamic Data Provider has not been initialized.');
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Adds the registration to the pending registrations if not already added.
|
|
340
|
+
* Also adds a listener to the _DynamicDataManager's sourcesChangedEvent.
|
|
341
|
+
*/ _addPendingRegistration(registration) {
|
|
342
|
+
if (!this._isRegistrationPending(registration)) {
|
|
343
|
+
this._pendingRegistrations.set(registration.id + (registration.propertyId || ''), {
|
|
344
|
+
id: registration.id,
|
|
345
|
+
propertyId: registration.propertyId,
|
|
346
|
+
callback: registration.callback
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
if (!this._isSourcesChangedEventListenerAdded) {
|
|
350
|
+
this._dynamicDataManager.sourcesChangedEvent.add(this._component, this._onSourcesChanged);
|
|
351
|
+
this._isSourcesChangedEventListenerAdded = true;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Removes the pending registration and then, if there are no more pending registrations
|
|
356
|
+
* remove the 'sourcesChangedEvent' listener.
|
|
357
|
+
*/ _removePendingRegistration(registration) {
|
|
358
|
+
this._pendingRegistrations.delete(registration.id + (registration.propertyId || ''));
|
|
359
|
+
if (this._pendingRegistrations.size === 0) {
|
|
360
|
+
this._dynamicDataManager.sourcesChangedEvent.remove(this._component, this._onSourcesChanged);
|
|
361
|
+
this._isSourcesChangedEventListenerAdded = false;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Returns true if the incoming source is already added to the _pendingRegistrations Map.
|
|
366
|
+
*
|
|
367
|
+
* @param incomingRegistration - registration to be checked.
|
|
368
|
+
*/ _isRegistrationPending(incomingRegistration) {
|
|
369
|
+
return this._pendingRegistrations.has(incomingRegistration.id + (incomingRegistration.propertyId || ''));
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Logs a feature event with any extra data from the producer of the event.
|
|
373
|
+
* @param logFeature - Name of the feature to log.
|
|
374
|
+
* @param contextualProps - Contextual log properties of the feature event.
|
|
375
|
+
*/ _logFeatureEntry(logFeature, contextualProps) {
|
|
376
|
+
const isInternal = this._component.manifest.isInternal || false;
|
|
377
|
+
const logProperties = {
|
|
378
|
+
alias: this._component.manifest.alias,
|
|
379
|
+
isInternal: isInternal.toString()
|
|
380
|
+
};
|
|
381
|
+
const logEntry = new _LogEntry('DynamicDataProvider', logFeature, _LogType.Event, lodash.merge(logProperties, contextualProps));
|
|
382
|
+
_EngagementLogger.logEventWithLogEntry(logEntry);
|
|
383
|
+
}
|
|
384
|
+
constructor(){
|
|
385
|
+
this._isDisposed = false;
|
|
386
|
+
this._isInitialized = false;
|
|
387
|
+
this._isSourcesChangedEventListenerAdded = false;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Regular expression to evaluate arrays in a json path expression.
|
|
392
|
+
* @internal
|
|
393
|
+
*/ DynamicDataProvider._jsonPathArrayRegex = new RegExp(/\[|\]/);
|
|
394
|
+
/**
|
|
395
|
+
* The Dynamic Data Provider allows components to consume Dynamic Data.
|
|
396
|
+
* It allows components to request Dynamic Data sources and register/unregister to those.
|
|
397
|
+
*
|
|
398
|
+
* @public
|
|
399
|
+
*/ export { DynamicDataProvider as default };
|
|
400
|
+
|
|
401
|
+
//# sourceMappingURL=./DynamicDataProvider.js.map
|