Open langpavel opened 8 years ago
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__@@
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 Actually, Record can be detected in this way:
const isRecord = o => !!(
o['@@__IMMUTABLE_KEYED__@@'] &&
o['@@__IMMUTABLE_ITERABLE__@@'] &&
o._defaultValues);
It will helps a lot if
installDevTools
can be called directly in this package and only required injectiong code will berequire('immutable-devtools')