Skip to content
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

Made Rendr work with requirejs #190

Merged
merged 30 commits into from
Dec 11, 2013
Merged

Made Rendr work with requirejs #190

merged 30 commits into from
Dec 11, 2013

Conversation

alexindigo
Copy link
Member

@spikebrehm This PR adds RequireJs support to Rendr and example app 05_requirejs that contains grunt file and modified app files.
In order to make it run, you need to augment Rendr files to work on frontend by running grunt init (as you suggested no extra boilerplate in original Rendr files on the server).
When it's done you can continue as usual with grunt server.
This example works with unminified/uncombined app/rendr files as a proof of the concept (and probably dev env workflow), for the production files can be minified combined into one or few different files using grunt + r.js minification tool.

Please let me know if you have any questions/concerns. Thank you.

/cc @bigethan @jskulski

@@ -7,5 +7,9 @@ examples/*/node_modules
examples/**/compiledTemplates.js
examples/*/public/mergedAssets.js
examples/*/public/styles.css
examples/*/public/mergedAssets.js
Copy link
Member

Choose a reason for hiding this comment

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

This line is duped from above

@@ -0,0 +1,20 @@
require(
Copy link
Member

Choose a reason for hiding this comment

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

should this file be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

we need to preload globals before everything and routes too,
handlebars require in the compliledTemplates.

@spikebrehm
Copy link
Member

In general I really like the approach. It's good to make more of these methods async (BaseView, Fetcher). Like I said, I don't have the chance to spin through it right now locally because of a deadline but LMK if I'm blocking you on anything.

One note: it would be awesome if these changes could conform to the existing style of the codebase. We try to follow the style guide published here: https://github.com/airbnb/javascript. Mainly i'm thinking of having curly braces on the same line rather than on its own line (PHP-style).

Good:

if (foo) {
  bar();
} else {
  baz(function() {
    console.log('baz');
  });
}

Bad:

if (foo)
{
  bar();
}
else
{
  baz(function()
  {
    console.log('baz');
  });
}

@alexindigo
Copy link
Member Author

Sure, I fix styling. It's just helps me to read code, usually I go and clean up after, but when it's middle of the night, I might miss some chunks. :)

For I'm focusing on other stuff too,
but it would be nice to take it out of limbo one way or another
and sooner the better.

Let me know what I can do to speed things up.

Thank you.

keeping it by default, but adding ways to disable it.
Useful for Oauth, which doesn't like JSON requests.

PS. We need it now, but I'll clean it up and make as separate PR, when we will be merging RequireJS one.
{
// TODO: Make it function (err, View)
if (!_.isFunction(View)) {
throw new Error("View '" + key + "' not found.");
Copy link
Member

Choose a reason for hiding this comment

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

Probably should pass this error as first arg to callback rather than throwing.

@spikebrehm
Copy link
Member

I'm having some trouble running 05_requirejs example locally. Getting this error in js console:

GET http://localhost:5000/js/libs.js 404 (Not Found) 

and indeed, public/js doesn't have it:

$ ls public/js/
total 8
drwxr-xr-x  3 spike  staff   102B Nov 27 12:26 app
-rw-r--r--  1 spike  staff   336B Nov 27 12:01 app.js

@spikebrehm
Copy link
Member

Cool. Looks good. There's some cleanup we can do, but let's just get this merged and move forward from there! Thanks a lot @alexindigo @jskulski @bigethan for all your help.

Would you like to try squashing these commits first? If not, not a blocker.

@alexindigo
Copy link
Member Author

Sure, thank you for your support.

spikebrehm pushed a commit that referenced this pull request Dec 11, 2013
Made Rendr work with requirejs
@spikebrehm spikebrehm merged commit ebe734c into rendrjs:master Dec 11, 2013
@alexindigo
Copy link
Member Author

Oh... I just squished everything together :) Too slow. #fail :)

@spikebrehm
Copy link
Member

Lol, sorry! I was too eager!

@alexindigo
Copy link
Member Author

It's actually good. Keeps me on my toes :) You know – survival of the fittest :)
Thanx one more time. :) It was awesome ride. :)

@spikebrehm
Copy link
Member

Ah shoot, ran into an error with grunt init. Should have tried earlier:

Running "rendr_requirejs:init_shared" (rendr_requirejs) task

Tracing dependencies for: rendr/shared/app
Error: ENOENT, no such file or directory '/Users/spike/code/rendr/examples/05_requirejs/public/js/rendr/shared/rendr/shared/rendr/client/app_view.js'
In module tree:
    rendr/shared/app

{ [Error: Error: ENOENT, no such file or directory '/Users/spike/code/rendr/examples/05_requirejs/public/js/rendr/shared/rendr/shared/rendr/client/app_view.js'
In module tree:
    rendr/shared/app

    at Object.fs.openSync (fs.js:427:18)
]
  originalError:
   { [Error: ENOENT, no such file or directory '/Users/spike/code/rendr/examples/05_requirejs/public/js/rendr/shared/rendr/shared/rendr/client/app_view.js']
     errno: 34,
     code: 'ENOENT',
     path: '/Users/spike/code/rendr/examples/05_requirejs/public/js/rendr/shared/rendr/shared/rendr/client/app_view.js',
     syscall: 'open',
     fileName: '/Users/spike/code/rendr/examples/05_requirejs/public/js/rendr/shared/rendr/shared/rendr/client/app_view.js',
     moduleTree: [ 'rendr/shared/app' ] } }

@spikebrehm
Copy link
Member

The path is weird for the command: /public/js/rendr/shared/rendr/shared/rendr/

@alexindigo
Copy link
Member Author

yes, it's a bug in requires (they said it's not, but rather feature) I'm yet to add workaround for that, I mean I have workaround there as part of grunt options, but going to add into requirejs itself.

Can you show me your grunt options file or is it the one from 05_requirejs?

@spikebrehm
Copy link
Member

It's straight from master.

@alexindigo
Copy link
Member Author

Hmm, one sec then.

@muhleder
Copy link

I ran into this just today. You need to add
'rendr/client': '../../../client',
to the paths for init_shared in the Gruntfile.

@muhleder
Copy link

It comes from getAppViewClass() referencing the client libs in rendr/shared/app.js

@alexindigo
Copy link
Member Author

I think I added it. And I had to remove and recheckout my example/05 to reproduce it (lack of smoke tests).
Thanx :)

@alexindigo alexindigo mentioned this pull request Dec 11, 2013
@alexindigo
Copy link
Member Author

Oh and tests, seems like I forgot something somewhere. Sorry.

@spikebrehm
Copy link
Member

Thanks a lot @muhleder! That does it. Fixed in 34d2563.

There may be some other things we need to fix due to divergence from master during this PR's long incubation period. For example, I see a reference to rendr.entryPath in users_controller.js:

https://github.com/airbnb/rendr/blob/master/examples/05_requirejs/app/controllers/users_controller.js#L55

We've since deprecated rendr.entryPath. I also wonder what workarounds are still left here that we can clean up.

@spikebrehm
Copy link
Member

You know, actually, I think i might just remove the show_lazy action from all the examples, to slim them down, and I'll create a separate example to demonstrate lazy loading of models.

@alexindigo
Copy link
Member Author

I'll port changes from example/00. (Feels like we're talking about Evangelion) :)

@alexindigo
Copy link
Member Author

I think it's good to have more features to showcase in requires version, or maybe to have two examples, very simple one and something more sophisticated.

@alexindigo
Copy link
Member Author

How about you'd update 00 – 04 the way you think would be more example-friendly and then I'll port `00`` and something else to requirejs.

@spikebrehm
Copy link
Member

Deal, sounds good.

@spikebrehm
Copy link
Member

@alexindigo any plans to release grunt-rendr-requirejs as an NPM module?

@alexindigo
Copy link
Member Author

Yes, I wanted incorporate that workaround into it, but probably better "ship it early fix it later". :)
Will do.

@alexindigo
Copy link
Member Author

Done. https://npmjs.org/package/grunt-rendr-requirejs
(Still work in progress though)

@spikebrehm
Copy link
Member

Cool! It's a start. Added to 05_requirejs's package.json here: ec6632f

@alexindigo
Copy link
Member Author

Thanx. Btw, there is PR for grunt-rendr-stitch, tests were failing. Or stitch is thing of the past now?

@alexindigo
Copy link
Member Author

Oh and rendr-handlerbars, looks like it's missing recent changes from the npm package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants