Fix of TypeError: Cannot read property 'dynamicDataSourceManager' of undefined at anchorElRef when redirecting from the page with nav (#837)

This commit is contained in:
Alex Terentiev 2019-04-12 05:53:16 -07:00 committed by Vesa Juvonen
parent dcec947cd6
commit a0e9e0fdb6
2 changed files with 32 additions and 6 deletions

View File

@ -35,10 +35,11 @@ export default class PageSectionsNavigationWebPart extends BaseClientSideWebPart
const { customCssUrl } = this.properties;
this._onAnchorChanged = this._onAnchorChanged.bind(this);
this._availableSourcesChanged = this._availableSourcesChanged.bind(this);
// getting data sources that have already been added on the page
this._initDataSources();
// registering for changes in available datasources
this.context.dynamicDataProvider.registerAvailableSourcesChanged(this._initDataSources.bind(this, true));
this.context.dynamicDataProvider.registerAvailableSourcesChanged(this._availableSourcesChanged);
this._addCustomCss(customCssUrl);
@ -100,7 +101,15 @@ export default class PageSectionsNavigationWebPart extends BaseClientSideWebPart
}
protected onDispose(): void {
this.context.dynamicDataProvider.unregisterAvailableSourcesChanged(this._availableSourcesChanged);
if (this._dataSources) {
this._dataSources.forEach(ds => {
this.context.dynamicDataProvider.unregisterPropertyChanged(ds.id, 'anchor', this._onAnchorChanged);
});
delete this._dataSources;
}
ReactDom.unmountComponentAtNode(this.domElement);
super.onDispose();
}
protected get dataVersion(): Version {
@ -236,6 +245,10 @@ export default class PageSectionsNavigationWebPart extends BaseClientSideWebPart
};
}
private _availableSourcesChanged() {
this._initDataSources(true);
}
/**
* Initializes collection of "Anchor" data soures based on collection of existing page's data sources
* @param reRender specifies if the web part should be rerendered

View File

@ -43,10 +43,13 @@ export default class PageSectionsNavigationAnchorWebPart extends BaseClientSideW
uniqueId: uniqueId
};
this._initDataSource = this._initDataSource.bind(this);
this._onPageNavPositionChanged = this._onPageNavPositionChanged.bind(this);
// getting data sources that have already been added on the page
this._initDataSource();
// registering for changes in available datasources
this.context.dynamicDataProvider.registerAvailableSourcesChanged(this._initDataSource.bind(this));
this.context.dynamicDataProvider.registerAvailableSourcesChanged(this._initDataSource);
// registering current web part as a data source
this.context.dynamicDataSourceManager.initializeSource(this);
@ -69,9 +72,11 @@ export default class PageSectionsNavigationAnchorWebPart extends BaseClientSideW
showTitle: showTitle,
updateProperty: this._onTitleChanged.bind(this),
anchorElRef: (el => {
// notifying subscribers that the anchor component has been rendered
this._anchor.domElement = el;
this.context.dynamicDataSourceManager.notifyPropertyChanged('anchor');
if (!this.isDisposed) {
// notifying subscribers that the anchor component has been rendered
this._anchor.domElement = el;
this.context.dynamicDataSourceManager.notifyPropertyChanged('anchor');
}
}),
navPosition: position
}
@ -105,7 +110,15 @@ export default class PageSectionsNavigationAnchorWebPart extends BaseClientSideW
}
protected onDispose(): void {
this.context.dynamicDataProvider.unregisterAvailableSourcesChanged(this._initDataSource);
if (this._pageNavDataSource) {
this.context.dynamicDataProvider.unregisterPropertyChanged(this._pageNavDataSource.id, 'position', this._onPageNavPositionChanged);
delete this._pageNavDataSource;
}
ReactDom.unmountComponentAtNode(this.domElement);
delete this._anchor;
super.onDispose();
}
protected get dataVersion(): Version {
@ -155,7 +168,7 @@ export default class PageSectionsNavigationAnchorWebPart extends BaseClientSideW
let dataSource = availableDataSources[i];
if (dataSource.getPropertyDefinitions().filter(pd => pd.id === 'position').length) {
this._pageNavDataSource = dataSource;
this.context.dynamicDataProvider.registerPropertyChanged(dataSource.id, 'position', this._onPageNavPositionChanged.bind(this));
this.context.dynamicDataProvider.registerPropertyChanged(dataSource.id, 'position', this._onPageNavPositionChanged);
hasPageNavDataSource = true;
break;
}