Skip to content

Commit

Permalink
Don't override template if already set
Browse files Browse the repository at this point in the history
  • Loading branch information
taylortom committed Sep 17, 2015
1 parent eb5033c commit a7af2e3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/js/adapt.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ define(function(require){
// Store the component view
if (Adapt.componentStore[name])
throw Error('This component already exists in your project');
object.template = name;
if(!object.template) object.template = name;
Adapt.componentStore[name] = object;

}
Expand Down

11 comments on commit a7af2e3

@LukaszGrela
Copy link
Contributor

Choose a reason for hiding this comment

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

it has a bug as the object can have inherited template property, test with GMCQ for instance, it will have mcq already.

@andrewhosgood
Copy link
Contributor

Choose a reason for hiding this comment

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

Tried making a PR myself to the Grunt Handlebars module: gruntjs/grunt-contrib-handlebars#147

@LukaszGrela
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this would be better option:
if(!object.template || object.template != name)

@oliverfoster
Copy link
Member

Choose a reason for hiding this comment

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

The intention of this code is to stop object.template == name as default if a template is specified.
The better solution is to add "template": "gmcq" to the gmcq definition.

@himanshu1618
Copy link
Contributor

Choose a reason for hiding this comment

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

@oliverfoster
Copy link
Member

Choose a reason for hiding this comment

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

thanks @hrajotia

@LukaszGrela
Copy link
Contributor

Choose a reason for hiding this comment

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

My point is that the intention breaks course with the GMCQ, the fix would be not simply check if the property exist but also compare the content of the property.

@hrajotia it is good solution as well but this also needs to be added to any other components that extends others, my change is single point one fix

@oliverfoster
Copy link
Member

Choose a reason for hiding this comment

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

please apply the fix himanshu has listed above ^ it's not in master yet but is in the develop of gmcq.

@oliverfoster
Copy link
Member

Choose a reason for hiding this comment

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

the component register function is the only place in adapt where templates do not need to be explicitly declared and it's really bad for clarity. all other plugins define their templates and realistically, the components should too. giving more power to the register function is not really the direction we should be heading in, although it does indeed solve a temporary issue.

@oliverfoster
Copy link
Member

Choose a reason for hiding this comment

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

i would prefer line 83 to go missing entirely.

@taylortom
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 submitted this change so that register would play a bit nicer with extensions that inherited from other extensions. Previously, you were forced to create a template for every extension, rather than use an existing template, and just extend the functionality.

I agree with @oliverfoster about removing the line altogether.

Please sign in to comment.