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

Fix Required Issue with Heterogenous Arrays #546

Merged
merged 4 commits into from
Aug 7, 2018

Conversation

sophypal
Copy link
Contributor

@sophypal sophypal commented Aug 4, 2018

#PATCH#

CHANGELOG

  • Fixed conditions inside arrays with required fields

@sophypal sophypal requested a review from a team as a code owner August 4, 2018 01:27
@sophypal sophypal changed the title Fix Requires Issue with Heterogenous Arrays Fix Required Issue with Heterogenous Arrays Aug 4, 2018
quincyle
quincyle previously approved these changes Aug 7, 2018
} else if ('properties' in bunsenModel) {
bunsenModel = bunsenModel.properties[pathSegment]
} else {
return undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a condition doesn't seem to exist in the original code. Do we have a use case in bunsen that we would want this condition to be hit?

Copy link
Contributor Author

@sophypal sophypal Aug 7, 2018

Choose a reason for hiding this comment

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

I hit it. That's why I added it. If the path doesn't match the model, then this can happen.

type: 'object'
properties: {
  a: {type: 'string'}
}

Works when the path is a. Doesn't work when the model is a.b. The caller is looking for undefined to end the traversal loop and handling the condition here makes sure we don't end up in a situation where it tries to index into an undefined object.

addon/utils.js Outdated
@@ -390,6 +382,22 @@ export function getErrorMessage (error) {
}
/* eslint-enable complexity */

export function getSubModel (pathSegment, bunsenModel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have some simple JSdoc for the future code reader?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does JSDoc really help though? I purposely deleted some JSDoc from bunsen-core because I realized that not once did I look at them nor did I find them descriptive enough to warrant their usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I can add it if you find it useful. It maybe be just me that don't find it useful and find it easier to follow code. Just note that in the near future, I plan to refactor all so we can centralize all the different flavors of model traversals.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I was just about to ask the question why did you remove some JSDoc in bunsen-core. I think they still provide some value to developers like me that are not very familiar with the code base and make a complex project less scared.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps. I thought this in the past. I do value JSDoc for documenting types still but most often I find this kind of JSDoc,

Gets the sub model
@param {Object} input - the input object
getSubModel (input)

How is that useful? Also when getSubModel starts getting more complex, the JSDoc is often left out of maintenance. So you find yourself reading the past instead of the present. There was a study that was done that found that comments lead to more bugs. This conclusion was that developers would read through the comments instead of relying on reading what the code did.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I'm going to put some JSDoc in here if only to document the types properly. I still think the comments for this small function will serve little value (not I didn't say no value). The larger confusion new developers will have is not necessarily understanding what this function explicit does but how it functions in the larger scheme of things.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's true. When I read through the comments/docs, I did assume that they're correct and up to date. In this case, I agree in this case it's not proving too much value except types.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a specific JSDoc that I think it shouldn't be removed in bunsen-core.
https://github.com/ciena-blueplanet/bunsen-core/pull/135/files#diff-30699e11bc5c44658541e1afec32d6f5L3
This one does provide some conceptual idea of what does this function do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That whole section is hard to read honestly. I'd have to agree that comments did make it more approachable but if I was the one reviewing it I'd actually force the developer to make the code cleaner. Not all comments are bad but I'd rather document that kind of thing in an architecture document somewhere. The condition logic exist in multiple places so instead of copy/paste on that kind of architectural information, it would be better documented elsewhere outside of the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you're right. We probably should add something like How condition works section in the general doc instead of copy/paste it over and over onto every conditional related util function. Anyway, since it's not related to this project anymore, I'm going to merge the PR after the build passes and we can move the discussion to somewhere else if needed.

sdesros
sdesros previously approved these changes Aug 7, 2018
@sophypal sophypal dismissed stale reviews from sdesros and quincyle via 2855a0b August 7, 2018 18:38
quincyle
quincyle previously approved these changes Aug 7, 2018
addon/utils.js Outdated
* Gets the sub model associated with the path segment
* @param {String} pathSegment - path of the segment (must be direct descendant)
* @param {Object} bunsenModel - starting bunsen model
* @returns {Object} the submodel or undefined if it doesn't exist
Copy link

@lirwin lirwin Aug 7, 2018

Choose a reason for hiding this comment

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

{Object|undefined}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lirwin Glad to see you here.

@quincyle quincyle merged commit 5d83f58 into ciena-frost:master Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants