php-hot-reloader icon indicating copy to clipboard operation
php-hot-reloader copied to clipboard

Included files

Open ttodua opened this issue 4 years ago • 2 comments

It would be nice if the script had a feature to reload the current page, only if any of the related files (which have been used while generating the current page) is changed (as opposed to "any" file change in the project dir, or manually setting the "watch-files" list).

To achieve that, it should have been done the following way:

  1. If user wants to use that approach, he should set the project_dir in the initializer, like: new HotReloader\HotReloader('//localhost/'', __DIR__ )
  2. Then, in "register_shutdown_hook" (when injecting EVENT_SOURCE_ENDPOINT codes in HTML), it should get all files that were involved in page execution, using get_included_files().
  3. Due to possible large-list of included files, instead of query, send the data with Session-ids.
  4. in phrwatcher, make fileslist parameter into array and check if the changed file's path is in that array. If so, send reload signal, otherwise don't send.

This will save much of unnecessary reloads, while we work on the project ALL OPEN TABS are reloaded, when only one file (related to specific page) changes, and it looses all the Client-Side changes on all tabs (i.e. filled forms, JavaScript actions and states on UI), which are not necessary to have changed. So, this will solve the problem and increase the efficiency.

ttodua avatar Jan 24 '21 20:01 ttodua

Ideally, in my mind (as the script is totally intended for development stage), the variables could be set-able from the initializer , when including lines new HotReloader\HotReloader('....) in our scripts, so i.e.:

new HotReloader\HotReloader(..url.., project_dir, ignored_files, enabled, ...)

those variables could be set there, and thus, disregard changing anything in phrwatcher.php at all. Thus, there will not be need to change 2 files in order to use PHR, and just tell people in readme that they need just set them inside their project (imho, I find a bit complicated readme for newcomers, while many projects tend to give "example usages" in one paragraphs, here the repo has a bit larger readme to understand how to use the project, however, i might be wrong, just my 2 cents).

ttodua avatar Jan 24 '21 20:01 ttodua

set them inside their project

Yes, that's what I was trying to say here: https://github.com/felippe-regazio/php-hot-reloader/issues/14#issue-784998893

If the plugin is installed via composer, imo it's absolutely necessary to have to set set the variables only from outside the plugin.

moevbiz avatar Feb 12 '21 21:02 moevbiz