ngOnInit()

in toolings/tfjs-debugger/src/app/components/backend_selector/backend_version_selector.component.ts [56:123]


  ngOnInit() {
    // Get the fetched TFJS releases and update selector options.
    this.store.select(selectTfjsReleases)
        .pipe(takeWhile(() => this.active))
        .subscribe(releases => {
          if (releases.length === 0) {
            return;
          }

          // Store locally.
          this.releases.push(...releases);
          for (const release of releases) {
            this.releasesMap.set(release.version, release);
          }

          // Only set default value if selectedVersion has not been set from
          // url.
          if (!this.selectedVersion) {
            this.selectedVersion = this.releases[0].version;

            // Update url with the default version.
            //
            // This is necessary because default value might change over time
            // (e.g. when we release new versions). We encode the actual version
            // number to url to make sure the url always points to the correct
            // version that user was looking at.
            //
            // We don't do this for other form fields because their default
            // values rarely change.
            this.updateUrlWithVersion(this.selectedVersion);
          }
          this.changeDetectorRef.markForCheck();
        });

    // Update currently selected backend version from URL.
    this.store
        .select(selectConfigValueFromUrl(
            this.configIndex, UrlParamKey.SELECTED_BACKEND_VERSION))
        .pipe(
            takeWhile(() => this.active),
            distinctUntilChanged(),
            )
        .subscribe(strVersion => {
          let version = '';

          // Set default version.
          if (this.releases.length > 0 && !this.selectedVersion) {
            version = this.releases[0].version;

            // Update url with the default version.
            //
            // See comments above about why this is necessary.
            if (!strVersion) {
              this.updateUrlWithVersion(version);
            }
          }
          if (strVersion) {
            version = strVersion;
          }

          if (version) {
            this.selectedVersion = version;
            this.changeDetectorRef.markForCheck();
          }

          // TODO: update configs in store.
        });
  }