andrewdavey / immutable-devtools

Chrome Dev Tools custom formatter for Immutable-js values
BSD 3-Clause "New" or "Revised" License
661 stars 29 forks source link

Throw away dependency on Immutable #20

Open langpavel opened 8 years ago

langpavel commented 8 years ago

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 commented 8 years ago

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

mattzeunert commented 8 years ago

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.

langpavel commented 8 years ago

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

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