Draft-js: ContentState comparisons: how to test whether ContentState has changed?

Created on 11 Jul 2017  路  1Comment  路  Source: facebook/draft-js

Do you want to request a feature or report a bug?

This is a question.

What is the current behavior?

What is the best way to compare ContentStates? I understand that ContentState is an Immutable Record, so part of its charm should be its #equals() method. I was hoping to be able to compare ContentStates to see whether data needed to be synced remotely. I'm not sure how to do this.

It appears that ContentStates aren't actually comparable in the Immutable sense. For example, suppose:

var raw = convertToRaw(state)
var state1 = convertFromRaw(raw)
var state2 = convertFromRaw(raw)

Now, not only is state1.equals(state2) === false, but also state1.getBlockMap().equals(state2.getBlockMap()) === false.

And the entityMap, which is currently in the process of being transitioned to the Immutable API as I understand it, is currently not Immutable and therefore not comparable.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. You can use this jsfiddle to get started: https://jsfiddle.net/stopachka/m6z0xn4r/.

What is the expected behavior?

Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js?

question

Most helpful comment

Yes,

var state1 = convertFromRaw(raw)
var state2 = convertFromRaw(raw)
state1.getBlockMap().equals(state2.getBlockMap()) // false

but that's okay?

>All comments

Yes,

var state1 = convertFromRaw(raw)
var state2 = convertFromRaw(raw)
state1.getBlockMap().equals(state2.getBlockMap()) // false

but that's okay?

Was this page helpful?
0 / 5 - 0 ratings