Skip to content

Commit

Permalink
Fix onDestroy directive (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcere authored Nov 25, 2017
1 parent 281727d commit a807630
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
8 changes: 4 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ machine:

dependencies:
override:
- yarn install
- yarn install --no-progress
cache_directories:
- ~/.cache/yarn

Expand All @@ -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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"angular",
"angular-2",
"angular-4",
"angular-5",
"angular2",
"angular4",
"angular5",
Expand Down
11 changes: 11 additions & 0 deletions src/app/malihu-scrollbar/malihu-scrollbar.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <any>{ mCustomScrollbar: () => null };

spyOn(mockScrollableElement, 'mCustomScrollbar').and.throwError('error-x');

mScrollbarDirective.scrollableElement = mockScrollableElement;

expect(() => mScrollbarDirective.destroyScrollbar()).not.toThrow();
});
});
});
10 changes: 9 additions & 1 deletion src/app/malihu-scrollbar/malihu-scrollbar.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
}
}
5 changes: 4 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!doctype html>
<html lang="en">

<head>
<meta charset="utf-8">
<title>ngx-malihu-scrollbar</title>
Expand All @@ -8,7 +9,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>

<body>
<malihu-scrollbar-demo>Loading...</malihu-scrollbar-demo>
</body>
</html>

</html>

0 comments on commit a807630

Please sign in to comment.