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

Feature/dynamic dom #17

Merged
merged 30 commits into from
May 22, 2017
Merged

Feature/dynamic dom #17

merged 30 commits into from
May 22, 2017

Conversation

jennasalau
Copy link
Member

@jennasalau jennasalau commented May 21, 2017

Hey guys,

If you can cast your eyes over this one I would appreciate it for my own sanity. If nothing jumps out at you please give it a tick of approval so I feel slightly more comfortable merging it :)

The bulk of the work has been to the Bootstrapper class.

This PR address issue number #12 by adding a new update() method as well as implementing an automatic dom watcher via the MutationObserver api.

Watcher performance looks good and everything still pretty snappy. I've tested in IE9 & 10 with a polyfill and again impressed with performance.

Im not sure if the watcher should be enabled by default though?.. on one part I like that "it will just work" out of the box. However, theoretically it will perform better with the watcher disabled and you manually call update() after a dom change (which would be my recommendation for serious web apps). What default do you think is better?

@dkeeghan
Copy link
Member

Looks like a good fix. In regards to your question about the watcher can you make it configurable to enable or disable if you choose? I agree for most larger apps it would be smarter to run it as needed but to make it easier for people who aren't as familiar with React it might be good to have it there.

@keeganstreet
Copy link

Looks good! Small suggestion - I would prefer if we import the MutationObserver polyfill via npm, and then self-host it, rather than loading it from a third party CDN. Otherwise we are completely trusting that CDN not to execute malicious code on our sites. It is an unnecessary security vulnerability.

@jennasalau
Copy link
Member Author

Thanks for the feedback 👍

@dkeeghan yes I've made it configurable so you can opt in to switch it off with this.enableWatcher = false;

I did have a thought this morning it might be better to have that passed in as an option when you set the container.

Example maybe this is better

this.setContainer(/*container=* /myContainer, /*enableWatcher=*/ false)

@keeganstreet good pick up and reasoning.. this is me being lazy. I'll get that updated to our best practice :)

@jeffdowdle
Copy link

jeffdowdle commented May 22, 2017

Personally I think disabling the watcher by default is the way to go. But I can see the argument for enabling it too.

The way I see it, as someone new to using React Habitat, I'd probably take these steps:

  1. Get my app/containers working on my static HTML.
  2. Live happily for a while, possibly forever.
  3. I realise I need to re-render my component for whatever reason.
  4. I search the React Habitat docs for 'dynamic html' or something similar. Then I follow the instructions there.

I would expect most people to stop at step 2, and this way they all get the performance benefits without having to know about the watcher option.

@jennasalau
Copy link
Member Author

Okay I've implemented everyones feedback. I've ended up agreeing with @jeffdowdle and I actually think disabled by default works much better now. As soon as I did that all my unit tests where much easier to write too. I was slightly worried that developers might complain that it chugs on large apps with the watcher, at least this way they are making conscious decisions and I will sleep easier.

@keeganstreet No more CDN's in the examples :)

The docs are starting to get huge. Not sure what we can do about that, but might have a review later on.

Does this look okay to everyone for a merge?

Copy link
Member

@dkeeghan dkeeghan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Nice one! Yep, we should look at a static site using GitHub.io as a standard docs format when they get large like this.

@jennasalau jennasalau merged commit 37a7cd8 into develop May 22, 2017
@jennasalau jennasalau deleted the feature/dynamic-dom branch May 22, 2017 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants