-
Notifications
You must be signed in to change notification settings - Fork 140
Update Tailor using ES6 features(fixes #102) #109
Update Tailor using ES6 features(fixes #102) #109
Conversation
…into update-es6-features
@@ -1,8 +1,7 @@ | |||
sudo: false | |||
language: node_js | |||
node_js: | |||
- '4.4.4' | |||
- '6.0.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep 6 as well.. We shall drop 4 dependency alone.
|
||
const stripUrl = fileUrl => path.normalize(fileUrl.replace('file://', '')); | ||
const getPipeAttributes = attributes => { | ||
const { primary, id} = attributes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after id for consistency.
fs.readFile(path, 'utf-8', (err, data) => { | ||
if (err) { | ||
reject(new TemplateError(err)); | ||
return; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else not needed here..
module.exports = function fetchTemplate (templatesPath, baseTemplateFn) { | ||
return (request, parseTemplate) => { | ||
module.exports = (templatesPath, baseTemplateFn) => | ||
(request, parseTemplate) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would keep the consistency of keeping parenthesis everywhere.. keeping some function without parenthesis and others with it doesn't look good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am keeping parenthesis only when returning object. Since , this function returns a promise there is no need of keeping it. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keeping parentheses for args looks better to me and make you feel its a function.. Its just my thoughts though... If we keep it here,I would also keep it in all arrow functions to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
const attribs = node.attribs; | ||
return node.name === 'script' && | ||
attribs && attribs.type === 'slot'; | ||
const { attribs, name} = node; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if eslint rule for this exist but would be cool to add this rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vigneshshanmugam We can use http://eslint.org/docs/rules/object-curly-spacing for this but the problem is the existing code is not consistent for any of the never
or always
rules. It throws 58 and 60 errors respectively with never
and always
rules. Which one do you think should be used across? I am planning to add this and make it consistent
@@ -24,7 +24,7 @@ | |||
"test" | |||
], | |||
"engines": { | |||
"node": ">4.4.3" | |||
"node": ">7.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6.0.0
const slotNodes = slotMap.get(slot) || []; | ||
const updatedSlotNodes = [...slotNodes, node]; | ||
slotMap.set(slot, updatedSlotNodes); | ||
this._pushText(node.next, updatedSlotNodes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont think this works though. updatedSlotNodes
doesnt have reference to the slotMap and would not update the text nodes.. I think it should be slotMap.get(slot)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think updatedSlotNodes
contains the result of line 59-63 which is what is getting used as second parameter of this._pushText
. So,
[...slotNodes, node] ≈ (slotMap.get(attribs.slot).push(node); || slotMap.set(attribs.slot, [node]);)
This is just our understanding of the syntax and seems same in functionality. But, you can confirm if the functionality is broken or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am 99% sure its broken, I will confirm you anyways :) I may be wrong as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wrong.. Its working as expected.. sorry for that! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. I was hoping to not have to change this :) @diogodadalt You were right on this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vigneshshanmugam @Addi90 thanks for taking the time to review it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diogodadalt No issues man.. I just came to know there should be a test for this as well.. Will add it after this PR has landed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added f91bcff
@Addi90 Huge thanks for the PR :) |
/cc @grassator @dazld Thoughts? |
path.join(process.cwd(), 'templates') | ||
), | ||
fragmentTag: 'fragment', | ||
handledTags: [], | ||
handleTag: () => '', | ||
requestFragment, | ||
pipeDefinition: (pipeInstanceName) => pipeChunk(amdLoaderUrl, pipeInstanceName), | ||
pipeDefinition: pipeInstanceName => pipeChunk(amdLoaderUrl, pipeInstanceName), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about pipeChunk.bind(null, amdLoaderUrl)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. We can curry a new function since pipeInstanceName
is anyway the second param
@@ -19,8 +19,8 @@ const requiredHeaders = { | |||
* @param {Object} request - HTTP request stream | |||
* @returns {Promise} Response from the fragment server | |||
*/ | |||
module.exports = function requestFragment (fragmentUrl, fragmentAttributes, request) { | |||
return new Promise((resolve, reject) => { | |||
module.exports = (fragmentUrl, fragmentAttributes, request) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think this should probably stay as a named function for stack traces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch @dazld
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dazld But wouldn't the stack trace use the name from the name of the import. E.g.:
const requestFragment = require('./lib/request-fragment');
I may be wrong but based on my understanding, with any error, the stack trace would use the name of the import i.e. requestFragment
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can test it out by throwing error manually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Irrespective of the syntax of the function, if its the default
module function the error thrown is the same for me and defined by the file and line number. E.g. on throwing error in request-fragment.js
, the below error is thrown with both the syntaxes:
if (response.statusCode >= 500) {
reject(new Error('Internal Server Error'));
} else {
throw new Error('test the stack trace');
resolve(response);
}
Uncaught Error: test the stack trace
at OverriddenClientRequest.fragmentRequest.on (lib/request-fragment.js:43:23)
at respond (node_modules/nock/lib/request_overrider.js:441:17)
at node_modules/nock/lib/request_overrider.js:479:11
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright then 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed the other comment from @dazld and pushed. Check if it makes sense to merge it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome 👍
Current coverage is 91.26% (diff: 90.54%)
|
() => {}
and remove verbose code, wherever applicable.includes()
, wherever applicablenode-7.x