From 44ef420f165e0185919af1e6b2204f8acebb7904 Mon Sep 17 00:00:00 2001 From: Colby Rabideau Date: Mon, 4 Dec 2017 16:27:31 -0500 Subject: [PATCH] Revert "make indexBy more type sensitive" This reverts commit a911be7f5a4a1909e6b38cbff98887877c785e2c. --- src/__tests__/__snapshots__/indexBy-test.js.snap | 6 +++--- src/indexBy.js | 8 ++++---- src/internal/_keyedEquivalent.js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/__tests__/__snapshots__/indexBy-test.js.snap b/src/__tests__/__snapshots__/indexBy-test.js.snap index ee3ee41..2b433ac 100644 --- a/src/__tests__/__snapshots__/indexBy-test.js.snap +++ b/src/__tests__/__snapshots__/indexBy-test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`transmute/indexBy indexes a List 1`] = ` -Immutable.Map { +Immutable.OrderedMap { "123": Immutable.Map { "id": "123", }, @@ -23,7 +23,7 @@ Immutable.Map { `; exports[`transmute/indexBy indexes an Array 1`] = ` -Object { +Immutable.OrderedMap { "123": Immutable.Map { "id": "123", }, @@ -34,7 +34,7 @@ Object { `; exports[`transmute/indexBy indexes an Object 1`] = ` -Object { +Immutable.OrderedMap { "123": Object { "id": "123", }, diff --git a/src/indexBy.js b/src/indexBy.js index 6b72970..f146d48 100644 --- a/src/indexBy.js +++ b/src/indexBy.js @@ -1,13 +1,13 @@ -import _keyedEquivalent from './internal/_keyedEquivalent'; import _reduce from './internal/_reduce'; -import _set from './internal/_set'; import curry from './curry'; import { Iterable, Map, OrderedMap } from 'immutable'; function indexBy(keyMapper, subject) { return _reduce( - _keyedEquivalent(subject), - (acc, v, k) => _set(keyMapper(v, k, subject), v, acc), + Iterable.isOrdered(subject) || !Iterable.isIterable(subject) + ? OrderedMap() + : Map(), + (acc, v, k) => acc.set(keyMapper(v, k, subject), v), subject ); } diff --git a/src/internal/_keyedEquivalent.js b/src/internal/_keyedEquivalent.js index b95dcfd..8eea5bc 100644 --- a/src/internal/_keyedEquivalent.js +++ b/src/internal/_keyedEquivalent.js @@ -1,4 +1,4 @@ -import { Collection, Iterable, Map, Seq } from 'immutable'; +import { Collection, Map, Seq } from 'immutable'; import { keyedEquivalent } from './TransmuteCollection'; const makeObject = () => ({});