Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

Commit

Permalink
fixdirective): fix box factory to IVY support
Browse files Browse the repository at this point in the history
* chore(directive): extract option from nativeElement

* chore(all): fix comments
  • Loading branch information
vladimirpotekhin committed May 16, 2020
1 parent 2679dbe commit b956f4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import {Attribute, Directive, Inject, Output} from '@angular/core';
import {Attribute, Directive, ElementRef, Inject, Output} from '@angular/core';
import {Observable} from 'rxjs';
import {ResizeObserverService} from '../services/resize-observer.service';
import {RESIZE_OPTION_BOX, RESIZE_OPTION_BOX_DEFAULT} from '../tokens/resize-option-box';

// TODO switch to Attribute once https://github.com/angular/angular/issues/36479 is fixed
export function boxExtractor({
nativeElement,
}: ElementRef<Element>): ResizeObserverOptions['box'] {
const attribute = nativeElement.getAttribute(
'waResizeBox',
) as ResizeObserverOptions['box'];

return boxFactory(attribute);
}

export function boxFactory(
box: ResizeObserverOptions['box'] | null,
): ResizeObserverOptions['box'] {
Expand All @@ -16,8 +27,8 @@ export function boxFactory(
ResizeObserverService,
{
provide: RESIZE_OPTION_BOX,
deps: [[new Attribute('waResizeBox')]],
useFactory: boxFactory,
deps: [ElementRef],
useFactory: boxExtractor,
},
],
})
Expand Down
11 changes: 6 additions & 5 deletions projects/resize-observer/src/services/resize-observer.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ElementRef, Inject, Injectable, NgZone} from '@angular/core';
import {Observable} from 'rxjs';
import {finalize, share} from 'rxjs/operators';
import {share} from 'rxjs/operators';
import {RESIZE_OPTION_BOX} from '../tokens/resize-option-box';
import {RESIZE_OBSERVER_SUPPORT} from '../tokens/support';

Expand Down Expand Up @@ -28,11 +28,12 @@ export class ResizeObserverService extends Observable<
});
});
observer.observe(nativeElement, {box});

return () => {
observer.disconnect();
};
});

return this.pipe(
finalize(() => observer.disconnect()),
share(),
);
return this.pipe(share());
}
}

0 comments on commit b956f4e

Please sign in to comment.