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

Throw away dependency on Immutable #20

Open
langpavel opened this issue Mar 26, 2016 · 3 comments
Open

Throw away dependency on Immutable #20

langpavel opened this issue Mar 26, 2016 · 3 comments

Comments

@langpavel
Copy link
Collaborator

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
Copy link
Collaborator Author

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__@@

@mattzeunert
Copy link
Collaborator

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
Copy link
Collaborator Author

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

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

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

No branches or pull requests

2 participants