"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.skipListsMerger = void 0;

var _immutable = _interopRequireDefault(require("immutable"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

/* * *  *  * *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  * */

/* Copyright (c) 2018 Mobify Research & Development Inc. All rights reserved. */

/* * *  *  * *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  * */
var isList = _immutable["default"].List.isList; // Ensures the new list is always used when merging Maps that contain lists
// Otherwise we would end up with something like this:
// for a = {test: [1, 2, 3]}, b = {test: [1, 2]}
// a.mergeDeep(b) => {test: [1, 2, 3]}
// When we want it to return {test: [1, 2]} (ie. delete the third item)
// Based on: https://github.com/facebook/immutable-js/issues/762

var skipListsMerger = function skipListsMerger(a, b) {
  if (a && a.mergeWith && !isList(a) && !isList(b)) {
    return a.mergeWith(skipListsMerger, b);
  }

  return b;
};

exports.skipListsMerger = skipListsMerger;