immutable-devtools icon indicating copy to clipboard operation
immutable-devtools copied to clipboard

Throw away dependency on Immutable

Open langpavel opened this issue 9 years ago • 3 comments

It will helps a lot if installDevTools can be called directly in this package and only required injectiong code will be require('immutable-devtools')

langpavel avatar Mar 26 '16 15:03 langpavel

How to detect Immutable objects? Under the hood this is possible because of special properties on prototype called sentinels:

  • @@__IMMUTABLE_INDEXED__@@
  • @@__IMMUTABLE_ITERABLE__@@
  • @@__IMMUTABLE_KEYED__@@
  • @@__IMMUTABLE_LIST__@@
  • @@__IMMUTABLE_MAP__@@
  • @@__IMMUTABLE_ORDERED__@@
  • @@__IMMUTABLE_SEQ__@@
  • @@__IMMUTABLE_SET__@@
  • @@__IMMUTABLE_STACK__@@

langpavel avatar Mar 26 '16 15:03 langpavel

From what I've found the only change that needs to be made is replacing instanceOf Immutable.Record. Everything else already uses the sentinels under the hood, so you can include the Immutable library in the bookmarklet, rather than depending on the one on the page.

It's not pure, but using record._defaultValues !== undefined to detect Records worked for me.

mattzeunert avatar Mar 26 '16 16:03 mattzeunert

@mattzeunert Actually, Record can be detected in this way:

const isRecord = o => !!(
  o['@@__IMMUTABLE_KEYED__@@'] && 
  o['@@__IMMUTABLE_ITERABLE__@@'] &&
  o._defaultValues);

langpavel avatar Mar 26 '16 17:03 langpavel