Skip to content

Conversation

@tonymarklove
Copy link

Use a custom watcher/reloader middleware to find all the dependent
files of component_filenames and watch them for changes.

The reloader sits outside of the Rails stack, but makes use of
ActiveSupport::FileUpdateChecker.

This has a few benefits:

  1. Non-jsx files can easily be watched. For example, changes to
    components.js and other helper files are detected.
  2. Newly required files can be detected and added to the list of
    watched files for future updates.
  3. We don’t force Rails to reload its own Ruby classes when only .js
    or .jsx files have changed.

One potentially controversial change, which didn’t seem to provide
much benefit before:

  • Moved the concatenated source files for components.js and react.js
    out of the app config. They are now encapsulated in the
    after_initialize block.
Use a custom watcher/reloader middleware to find all the dependent files of component_filenames and watch them for changes. The reloader sits outside of the Rails stack, but makes use of ActiveSupport::FileUpdateChecker. This has a few benefits: 1. Non-jsx files can easily be watched. For example, changes to components.js and other helper files are detected. 2. Newly required files can be detected and added to the list of watched files for future updates. 3. We don’t force Rails to reload its own Ruby classes when only .js or .jsx files have changed. One potentially controversial change, which didn’t seem to provide much benefit before: - Moved the concatenated source files for components.js and react.js out of the app config. They are now encapsulated in the after_initialize block.
@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@pboling
Copy link

pboling commented Oct 22, 2014

This is great! 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

How about component_source_files or component_sources, since we are catching multiple files here?

Copy link
Author

Choose a reason for hiding this comment

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

We are catching multiple files, but it ends up as a single large source block. So I have renamed to combined_components_source to better document its purpose.

Tony Marklove added 2 commits November 3, 2014 10:28
We only ever expect to call this internally, so the extra check is not very useful.
Make it clearer that it is the result of concatenating all the component source files listed in the config.
@rmosolgo
Copy link
Member

I think this is handled by the gem now, because

  • We watch .jsx files (src)
  • To reload, we clear out existing renderers (src)

If that's not sufficient or if I've missed something, please feel free to re-open & rebase on master!

@rmosolgo rmosolgo closed this Feb 12, 2016
@tonymarklove tonymarklove deleted the dependent-js-reloading branch March 3, 2023 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants