当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ReplaySubject.asObservable方法代码示例

本文整理汇总了TypeScript中rxjs.ReplaySubject.asObservable方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ReplaySubject.asObservable方法的具体用法?TypeScript ReplaySubject.asObservable怎么用?TypeScript ReplaySubject.asObservable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rxjs.ReplaySubject的用法示例。


在下文中一共展示了ReplaySubject.asObservable方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: constructor

 constructor(monitor: MediaMonitor,
             elRef: ElementRef,
             styleUtils: StyleUtils) {
   super(monitor, elRef, styleUtils);
   this._announcer = new ReplaySubject<Layout>(1);
   this.layout$ = this._announcer.asObservable();
 }
开发者ID:marffox,项目名称:flex-layout,代码行数:7,代码来源:layout.ts

示例2: _getNpmPackageJson

/**
 * Get the NPM repository's package.json for a package. This is p
 * @param {string} packageName The package name to fetch.
 * @param {LoggerApi} logger A logger instance to log debug information.
 * @returns {Observable<JsonObject>} An observable that will put the pacakge.json content.
 * @private
 */
function _getNpmPackageJson(
  packageName: string,
  logger: logging.LoggerApi,
): Observable<JsonObject> {
  const url = `https://registry.npmjs.org/${packageName.replace(/\//g, '%2F')}`;
  logger.debug(`Getting package.json from ${JSON.stringify(packageName)}...`);

  let maybeRequest = npmPackageJsonCache.get(url);
  if (!maybeRequest) {
    const subject = new ReplaySubject<JsonObject>(1);

    const request = https.request(url, response => {
      let data = '';
      response.on('data', chunk => data += chunk);
      response.on('end', () => {
        try {
          const json = parseJson(data, JsonParseMode.Strict);
          subject.next(json as JsonObject);
          subject.complete();
        } catch (err) {
          subject.error(err);
        }
      });
      response.on('error', err => subject.error(err));
    });
    request.end();

    maybeRequest = subject.asObservable();
    npmPackageJsonCache.set(url, maybeRequest);
  }

  return maybeRequest;
}
开发者ID:fmalcher,项目名称:angular-cli,代码行数:40,代码来源:npm.ts

示例3: concatMap

        concatMap(options => {
          const subject = new ReplaySubject<NpmRepositoryPackageJson>(1);

          const client = new RegistryClient({
            proxy: {
              http: options[0],
              https: options[1],
            },
          });
          client.log.level = 'silent';
          const params = {
            timeout: 30000,
          };

          client.get(
            fullUrl,
            params,
            (error: object, data: NpmRepositoryPackageJson) => {
            if (error) {
              subject.error(error);
            }

            subject.next(data);
            subject.complete();
          });

          maybeRequest = subject.asObservable();
          npmPackageJsonCache.set(fullUrl.toString(), maybeRequest);

          return maybeRequest;
        }),
开发者ID:iwe7,项目名称:devkit,代码行数:31,代码来源:npm.ts

示例4: componentDestroyed

export function componentDestroyed(component: OnDestroyLike): Observable<true> {
    if (component.__componentDestroyed$) {
        return component.__componentDestroyed$;
    }
    const oldNgOnDestroy = component.ngOnDestroy;
    const stop$ = new ReplaySubject<true>();
    component.ngOnDestroy = function () {
        oldNgOnDestroy && oldNgOnDestroy.apply(component);
        stop$.next(true);
        stop$.complete();
    };
    return component.__componentDestroyed$ = stop$.asObservable();
}
开发者ID:antonioplacerda,项目名称:loading-sample,代码行数:13,代码来源:componetDestroyed.ts

示例5: getNpmConfigOption

function getNpmConfigOption(
  option: string,
  scope?: string,
  tryWithoutScope?: boolean,
): Observable<string | undefined> {
  if (scope && tryWithoutScope) {
    return concat(
      getNpmConfigOption(option, scope),
      getNpmConfigOption(option),
    ).pipe(
      filter(result => !!result),
      defaultIfEmpty(),
      first(),
    );
  }

  const fullOption = `${scope ? scope + ':' : ''}${option}`;

  let value = npmConfigOptionCache.get(fullOption);
  if (value) {
    return value;
  }

  const subject = new ReplaySubject<string | undefined>(1);

  try {
    exec(`npm get ${fullOption}`, (error, data) => {
      if (error) {
        subject.next();
      } else {
        data = data.trim();
        if (!data || data === 'undefined' || data === 'null') {
          subject.next();
        } else {
          subject.next(data);
        }
      }

      subject.complete();
    });
  } catch {
    subject.next();
    subject.complete();
  }

  value = subject.asObservable();
  npmConfigOptionCache.set(fullOption, value);

  return value;
}
开发者ID:fmalcher,项目名称:angular-cli,代码行数:50,代码来源:npm.ts

示例6: concatMap

        concatMap(options => {
          const [
            http,
            https,
            strictSsl,
            cafile,
            token,
            username,
            password,
            alwaysAuth,
          ] = options;

          const subject = new ReplaySubject<NpmRepositoryPackageJson>(1);

          const sslOptions = getNpmClientSslOptions(strictSsl, cafile);

          let auth;
          if (token) {
            auth = { token, alwaysAuth };
          } else if (username) {
            auth = { username, password, alwaysAuth };
          }

          const client = new RegistryClient({
            proxy: { http, https },
            ssl: sslOptions,
          });
          client.log.level = 'silent';
          const params = {
            timeout: 30000,
            auth,
          };

          client.get(
            fullUrl.toString(),
            params,
            (error: object, data: NpmRepositoryPackageJson) => {
            if (error) {
              subject.error(error);
            }

            subject.next(data);
            subject.complete();
          });

          maybeRequest = subject.asObservable();
          npmPackageJsonCache.set(fullUrl.toString(), maybeRequest);

          return maybeRequest;
        }),
开发者ID:fmalcher,项目名称:angular-cli,代码行数:50,代码来源:npm.ts

示例7: getNpmConfigOption

function getNpmConfigOption(
  option: string,
  scope?: string,
  tryWithoutScope?: boolean,
): Observable<string | undefined> {
  if (scope && tryWithoutScope) {
    return concat(
      getNpmConfigOption(option, scope),
      getNpmConfigOption(option),
    ).pipe(
      filter(result => !!result),
      defaultIfEmpty(),
      first(),
    );
  }

  const fullOption = `${scope ? scope + ':' : ''}${option}`;

  let value = npmConfigOptionCache.get(fullOption);
  if (value) {
    return value;
  }

  const subject = new ReplaySubject<string | undefined>(1);

  const optionValue = npmConfig && npmConfig[fullOption];
  if (optionValue == undefined || optionValue == null) {
    subject.next();
  } else {
    subject.next(optionValue);
  }

  subject.complete();

  value = subject.asObservable();
  npmConfigOptionCache.set(fullOption, value);

  return value;
}
开发者ID:rexebin,项目名称:angular-cli,代码行数:39,代码来源:npm.ts

示例8:

 get resultPage$(): Observable<ResultPage> {
     return this.subject.asObservable();
 }
开发者ID:netlogix,项目名称:angular2-jsonapi-src,代码行数:3,代码来源:paginator.ts

示例9:

 (collection.getSelectedNote as Spy).and.callFake(() => selectedNoteStream.asObservable());
开发者ID:suiruiw,项目名称:geeks-diary,代码行数:1,代码来源:note-editor.component.spec.ts

示例10: concatMap

        concatMap(options => {
          const [
            http,
            https,
            strictSsl,
            cafile,
            token,
            authToken,
            username,
            password,
            email,
            alwaysAuth,
          ] = options;

          const subject = new ReplaySubject<NpmRepositoryPackageJson>(1);

          const sslOptions = getNpmClientSslOptions(strictSsl, cafile);

          const auth: {
            token?: string,
            alwaysAuth?: boolean;
            username?: string;
            password?: string;
            email?: string;
          } = {};

          if (alwaysAuth !== undefined) {
            auth.alwaysAuth = alwaysAuth === 'false' ? false : !!alwaysAuth;
          }

          if (email) {
            auth.email = email;
          }

          if (authToken) {
            auth.token = authToken;
          } else if (token) {
            try {
              // attempt to parse "username:password" from base64 token
              // to enable Artifactory / Nexus-like repositories support
              const delimiter = ':';
              const parsedToken = Buffer.from(token, 'base64').toString('ascii');
              const [extractedUsername, ...passwordArr] = parsedToken.split(delimiter);
              const extractedPassword = passwordArr.join(delimiter);

              if (extractedUsername && extractedPassword) {
                auth.username = extractedUsername;
                auth.password = extractedPassword;
              } else {
                throw new Error('Unable to extract username and password from _auth token');
              }
            } catch (ex) {
              auth.token = token;
            }
          } else if (username) {
            auth.username = username;
            auth.password = password;
          }

          const client = new RegistryClient({
            proxy: { http, https },
            ssl: sslOptions,
          });
          client.log.level = 'silent';
          const params = {
            timeout: 30000,
            auth,
          };

          client.get(
            fullUrl.toString(),
            params,
            (error: object, data: NpmRepositoryPackageJson) => {
            if (error) {
              subject.error(error);
            }

            subject.next(data);
            subject.complete();
          });

          maybeRequest = subject.asObservable();
          npmPackageJsonCache.set(fullUrl.toString(), maybeRequest);

          return maybeRequest;
        }),
开发者ID:baconwaffles,项目名称:angular-cli,代码行数:86,代码来源:npm.ts


注:本文中的rxjs.ReplaySubject.asObservable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。