-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Addon-actions: Fix types and refactor #2438
Addon-actions: Fix types and refactor #2438
Conversation
…' into fix-types-and-refactor
Codecov Report
@@ Coverage Diff @@
## release/3.3 #2438 +/- ##
===============================================
+ Coverage 19.11% 19.51% +0.39%
===============================================
Files 355 386 +31
Lines 8259 8707 +448
Branches 901 959 +58
===============================================
+ Hits 1579 1699 +120
- Misses 6003 6263 +260
- Partials 677 745 +68
Continue to review full report at Codecov.
|
const { hasOwnProperty } = Object.prototype; | ||
|
||
export default function getPropertiesList(value) { | ||
const keys = Object.getOwnPropertyNames(value); |
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.
This includes non-enumerable props. I don't think they should be displayed. Just for ... in
should be enough
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 tried to get the same behavior as in the console for something like the Math object, which does show the non-enumerable properties, otherwise it would just be empty.
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.
console shows them in half-transparent style, to indicate that they're somewhat secondary. And it logs __proto__
among them.
And I can't actually imagine someone using Math object as event handler attribute. Let's not add non-enumerable props unless we find a usecase.
@@ -0,0 +1,3 @@ | |||
export default function isReserved(name) { | |||
return ['delete'].indexOf(name) >= 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.
There's a lot of other reserved keywords: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords
You can also consider this approach instead of appending $
:
https://github.com/rhalff/storybook/blob/master/addons/actions/src/preview.js#L27-L33
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.
Tried to solve it by supporting both methods, preferring the one you have suggests.
The eval version could be removed if you find it unnecessary.
I've included the changes of #2428 but moved the check to a different location.
Object.assign(this, data); | ||
} | ||
|
||
Object.defineProperty(FakeConstructor, '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.
This will break in android emulator, see #2324
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.
Adding canConfigureName
check should solve this
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.
This should also be fixed now, I didn't test it on android though.
@@ -0,0 +1,62 @@ | |||
/* global File */ |
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.
require { File, Math } from 'global'
This reverts commit 9bda5ab.
for (const name in value) { | ||
// noinspection JSUnfilteredForInLoop | ||
if ( | ||
keys.indexOf(name) === -1 && |
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.
Why is this check needed? There's no chance that for .. in
yields duplicate keys:
const a = {foo: 'foo', bar: 'bar'}
const b = Object.create(a, {foo: {value: 'baz', enumerable: 'true'}})
for (key in b) { console.log(key) }
VM372:1 foo
VM372:1 bar
Note that foo
is logged only once
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.
Sorry, a left over from populating the keys array with ownPropertyNames first, I will remove it.
The function check is needed to only show functions in case they are own properties of the current object.
The previous fix only worked because the results were stringified, filtering out all functions e.g. for .. in
over a file object does include slice
etc. but were not shown, because of the stringification later on.
// noinspection JSUnfilteredForInLoop | ||
if ( | ||
keys.indexOf(name) === -1 && | ||
!(typeof value[name] === 'function' && !hasOwnProperty.call(value, 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.
Let's invert the check, so that it's more clear what it does (picks all the own properties, and non-function delegated properties):
if (hasOwnProperty.call(value, name)) || typeof value[name] !== 'function')
@rhalff can you please extract the fix for primitive types into a separate PR? We need it for |
I do not think that will be a better merge than the one currently offered. The main problems I found in the current state of the pull request is Firefox not liking some objects as weakmap keys and IE Edge and down still consider some decycled objects as cyclic. This only happens on logging the 'window' object though. Not at the level of e.g SyntheticEvent. I would prefer updating this pull request and just return the errors to the action logger. |
OK, let's do that |
@Hypnosphi I've added the error handling, to trigger some errors you can cllick the window type button in firefox and IE / Edge, perhaps there are better solutions to solve this, but it works for now. |
Great. Please run |
Please also update storyshots:
|
Storyshots is also updated now, I still get a warning when I run jest though:
Should the babel ignore pattern be updated to also ignore the I think it's defined in scripts/prepare.js |
Yes, I think so. Please adjust |
@rhalff Thank you for this epic PR, I know you spend a lot of work and time on this 🙇 Are you planning to open more PR's? I can add you to the github organisation to make this easier if you want? |
@ndelangen Thanks! I'm not planning more PR's at the moment though. Besides that the current method is easy enough. @Hypnosphi thanks for reviewing. |
Actually, when the PR branch is in the same repo, it makes things a bit easier for reviewers =) |
In that case, add me.. :) |
Primitive types failed to be logged.
Refactor of the code, split functionality into different files and added tests.
I've added an extra example in the kitchen sink app which logs different types.
The changes from #2401 were merged.