mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-19 05:02:40 +08:00
do not list non-enumerable properties
This commit is contained in:
parent
a39858318c
commit
9bda5ab493
@ -1,4 +1,4 @@
|
|||||||
import { getPropertiesList, typeReplacer } from './util';
|
import { typeReplacer } from './util';
|
||||||
|
|
||||||
import { CYCLIC_KEY } from './';
|
import { CYCLIC_KEY } from './';
|
||||||
|
|
||||||
@ -48,9 +48,10 @@ export default function decycle(object, depth = 10) {
|
|||||||
} else {
|
} else {
|
||||||
obj = classType.serialize(value);
|
obj = classType.serialize(value);
|
||||||
|
|
||||||
getPropertiesList(value).forEach(name => {
|
// eslint-disable-next-line guard-for-in, no-restricted-syntax
|
||||||
|
for (const name in value) {
|
||||||
obj[name] = derez(value[name], `${path}[${JSON.stringify(name)}]`, _depth + 1);
|
obj[name] = derez(value[name], `${path}[${JSON.stringify(name)}]`, _depth + 1);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_depth === 0 && value instanceof Object && isCyclic) {
|
if (_depth === 0 && value instanceof Object && isCyclic) {
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
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']);
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,17 +0,0 @@
|
|||||||
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,4 +1,3 @@
|
|||||||
export getPropertiesList from './getPropertiesList.js';
|
|
||||||
export isObject from './isObject.js';
|
export isObject from './isObject.js';
|
||||||
export muteProperty from './muteProperty.js';
|
export muteProperty from './muteProperty.js';
|
||||||
export typeReviver from './typeReviver.js';
|
export typeReviver from './typeReviver.js';
|
||||||
|
@ -43,7 +43,6 @@ storiesOf('Addon Actions', module)
|
|||||||
<Button onClick={() => action('NaN')(NaN)}>NaN</Button>
|
<Button onClick={() => action('NaN')(NaN)}>NaN</Button>
|
||||||
<Button onClick={() => action('null')(null)}>null</Button>
|
<Button onClick={() => action('null')(null)}>null</Button>
|
||||||
<Button onClick={() => action('Number')(10000)}>Number</Button>
|
<Button onClick={() => action('Number')(10000)}>Number</Button>
|
||||||
<Button onClick={() => action('Math')(Math)}>Math</Button>
|
|
||||||
<Button
|
<Button
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
action('clicked')(
|
action('clicked')(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user