-
Notifications
You must be signed in to change notification settings - Fork 0
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
Simplifications #3
Conversation
index.js
Outdated
let obj = parseArgs(args) | ||
log[level](obj.message, obj); | ||
} | ||
const logger = Object.assign({},...Object.keys(log.levels).map(level => ({[level]: logByLevel(level)}))); |
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 we can use reduce insteal of Object.assign and map. something like
Object.keys(log.levels).reduce((acc, level) => acc[level] = logByLevel(level), {})
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.
Which one you like more?
const logger = Object.assign({},...Object.keys(log.levels).map(level => ({[level]: logByLevel(level)})));
const logger = Object.keys(log.levels).reduce((acc, val) => { acc[val] = logByLevel(val); return acc; },{});
I have the feeling that the second one is much clear.
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.
same here, the second 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.
Done ;)
index.js
Outdated
message:objToLog.message.concat(util.inspect(arg)), | ||
}) || isObject(arg) && Object.assign({}, objToLog, arg) || Object.assign({},objToLog,{ | ||
message:objToLog.message.concat(util.inspect(arg)), | ||
}); |
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 using many shorthand expressions here makes it a bit harder to read.
Also, I think it might be better if we change parseArgs to return { message, context } and don't initialize message inside objtoLog in the first place. something like in here f164f8d#diff-168726dbe96b3ce427e7fedce31bb0bcR29
@rubanour Applied ;) |
index.js
Outdated
}; | ||
const parseArgs = (args) => { | ||
const { messages, context } = args.reduce((acc, arg) => { | ||
return !arg && acc || addError(arg,acc) || addObject(arg,acc) || Object.assign({},acc,{messages:addMessage(arg,acc)}); |
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.
arg instead of !arg .. right?
we can remove the brackets and the return as well :D
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.
No, should be !arg
as if there is no argument we return the acc and only if we have an argument we execute the assignation chain.
Respect brackets...yes 😅 I'll do it.
669477c
to
0b3cde3
Compare
No description provided.