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

objectSpec sub-spec on arrays fix; themeSpec fix #11133

Conversation

nucleogenesis
Copy link
Member

Summary

The objectSpec utility was not properly validating an Array-type spec's items against the given spec, this ensures that the spec is tested against all child items when given.

The themeSpec had an Array-type property with a default that was not a function as it ought to be, this is fixed.

This eliminates the benign but annoying console errors about the above.

Reviewer guidance

Start the server, go to Kolibri, you should not see objectSpec errors in the devtools console.

Copy link
Member

@bjester bjester left a comment

Choose a reason for hiding this comment

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

LGTM-- only some thoughts about simplifying the logic a bit

}
}
}
if (isObject(data) && !isArray(data) && !validateObject(data, options.spec)) {
Copy link
Member

Choose a reason for hiding this comment

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

There are some unreachable conditions here, considering the first if ensuring data is only an object or an array. Making this an else if would remove !isArray(data), but also, would isObject and isArray ever be true at the same time?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's because isObject is super general and comes back true for an Array (and functions) - so isObject && !isArray needs the !isArray check there because above that bit I'm checking for isArray and handling it when true but don't return so the last step is saying "this is an object that isn't an array" -- which probably should also check "is also not a function".

Although - now that I look at it again, it'd probably be simpler to just return after succeeding within the block where isArray is true and passes validation. Will push an update

Copy link
Member

Choose a reason for hiding this comment

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

Since this is just for the object spec, perhaps isPlainObject is better? https://lodash.com/docs/4.17.15#isPlainObject

Copy link
Member Author

Choose a reason for hiding this comment

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

Bah - nevermind I misread the GH diff - it can't return early.

I added a comment to clarify a bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Awesome thanks for that - all uses of isObject were really trying to ask isPlainObject so I replaced them throughout.

@nucleogenesis nucleogenesis merged commit 429fec8 into learningequality:release-v0.16.x Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants