"use strict";
// Copyright 2017-2020 @polkadot/rpc-core authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
Object.defineProperty(exports, "__esModule", { value: true });
const operators_1 = require("rxjs/operators");
const util_1 = require("@polkadot/util");
const refCountDelay_1 = require("./refCountDelay");
const l = util_1.logger('drr');
const CMP = (a, b) => JSON.stringify({ t: a }) === JSON.stringify({ t: b });
const ERR = (error) => {
    l.error(error);
    throw error;
};
const NOOP = () => undefined;
/**
 * Shorthand for distinctUntilChanged(), publishReplay(1) and refCount().
 *
 * @ignore
 * @internal
 */
exports.drr = ({ skipChange = false, skipTimeout = false } = {}) => (source$) => source$.pipe(operators_1.catchError(ERR), skipChange
    ? operators_1.tap(NOOP)
    : operators_1.distinctUntilChanged(CMP), operators_1.publishReplay(1), skipTimeout
    ? operators_1.refCount()
    : refCountDelay_1.refCountDelay());
