Skip to content

Commit

Permalink
Merge pull request #428 from opentable/registerTemplaeFixes
Browse files Browse the repository at this point in the history
registerTemplate API fix
  • Loading branch information
matteofigus authored Apr 4, 2017
2 parents 225db00 + 3360c1d commit a79eb48
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/components/oc-client/src/oc-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var oc = oc || {};
}
};

var coreTemplates = {
var registeredTemplates = {
'oc-template-handlebars': {
externals: [
{ global: 'Handlebars', url: 'https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.6/handlebars.runtime.min.js' }
Expand All @@ -82,7 +82,21 @@ var oc = oc || {};
]
}
};
var registeredTemplates = oc.conf.templates ? oc.registerTemplates(oc.conf.templates) : coreTemplates;

function registerTemplates(templates) {
templates = Array.isArray(templates) ? templates : [templates];
templates.forEach(function(template){
if (!registeredTemplates[template.type]) {
registeredTemplates[template.type] = {
externals: template.externals
};
}
});
}

if (oc.conf.templates) {
registerTemplates(oc.conf.templates);
}

var retry = function(component, cb, failedRetryCb){
if(retries[component] === undefined){
Expand Down Expand Up @@ -113,16 +127,9 @@ var oc = oc || {};
};

oc.registerTemplates = function (templates) {
templates = Array.isArray(templates) ? templates : [templates];
templates.forEach(function(template){
if (!registeredTemplates[template.type]) {
registeredTemplates[template.type] = {
externals: template.externals
};
}
});
registerTemplates(templates);
oc.ready(oc.renderUnloadedComponents);
return templates;
return registeredTemplates;
};

// A minimal require.js-ish that uses head.js
Expand Down

0 comments on commit a79eb48

Please sign in to comment.