/*
 * Copyright 2017-2021 VMware, Inc. All rights reserved. VMware Confidential
 */
import { ActivatedRoute } from "@angular/router";
import { SubscriptionTracker } from "../../subscription-tracker.service";

export function readParamFromUrlByName(
    parentClass: any,
    activatedRoute: ActivatedRoute,
    paramName: string,
    onChange: (paramValue: string) => void,
    subTracker: SubscriptionTracker
): void {
    if (activatedRoute) {
        subTracker.subscribe(activatedRoute.params, (routeParameters: any) => {
            onChange.bind(parentClass)(routeParameters[paramName]);
        });
    }
}
