-
Notifications
You must be signed in to change notification settings - Fork 761
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
Native functions #2309
Native functions #2309
Conversation
src/execute/index.js
Outdated
@@ -76,7 +75,14 @@ export function execute({ | |||
...extras, | |||
}); | |||
|
|||
if (request.body && (isPlainObject(request.body) || Array.isArray(request.body))) { |
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.
Comparing this change with original, I'd say we'll stick with isPlainObject
for the time being. Determining if something is POJO is a hard job, and having a well tested utility function that abstract the complexity just make sense.
I think we have two options with isPlainObject
1.) remove the isPlainObject
from the list and keep using lodash version
2.) create our own utility function that does exactly the same thing as isPlainObject
from lodash
The scope of #2187 (as I understood it) is to replace lodash functions with modern & native simple javascript constructs. IMHO this doesn't fall within that scope.
// cc @jimmywarting
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.
What @char0n have mention about isPlainObject
not being equivalent to just a simple typeof
is true... need to check more things such as function, null etc
in some senarios it's fine to use just typeof x === object
but we need to know for sure if it's okey to use it.
the point of my issue is not to use any lodash at all, even if you just include one simple function then lodash will at least load some internal core functions that are pretty big in itself and is deeply dependent on many other stuff to make it compatible with es3 or 5 (whatever it is).
Right now there is so few lodash fn that we use that i don't see any point in keeping it, so i suggest # 2
create our own utility function that does the same thing
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.
where can i create function isPlainObject? In which project folder?
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.
@gabrielsimongianotti src/helpers.js
contains already two helper functions at the top of the file. Le'ts put isPlainObject
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.
Another options is to use https://www.npmjs.com/package/is-plain-object
Contains the logic that we need and handles corner cases. Has no dependencies as well.
If there are no strong objections to this proposal let's consider this package as a replacement for lodash.isPlainObject
src/helpers.js
Outdated
@@ -136,7 +134,7 @@ export function normalizeSwagger(parsedSpec) { | |||
for (const pathName in paths) { | |||
const path = paths[pathName]; | |||
|
|||
if (!isObject(path)) { | |||
if (typeof path !== 'object') { |
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.
isObject
cannot be simply replaced with typeof path === 'object'
; this is not functionally equivalent.
The source code of isObject
is as follows:
function isObject(value) {
var type = typeof value;
return value != null && (type == 'object' || type == 'function');
}
Which means that anything that reports typeof object
|| function
except null
and undefined
.
src/helpers.js
Outdated
@@ -136,7 +134,7 @@ export function normalizeSwagger(parsedSpec) { | |||
for (const pathName in paths) { | |||
const path = paths[pathName]; | |||
|
|||
if (!isObject(path)) { | |||
if (typeof path !== 'object') { |
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.
if (typeof path !== 'object') { | |
if (path == null || !['object', 'function'].includes(typeof path)) { |
src/helpers.js
Outdated
@@ -145,7 +143,7 @@ export function normalizeSwagger(parsedSpec) { | |||
// eslint-disable-next-line no-restricted-syntax, guard-for-in | |||
for (const method in path) { | |||
const operation = path[method]; | |||
if (!isObject(operation)) { | |||
if (typeof path !== 'object') { |
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.
if (typeof path !== 'object') { | |
if (path == null || !['object', 'function'].includes(typeof path)) { |
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.
Thanks for contributing! I've added couple of code review comments. Please have a look at them.
Made one change, but the PR is missing changes in |
thank you to remember 😅 |
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.
As we've introduced new library, we need the package-lock.json
file change in this PR as well.
I maked merge in 'upstream/master' , is something missing? you can make approve? |
You need to run following command in repo fork: $ npm i --save is-plain-object This will modify two files: More info about package-lock files here: https://docs.npmjs.com/cli/v7/configuring-npm/package-lock-json |
sorry i don't speak english very well, now i understand what you were trying to say |
I've made some final changes to the PR, regarding package-lock.json file. We're using |
Merging and thanks for contributing! |
🎉 This PR is included in version 3.18.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
i make two alters of #2187 (comment), removed lodash/isPlainObject, lodash/isObject and replace per native function
How Has This Been Tested?
I used your tests
Types of changes
Checklist: