rendrjs / rendr

Render your Backbone.js apps on the client and the server, using Node.js.
MIT License
4.09k stars 312 forks source link

Using Rendr with RequireJS #155

Open alexindigo opened 10 years ago

alexindigo commented 10 years ago

Hi Spike,

I'm another person on Trulia's team treading Rendr way for our mobile site.

One of the branches of our exploration is to make our app less monolithic, which brought us to requirejs as server/client conditional-/lazy- loading for the components.

I created proof-of-concept grunt-rendr-requirejs and had to hack rendr a bit to make it actually work. So it does and look very promising.

Although some of the pieces are still tangled together, and this is where we want to have a conversation with you, to better understand your roadmap.

Basically, I had to wrap some of the rendr modules into amd-define and it works pretty well on the server, save for couple extra lines of boilerplate.

But main thing we've bumped into is routing which wants to have all the controllers on init time and compiledTemplates, which again brings all the templates into single file.

I know you already talked to Jon and he is playing with modules-as-separate-apps, but this route brings us a lot of overhead in terms of shared code (will be great deal later down the road).

So, what is your stand on refactoring routes and template part to allow lazy loading/init so it will work with both stitch and requirejs approach?

I'm cleaning up my hack to make it into somewhat more presentable proof-of-concept. And would like to hear your opinion on early stages of the process, I'm sure sure you had some thoughts on this direction and probably can point to places I need to pay extra attention to. :)

Thank you.

spikebrehm commented 10 years ago

Thanks for bringing this up. I would like to support RequireJS, and if there are some modifications we need to make to make that easier then let's do it.

We also are very interested in figuring out how to break up the templates/views/controllers to better support lazy-loading. RequireJS/AMD might be one way of accomplishing this, but also I think if we move to Browserify from Stitch, this will be easier. This is something we want to do anyway.

Specifically re: not expecting controllers to be present at app boot time, we can work around that. Feel free to share your sample code I can take it for a spin.

alexindigo commented 10 years ago

Cool. Thanx.

I'm going to have some ready to show later today.

alexindigo commented 10 years ago

This is first chunk of proposed changes – https://github.com/airbnb/rendr-handlebars/pull/5

Changes for Rendr are still in progress, but you can see the trend there.

spikebrehm commented 10 years ago

To echo my comment on that PR, it scares me to have to add this boilerplate to every file in the project. Rather, it would be more forward-thinking to just write ES6 modules and transpile to CommonJS & AMD.

For inspiration: https://github.com/wycats/handlebars.js/pull/628

alexindigo commented 10 years ago

This change allows to load Rendr in pieces using RequireJS.

alexindigo commented 10 years ago

And another one for rendr-handlebars – https://github.com/airbnb/rendr-handlebars/pull/7

alexindigo commented 10 years ago

Step 2: https://github.com/airbnb/rendr/pull/177