UNPKG

@parity/light.js

Version:

A high-level reactive JS library optimized for light clients

36 lines (35 loc) 1.07 kB
"use strict"; // Copyright 2015-2019 Parity Technologies (UK) Ltd. // This file is part of Parity. // // SPDX-License-Identifier: MIT Object.defineProperty(exports, "__esModule", { value: true }); var bignumber_js_1 = require("bignumber.js"); var operators_1 = require("rxjs/operators"); var types_1 = require("@parity/api/lib/util/types"); /** * An intelligent distinctUntilChanged(). * * @ignore */ exports.distinctValues = function () { return operators_1.distinctUntilChanged(function (x, y) { // If T == Block if (x && y && x.number && y.number) { return x.number.eq(y.number); } // If T == BigNumber if (bignumber_js_1.default.isBigNumber(x) && bignumber_js_1.default.isBigNumber(y)) { return x.eq(y); } // If T == object if (types_1.isObject(x) && types_1.isObject(y)) { return JSON.stringify(x) === JSON.stringify(y); // TODO Do a deep equal instead } // Other cases return x === y; }); };