mic-inspector
Version:
A react inspector which a most similar of Chorme DevTools inspector
44 lines (43 loc) • 1.97 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import React, { useState } from 'react';
import { DescriptorValueType } from '../named-descriptor/types';
import { useStyles } from './use-styles';
import { NamedDescriptor } from '../named-descriptor';
import { renderGetterContent } from './locale';
import { PropertyValue } from '../property-value';
import { GetterStatus } from './types';
/**
* Getter type value that's one type of property value types
* @param param0 GetterValueProps
*/
export function GetterValue(_a) {
var { className, owner, value, onAccess: onAccessCallback } = _a, props = __rest(_a, ["className", "owner", "value", "onAccess"]);
const [status, setStatus] = useState(GetterStatus.Protected);
const [descriptor, setDescriptor] = useState();
const onAccess = () => {
let returnedValue;
let status;
try {
returnedValue = value.call(owner);
status = GetterStatus.Opened;
}
catch (e) {
returnedValue = `${e instanceof Error && e.stack ? e.stack : e}`;
status = GetterStatus.Unexpected;
}
setDescriptor(new NamedDescriptor(owner, '', returnedValue, DescriptorValueType.Normal));
setStatus(status);
onAccessCallback && onAccessCallback(status, returnedValue, value, owner);
};
return (React.createElement(PropertyValue, Object.assign({ className: useStyles(className) }, props, { "data-status": status }), renderGetterContent(status, descriptor, onAccess)));
}