You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 19, 2018. It is now read-only.
class Bar < Foo
...
do_something_with Baz
...
def my_fat_method
Hello.there()
end
end
Hyperloop automatically requires all files in the hyperloop directory in alphabetical order. This means the above case will not work (assuming Foo is a file named foo.rb, and Baz is in baz.rb.)
Rails does all this by intercepting const_missing, and using file naming convention finds the file, requires it, and returns the newly defined const.
In the case of Hyperloop we have to do this by running a preprocessor whenever we notice a file has changed or been added.
I think the preprocessor can actually leverage the rails autoload feature like this:
Patch the auto-loader so it logs someplace when it has to require a file (so we can record the load order)
create dummy classes and modules for all the client side hyperloop constants (i.e. Hyper::Component, Hyperloop::Store etc etc) (otherwise we aint going to find these)
Then start loading the files in alphabetical order and adding each file to the same log as the auto-loader patch is using.
The log will now be the ordered list of requires!
If this doesn't work, then another approach would be to do something similar in the server side JS environment.
Finally there have been other ideas about dynamically requiring and loading the code from the server in JIT fashion. This would be great as the actual page download would now be dependent only on the files used! By architecting systems (and hyperloop itself) you could automatically minimize the download size. Pretty complicated but cool.
And now really finally: I don't quite understand why Opal can't do this anyway??? Opal has all the code compiled ahead of time, and the requires (which must be static) point to the object to "load" (meaning execute top level context). So why can't we just keep track of the file names, and implement our own auto-loader in Opal itself.
The text was updated successfully, but these errors were encountered:
Consider this example to understand the theory:
Hyperloop automatically requires all files in the hyperloop directory in alphabetical order. This means the above case will not work (assuming Foo is a file named foo.rb, and Baz is in baz.rb.)
Rails does all this by intercepting const_missing, and using file naming convention finds the file, requires it, and returns the newly defined const.
In the case of Hyperloop we have to do this by running a preprocessor whenever we notice a file has changed or been added.
I think the preprocessor can actually leverage the rails autoload feature like this:
Hyper::Component
,Hyperloop::Store
etc etc) (otherwise we aint going to find these)The log will now be the ordered list of requires!
If this doesn't work, then another approach would be to do something similar in the server side JS environment.
Finally there have been other ideas about dynamically requiring and loading the code from the server in JIT fashion. This would be great as the actual page download would now be dependent only on the files used! By architecting systems (and hyperloop itself) you could automatically minimize the download size. Pretty complicated but cool.
And now really finally: I don't quite understand why Opal can't do this anyway??? Opal has all the code compiled ahead of time, and the requires (which must be static) point to the object to "load" (meaning execute top level context). So why can't we just keep track of the file names, and implement our own auto-loader in Opal itself.
The text was updated successfully, but these errors were encountered: