Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with Immutable.js structures #42

Closed
jamesopti opened this issue Apr 9, 2019 · 2 comments
Closed

Working with Immutable.js structures #42

jamesopti opened this issue Apr 9, 2019 · 2 comments

Comments

@jamesopti
Copy link

Summary

The project where I'd like to use this package uses ImmutableJS for many of its data collections, which are often passed to React as props.

If I were to use this in that library, what would be the best way to handle ImmutableJS comparisons, where the Immutable.is method is preferred.

Thanks!

@chrisbolin
Copy link
Contributor

Great question! How about just writing a custom function like this...

var isEqual = require("react-fast-compare");
const { Map, is } = require("immutable");

function extendedIsEqual(a, b) {
  // try Immutable
  if (is(a, b)) return true;
  // try react-fast-compare
  if (isEqual(a, b)) return true;
  // recurse Object-like entities
  if (a && b && typeof a == "object" && typeof b == "object") {
    var keys = Object.keys(a);
    for (var i = keys.length; i-- !== 0; ) {
      var key = keys[i];
      if (!extendedIsEqual(a[key], b[key])) return false;
    }
    return true;
  }
  return a === b;
}

Here's a demo of it: https://codesandbox.io/s/0o4n312kmp (see the Terminal output).

@chrisbolin
Copy link
Contributor

closing this, as a we have a workaround AND the new v3 is focused on ES6 support, speed, and bundle size. there's just not room for custom support for immutable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants