From a8076301b72551b287d9c8180fe7314736a3310e Mon Sep 17 00:00:00 2001 From: Jean-Francois Cere Date: Sat, 25 Nov 2017 17:18:47 -0500 Subject: [PATCH] Fix onDestroy directive (#25) --- circle.yml | 8 ++++---- package.json | 1 + .../malihu-scrollbar.directive.spec.ts | 11 +++++++++++ .../malihu-scrollbar/malihu-scrollbar.directive.ts | 10 +++++++++- src/index.html | 5 ++++- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/circle.yml b/circle.yml index d0dbca2..d0757e7 100644 --- a/circle.yml +++ b/circle.yml @@ -11,7 +11,7 @@ machine: dependencies: override: - - yarn install + - yarn install --no-progress cache_directories: - ~/.cache/yarn @@ -20,9 +20,9 @@ test: - mkdir $CIRCLE_TEST_REPORTS/karma - mkdir $CIRCLE_TEST_REPORTS/lint override: - - yarn test -- --code-coverage --single-run - - yarn lint -- --formatters-dir ./tslint-formatters --format junit -o $CIRCLE_TEST_REPORTS/lint/tslint.xml - - yarn build -- --prod --aot + - yarn test --code-coverage --single-run --no-progress + - yarn lint --formatters-dir ./tslint-formatters --format junit -o $CIRCLE_TEST_REPORTS/lint/tslint.xml + - yarn build --prod --aot --no-progress post: - mv test-results.xml $CIRCLE_TEST_REPORTS/karma - yarn coveralls \ No newline at end of file diff --git a/package.json b/package.json index 1969be4..cc02e4c 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "angular", "angular-2", "angular-4", + "angular-5", "angular2", "angular4", "angular5", diff --git a/src/app/malihu-scrollbar/malihu-scrollbar.directive.spec.ts b/src/app/malihu-scrollbar/malihu-scrollbar.directive.spec.ts index f2b13ae..26f93fb 100644 --- a/src/app/malihu-scrollbar/malihu-scrollbar.directive.spec.ts +++ b/src/app/malihu-scrollbar/malihu-scrollbar.directive.spec.ts @@ -137,5 +137,16 @@ describe('MalihuScrollbarDirective:unit', () => { expect(zone.runOutsideAngular).toHaveBeenCalled(); expect(mockScrollableElement.mCustomScrollbar).toHaveBeenCalledWith('destroy'); }); + + it('should swallow error if malihu-custom-scrollbar-plugin throws', () => { + + const mockScrollableElement = { mCustomScrollbar: () => null }; + + spyOn(mockScrollableElement, 'mCustomScrollbar').and.throwError('error-x'); + + mScrollbarDirective.scrollableElement = mockScrollableElement; + + expect(() => mScrollbarDirective.destroyScrollbar()).not.toThrow(); + }); }); }); diff --git a/src/app/malihu-scrollbar/malihu-scrollbar.directive.ts b/src/app/malihu-scrollbar/malihu-scrollbar.directive.ts index 57d9cae..1bf5947 100644 --- a/src/app/malihu-scrollbar/malihu-scrollbar.directive.ts +++ b/src/app/malihu-scrollbar/malihu-scrollbar.directive.ts @@ -43,6 +43,14 @@ export class MalihuScrollbarDirective implements AfterViewInit, OnDestroy { } destroyScrollbar() { - this.zone.runOutsideAngular(() => this.scrollableElement.mCustomScrollbar('destroy')); + this.zone.runOutsideAngular(() => { + try { + this.scrollableElement.mCustomScrollbar('destroy'); + } catch (error) { + // workaround for malihu-custom-scrollbar-plugin issue: + // Cannot read property 'autoUpdate' of undefined + // https://github.com/malihu/malihu-custom-scrollbar-plugin/issues/392 + } + }); } } diff --git a/src/index.html b/src/index.html index 636cee7..93caca5 100644 --- a/src/index.html +++ b/src/index.html @@ -1,5 +1,6 @@ + ngx-malihu-scrollbar @@ -8,7 +9,9 @@ + Loading... - + + \ No newline at end of file