mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-19 05:02:40 +08:00
Revert "do not list non-enumerable properties"
This reverts commit 9bda5ab4935a3395b5de93430b1506a8aee6fd8e.
This commit is contained in:
parent
9bda5ab493
commit
9a46c6e13d
@ -1,4 +1,4 @@
|
||||
import { typeReplacer } from './util';
|
||||
import { getPropertiesList, typeReplacer } from './util';
|
||||
|
||||
import { CYCLIC_KEY } from './';
|
||||
|
||||
@ -48,10 +48,9 @@ export default function decycle(object, depth = 10) {
|
||||
} else {
|
||||
obj = classType.serialize(value);
|
||||
|
||||
// eslint-disable-next-line guard-for-in, no-restricted-syntax
|
||||
for (const name in value) {
|
||||
getPropertiesList(value).forEach(name => {
|
||||
obj[name] = derez(value[name], `${path}[${JSON.stringify(name)}]`, _depth + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (_depth === 0 && value instanceof Object && isCyclic) {
|
||||
|
@ -0,0 +1,62 @@
|
||||
import { File, Math } from 'global';
|
||||
import getPropertiesList from '../getPropertiesList';
|
||||
|
||||
describe('getPropertiesList', () => {
|
||||
it('for plain object', () => {
|
||||
expect(getPropertiesList({ a: 'A', b: 'B' })).toEqual(['a', 'b']);
|
||||
});
|
||||
|
||||
it('for Math object', () => {
|
||||
expect(getPropertiesList(Math)).toEqual([
|
||||
'abs',
|
||||
'acos',
|
||||
'acosh',
|
||||
'asin',
|
||||
'asinh',
|
||||
'atan',
|
||||
'atanh',
|
||||
'atan2',
|
||||
'ceil',
|
||||
'cbrt',
|
||||
'expm1',
|
||||
'clz32',
|
||||
'cos',
|
||||
'cosh',
|
||||
'exp',
|
||||
'floor',
|
||||
'fround',
|
||||
'hypot',
|
||||
'imul',
|
||||
'log',
|
||||
'log1p',
|
||||
'log2',
|
||||
'log10',
|
||||
'max',
|
||||
'min',
|
||||
'pow',
|
||||
'random',
|
||||
'round',
|
||||
'sign',
|
||||
'sin',
|
||||
'sinh',
|
||||
'sqrt',
|
||||
'tan',
|
||||
'tanh',
|
||||
'trunc',
|
||||
'E',
|
||||
'LN10',
|
||||
'LN2',
|
||||
'LOG10E',
|
||||
'LOG2E',
|
||||
'PI',
|
||||
'SQRT1_2',
|
||||
'SQRT2',
|
||||
]);
|
||||
});
|
||||
|
||||
it('for File object', () => {
|
||||
const file = new File([''], 'filename.txt', { type: 'text/plain', lastModified: new Date() });
|
||||
|
||||
expect(getPropertiesList(file)).toEqual(['name', 'lastModified', 'size', 'type', 'isClosed']);
|
||||
});
|
||||
});
|
17
addons/actions/src/lib/util/getPropertiesList.js
Normal file
17
addons/actions/src/lib/util/getPropertiesList.js
Normal file
@ -0,0 +1,17 @@
|
||||
const { hasOwnProperty } = Object.prototype;
|
||||
|
||||
export default function getPropertiesList(value) {
|
||||
const keys = Object.getOwnPropertyNames(value);
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const name in value) {
|
||||
if (
|
||||
keys.indexOf(name) === -1 &&
|
||||
!(typeof value[name] === 'function' && !hasOwnProperty.call(value, name))
|
||||
) {
|
||||
keys.push(name);
|
||||
}
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
export getPropertiesList from './getPropertiesList.js';
|
||||
export isObject from './isObject.js';
|
||||
export muteProperty from './muteProperty.js';
|
||||
export typeReviver from './typeReviver.js';
|
||||
|
@ -43,6 +43,7 @@ storiesOf('Addon Actions', module)
|
||||
<Button onClick={() => action('NaN')(NaN)}>NaN</Button>
|
||||
<Button onClick={() => action('null')(null)}>null</Button>
|
||||
<Button onClick={() => action('Number')(10000)}>Number</Button>
|
||||
<Button onClick={() => action('Math')(Math)}>Math</Button>
|
||||
<Button
|
||||
onClick={() =>
|
||||
action('clicked')(
|
||||
|
Loading…
x
Reference in New Issue
Block a user