Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions shared/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ var Backbone = require('backbone'),
Fetcher = require('./fetcher'),
ModelUtils = require('./modelUtils'),
isServer = (typeof window === 'undefined'),
ClientRouter;
defaultRouterModule = 'app/router';

if (!isServer) {
ClientRouter = require('app/router');
Backbone.$ = window.$ || require('jquery');
}

Expand Down Expand Up @@ -56,8 +55,12 @@ module.exports = Backbone.Model.extend({
* We can't use `this.get('templateAdapter')` here because `Backbone.Model`'s
* constructor has not yet been called.
*/
var templateAdapterModule = attributes.templateAdapter || this.defaults.templateAdapter;
this.templateAdapter = require(templateAdapterModule)({entryPath: entryPath});
if (this.options.templateAdapterInstance) {
this.templateAdapter = options.templateAdapterInstance;
} else {
var templateAdapterModule = attributes.templateAdapter || this.defaults.templateAdapter;
this.templateAdapter = require(templateAdapterModule)({entryPath: entryPath});
}

/**
* Instantiate the `Fetcher`, which is used on client and server.
Expand All @@ -70,6 +73,8 @@ module.exports = Backbone.Model.extend({
* Initialize the `ClientRouter` on the client-side.
*/
if (!isServer) {
var ClientRouter = this.options.ClientRouter || require(defaultRouterModule);
Copy link
Member

Choose a reason for hiding this comment

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

require in the browser? Looks like something very specific to browserify.

Copy link
Contributor

Choose a reason for hiding this comment

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

it was already doing this on line 13? not sure how it's terribly different from the original functionality there. (Totally agree with you though.. 😞 )

Any suggestions to fix it up? my only thought is this.modelUtils._requireAMD(defaultRouterModule) instead.

@alexindigo #454

Copy link
Member

Choose a reason for hiding this comment

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

Before it had "hardcoded" default router path, so r.js was able to augment it and with this change it makes it invisible for r.js.

Copy link
Member

Choose a reason for hiding this comment

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

Btw, looks like assign path to a variable is not essential to this change. So we might revert that particular line to the previous state. While we're thinking on better implementation.

In general IoC should make things better, but here it went sideways :)

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, balls. sorry about that guys. is the requirejs example updated so i can use it as a test bed for this stuff?

Copy link
Contributor

Choose a reason for hiding this comment

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

@saponifi3d we have this PR rendrjs/rendr-examples#15 to make it work with Rendr 1.0.1

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, that doesn't seem to fix it for me, i'm getting an error on this line https://github.com/rendrjs/rendr/blob/master/shared/base/router.js#L184 - it looks like realAction is a string not the action that is expected.

In the meantime i'm going to revert the commit that caused the breakage and push out 1.0.4 (i think it's that version?) so it's in a working state for everyone.

Copy link
Contributor

Choose a reason for hiding this comment

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

@saponifi3d just tested the sample app (05_requirejs) and it seem to be working with the latest version of Rendr 1.0.2 but we still see the require issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I haven't merged / released those changes yet for the require. I just did a fresh install and tried the example with 1.0.1 and it didn't work. Its breaking on the real action of the controller on a client-side route. Until there's a working exple there it will be hard for me to make a proper fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

The example doesn't work with 1.0.1 because we need changes from those two PR:
#448
#450


new ClientRouter({
app: this,
entryPath: entryPath,
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/app/template_adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function (options) {
return {
name: 'Test template adapter',
suppliedOptions: options
};
}
37 changes: 37 additions & 0 deletions test/shared/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,41 @@ describe('BaseApp', function() {
new MyApp();
});
});

describe('constructor', function() {
context('with a custom templateAdapter module name', function() {
beforeEach(function () {
this.attributes = {templateAdapter: '../test/fixtures/app/template_adapter'};
});

it('creates the templateAdapter we specify', function() {
var app = new App(this.attributes);

expect(app.templateAdapter).to.have.property('name', 'Test template adapter');
});

it('supplies the entryPath to the template adapter', function() {
var app = new App(this.attributes, {entryPath: 'myEntryPath'});

expect(app.templateAdapter).to.have.deep.property('suppliedOptions.entryPath', 'myEntryPath');
});
});

context('with a concrete templateAdapterInstance', function() {
it('uses the supplied templateAdapterInstance', function() {
var myTemplateAdapter = {};
var app = new App(null, {templateAdapterInstance: myTemplateAdapter});

expect(app.templateAdapter).to.equal(myTemplateAdapter);
});

it('does not try to require a template adapter by name', function () {
new App({
templateAdapter: 'non existent module name - should throw'
}, {
templateAdapterInstance: {}
});
});
});
});
});