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 controller lazy load. #177

Closed
wants to merge 6 commits into from
Closed

Conversation

alexindigo
Copy link
Member

Spike,

This is step 2 towards RequireJS support.
For now I require views and compiled templates from within controllers,
but it's in my plans to make view/template async load part of Rendr too.
(Again aiming for minimal changes to Rendr).

/сс @jskulski @bigethan @c089

{
require([action], function(controller)
{
// check we have everythign we need
Copy link
Member

Choose a reason for hiding this comment

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

Little typo here

Copy link
Member Author

Choose a reason for hiding this comment

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

Not anymore :)

}
else
{
action.call(router, params, router.getRenderCallback(route));
Copy link
Member

Choose a reason for hiding this comment

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

There's some duplication here that would be nice to DRY up. Could add a function that calls the action.

function callAction(action) {
  if (!action) {
    throw new Error("Missing action \"" + route.action + "\" for controller \"" + route.controller + "\"");
  }
  action.call(router, params, router.getRenderCallback(route));
}

then use it in both code paths like:

callAction(action);

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want to have extra function expression within action handler, it might be not a big deal on the client,
but on the server it will cause unnecessary slow down.

So it's a little bit wet.

actionCall(action, params);

@spikebrehm
Copy link
Member

Interesting. Seems reasonable but again it would be really nice to have a little example app so we can play around with the changes before committing blindly.

@alexindigo
Copy link
Member Author

For now to make our app run it requires manual hacks and adjustments, since not all pieces are in place (i.e. RequireJS bug, pathAdapter for Rendr, views/templates loaded within controller) – I'm not if demo like that would be helpful or just confuse other parties. (When all that is done, I'm going to submit PR with requirejs demo).

@c089 was going to provide their browser test scripts where we can see how it performs with both Stitch and RequireJS.

But if you're worried that we're going the right direction, I'll setup playground where you can see our changes in action.

// check we have everything we need
if (typeof controller[route.action] != 'function')
{
throw new Error("Missing action \"" + route.action + "\" for controller \"" + route.controller + "\"");
Copy link
Member

Choose a reason for hiding this comment

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

the err msg code is duplicated from above

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but it's just error message.

Copy link
Member

Choose a reason for hiding this comment

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

It's still duplication and really trivial to avoid using the extract method refactoring.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, but then it asks for the error handling subsystem, which is probably welcome change, but not in this PR.

@c089
Copy link
Member

c089 commented Nov 8, 2013

To be honest I'm not too much of a fan of this. Seems like this will change things all over the place, mixing concerns, in this case routing and AMD support and making the code much harder to understand. I don't know enough about the different module systems to provide a better solution though.

@c089
Copy link
Member

c089 commented Nov 8, 2013

Quick thought: Could we maybe solve this in a different way altogether if we had a new design of the routing? I think i might have have to change substantially anyway to solve issues with express vs. backbone router with the goal being to implement a new isomorphic routing module...

@alexindigo
Copy link
Member Author

I'm ok with anything that allows async controller load. Do you have example of the new routing system?

@alexindigo
Copy link
Member Author

@spikebrehm Here is demo app (05_requirejs), it's still has bunch of hacks/workaround, since not all the planned changes been coded/landed into Rendr.

But I hope it will give better understand on what we're trying to do.

PS. It works in non-minified mode, idea to have separate grunt task that will minify/combine certain modules and lazy load other, similar to how libs.js is combination of all third-party libs/modules.

If you have more question, let's talk in IRC.

Thank you.

@alexindigo
Copy link
Member Author

@spikebrehm Have you had a chance to look at the new changes?
And I have final changes in the pipe line, that allow demo app run with no hacks.

Thank you.

@alexindigo alexindigo closed this Nov 19, 2013
@spikebrehm
Copy link
Member

@alexindigo sorry I haven't had a chance to look; heads down trying to get a product out by the end of the week. I'll try to take a peek but my SLA will be poor.

@alexindigo
Copy link
Member Author

There is new PR with latest changes to Rendr and demo app – #190
Thank you.

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