@vime/angular
Version:
Angular bindings for the Vime media player.
52 lines • 6.66 kB
JavaScript
import { __awaiter } from "tslib";
import { findPlayer, usePlayerContext, createDispatcher, } from '@vime/core';
import { Injectable } from '@angular/core';
export class VimeComponent {
constructor(playerProps) {
this.playerProps = playerProps;
this.playerDispatch = () => { };
this.unbindPlayerContext = () => { };
this.playerCache = new Map();
playerProps.forEach(prop => {
this.playerCache.set(prop, this[prop]);
});
const props = playerProps.reduce((prev, prop) => (Object.assign(Object.assign({}, prev), { [prop]: {
get() {
return this.playerCache.get(prop);
},
set: (value) => {
if (this.playerCache.get(prop) !== value) {
this.playerDispatch(prop, value);
this.playerCache.set(prop, value);
}
},
} })), {});
Object.defineProperties(this, props);
}
ngAfterViewInit() {
return __awaiter(this, void 0, void 0, function* () {
if (!this.ref.nativeElement)
return;
this.player = yield findPlayer(this.ref.nativeElement);
if (!this.player)
return;
this.playerDispatch = createDispatcher(this.ref.nativeElement);
this.unbindPlayerContext = yield usePlayerContext(this.ref.nativeElement, this.playerProps, (prop, value) => {
this.playerCache.set(prop, value);
this[prop] = value;
}, this.player);
});
}
ngOnDestroy() {
var _a;
(_a = this.unbindPlayerContext) === null || _a === void 0 ? void 0 : _a.call(this);
this.playerCache.clear();
}
}
VimeComponent.decorators = [
{ type: Injectable }
];
VimeComponent.ctorParameters = () => [
{ type: Array }
];
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVmltZUNvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3Byb2plY3RzL3ZpbWUvc3JjL1ZpbWVDb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE9BQU8sRUFHTCxVQUFVLEVBQ1YsZ0JBQWdCLEVBQ2hCLGdCQUFnQixHQUNqQixNQUFNLFlBQVksQ0FBQztBQUNwQixPQUFPLEVBQWMsVUFBVSxFQUFFLE1BQU0sZUFBZSxDQ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