-
Notifications
You must be signed in to change notification settings - Fork 751
[feedback requested] Create a installation generator #64
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
Conversation
I think this is a great idea and would be a welcome addition. I started with keeping the folders in lib modeling the modules they're named after (I thought that was a Ruby gem pattern). I don't really care either way, just want to make sure we follow whatever best practices are. But I haven't written much Ruby in the past few years outside of the initial version of this gem, so I'll defer to others. |
Sorry, I guess my comment wasn't very clear. This pull request actually adds the generator for users that have installed the gem into their rails app, which is very similar to how ember-rails works. After merging this pull request, users who install the gem in their Rails app will be able to run The generator currently does not support CoffeeScript or custom names for application.js. One of the additional generators I'd like to build is |
No, sorry I wasn't clear! I think generators would be awesome. I was just getting nitpicky on the file path. I was thinking |
Oh, gotcha.
|
[Heavily based on the ember.js bootstrap generator] Running rails generate react:install will append the basic require directives to application.js Possible avenues for upgrades: - allow for files with arbitrary names ("mycomponents.js" instead of "application.js") - allow for files with different extensions ("application.js.coffee" instead of "application.js")
I'm just not sure whether it's super good to keep |
If there's a better alternative, I'm happy to pull out the components.js Can you give me an example of what you're thinking, even in pseudo-code? Or On Tuesday, August 5, 2014, Jakub Malinowski notifications@github.com
|
commonjs would be good #33 but maybe we should just proceed with this and then iteratively improve... |
react_ujs and the autorequiring of components is new in master. The install generator now accounts for some application.js files already having react installed.
@JakubMal I agree, supporting additional gems like |
JS modules (usually commonjs) are what we always recommend. I don't know what best practices are in Rails land for building JS bundles based on dependencies & that sort of thing. Browserify & co have picked up a lot of steam in the node community. There are always going to be issues with the view helpers so I think just be opinionated and build what seems to work best. |
@zpao TL;DR - CommonJS would be really nice, but it's not the "Rails way." I would love for that to change, but that's a long ways (and a separate gem) away. For now I would recommend sticking with components.js. Rails does not have a good story for integrating Browseify or CommonJS modules. Instead, Rails uses a version of Sprockets -- the integration is referred to as the asset pipeline. As I remember it, Sprockets was built before node.js really took off, and it's stuck around mainly because that's what Basecamp uses. Dependencies can be managed using It's possible that you could do things like this: <%= react_component 'Bar' %> //= require react
//= require components/foo
var Bar = react.createClass({
render: function() {
return <div><Foo /></div>;
}
}); If the view helper then only asked the asset pipeline for the components/bar.js file, the asset pipeline could figure out the dependencies on react and foo and bundle those together. However, I think this is a really bad, Un-Rails-y way of doing it. It would break a lot of user's assumptions about how the asset pipeline works, and probably would end up building a lot of different js files and holding them in memory. The asset pipeline has a build process, where the |
👍 Thanks for the explanation. I knew some of the asset pipeline stuff, just not sure if it had really changed in the past few years. Sounds like no. The biggest JS-related innovation seems to be Turbolinks and that's really just to make is easier to continue using server-side views. I don't know how any Rails apps with non-trivial JS survive, unless they all use coffeescript and get IIFEs for free. Still needs to be globals somewhere if these bits of code are supposed to talk to each other. There's a lot of room for error with straight file concats but that's what we have. If we want to be good Rails citizens (and I think we do), let's do it their way and use... globals and I guess |
All of your observations and assumptions about Rails projects using non-trivial amounts of Javascript are correct. Turbolinks is flaky, and CoffeeScript allows them to punt on a real JS strategy for a few more years. That said, the situation is much improved from the bad old days, where you just stuck your JS in the public directory grab-bag and Rails dropped in 10-15 individual I'd love to use CommonJS, and if I were building a large new app from scratch, I'd probably disable the asset pipeline altogether and use something like Broccoli for front-end stuff instead. But I also have to work on legacy projects where the asset pipeline is already working, and I think react-rails could make the most sense for those apps. |
Sprockets works fine for Angular apps - it can work fine for us too. But let's proceed with global namespacing for now. |
OK, so, are there any changes I need to make before this can be merged? |
Probably want to add usage to the readme. Apart from that I think this looks fine. Any other comments @JakubMal? |
+1 for readme, no more comments |
Apologies for disappearing and letting this drop. I added the smallest amount to the README that would be necessary to communicate this. I'm not sure an install generator really needs much more than that. |
[feedback requested] Create a installation generator
Thanks, I think this is a great addition! I'm sure we'll here if anything goes wrong so keep an eye out. |
[Heavily based on the ember.js bootstrap generator]
Running
rails generate react:install
will append the basic require directives to application.jsPossible avenues for upgrades: