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

[GPT-565] Dynamic support to oc-templates in oc dev #426

Merged
merged 10 commits into from
Apr 5, 2017
Merged

Conversation

nickbalestra
Copy link
Contributor

No description provided.

throw format(templateNotSupported, type);
module.exports = function(template) {
var localTemplate = path.join(__dirname, '../../', 'node_modules', template);
if (fs.existsSync(localTemplate)) {
Copy link
Member

Choose a reason for hiding this comment

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

we can't use sync functions in the client. I think the only way to not make all of this async is to bring each require inside own try catch. In the catch, also, you may need to invalidate the require cache. Very similar to what we do here https://github.com/opentable/oc/blob/master/src/cli/domain/get-missing-deps.js#L22


_.forEach(_.keys(pkg.dependencies), function(d){
if (!deps.templates[type] && !legacyTemplates[type]) {
Copy link
Member

Choose a reason for hiding this comment

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

I think

var legacyTemplates = ['jade', 'handlebars']
...
if (!deps.templates[type] && !_.includes(legacyTemplates, type)) {

would be a bit more readable?

Copy link
Contributor Author

@nickbalestra nickbalestra Mar 31, 2017

Choose a reason for hiding this comment

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

very nit and very arguable weather an array of 2 elements is more readable then an object with 2 keys.. I've removed the usage of _.include when reformatting this, we were doing way too many useless array loops, so, my rationale is: quicklookups ftw

Copy link
Member

Choose a reason for hiding this comment

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

That's why I put it as question. I don't have strong opinions on this. Let's leave it as is if you like.

throw format(templateNotSupported, type);
module.exports = function(template) {
var localTemplate = path.join(__dirname, '../../', 'node_modules', template);
if (fs.existsSync(localTemplate)) {
Copy link
Member

Choose a reason for hiding this comment

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

same as before. Can't use blocking code in the registry

// }

// throw format(templateNotSupported, template);
Copy link
Member

@matteofigus matteofigus Mar 31, 2017

Choose a reason for hiding this comment

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

forgot to remove these lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😅

@nickbalestra
Copy link
Contributor Author

@matteofigus should be ok, let me know if you see anything else that need moar 💅


_.forEach(_.keys(pkg.dependencies), function(d){
if (!deps.templates[type] && !legacyTemplates[type]) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add check that if templatetype is not legacy must be declared as dependency

Copy link
Member

@matteofigus matteofigus left a comment

Choose a reason for hiding this comment

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

Also,

  1. on the client, let's ensure that when we call require-template (which can throw) that is wrapped in a try/catch so in case we return a callback with an error: https://github.com/opentable/oc/blob/ff87386f8331b1c257381177f11dd434b300d10c/client/src/template-renderer.js#L16

  2. same here: https://github.com/opentable/oc/blob/ff87386f8331b1c257381177f11dd434b300d10c/client/src/get-compiled-template.js

info = require(template).getInfo();
} catch (err) {
throw new Error(format(strings.errors.registry.TEMPLATE_NOT_FOUND, template));
}
Copy link
Member

Choose a reason for hiding this comment

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

Let's re-add a try catch here for a template that, in case is not valid, may throw as getInfo doesn't exist or is not a function. Error wouldn't be "template not found" anymore but more of a "template not valid" kind?

Copy link
Member

@matteofigus matteofigus left a comment

Choose a reason for hiding this comment

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

I think code-wise all looks good. Can we now add some tests? I'm mostly thinking about unit here?

@@ -1,12 +1,56 @@
'use strict';

var format = require('stringformat');
var templateNotSupported = 'Error loading component: template "{0}" not supported';
var path = require('path');
var _ = require('underscore');
Copy link
Member

Choose a reason for hiding this comment

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

we don't have underscore in the client! Made the same mistake when reviewing the previous PR with @mattiaerre and then realised - are you able to go vanilla with client's code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, actually I like it even more without it.

@matteofigus matteofigus merged commit 258b0d1 into master Apr 5, 2017
@matteofigus matteofigus deleted the gpt-565 branch April 5, 2017 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants