我已经尝试了几种方法来为我的 React 组件设置显示名称,但都没有奏效:我尝试将其设置为公共静态变量,如下所示:
class Base extends React.Component<any, any>{
public static displayName = "Base";
constructor(props){
...
}
render(){
...
}
}
Run Code Online (Sandbox Code Playgroud)
但是 eslint 仍然给我抛出这个错误:
error Component definition is missing display name react/display-name
我尝试了另一种方法,将它设置在类定义之外:
class Base extends React.Component<any, any>{
constructor(props){
...
}
render(){
...
}
}
Base.displayName = "Base";
Run Code Online (Sandbox Code Playgroud)
我最终收到一条错误消息:
Property 'displayName' does not exist on type 'typeof Base'.
我尝试了与其他 Stackoverflow 帖子不同的方法,但似乎无法摆脱错误。我该如何解决这个问题?请帮忙。
编辑:在下面回答了我自己的问题。这个问题的核心似乎是关于匿名函数而不是 React 类。
所以我知道 PromQL 中的一些百分位数函数histogram_quantile在这样的情况下使用:
// Over the past 5 minutes, what's the maximum http response time experienced by 95% of our users
histogram_quantile(0.95, rate(http_request_duration_bucket[5m])
Run Code Online (Sandbox Code Playgroud)
我们可以这样计算平均值:
// Over the past 5 mins, what the average http response time?
avg by (webId) (rate(http_request_duration_sum[5m])/rate(http_request_duration_count[5m])
Run Code Online (Sandbox Code Playgroud)
是否可以将这两个函数组合起来得到表示以下内容的查询:在过去 5 分钟内,我们 95% 的用户经历的最大平均 HTTP 响应时间是多少?又称为平均值的 95%?
我尝试过类似的东西:
histogram_quantile(0.95, avg by (webId) (rate(http_request_duration_sum[5m])/rate(http_request_duration_count[5m]))
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用。我的理解有什么建议或差距吗?
我最近阅读了 Stephen Cleary 的文章,内容涉及当我们在同步方法中调用异步代码时可能发生的死锁:https: //blog.stephencleary.com/2012/07/dont-block-on-async-code.html
关于这里稍微修改的示例(我添加的只是一个 writeline 代码):
// My "library" method.
public static async Task<JObject> GetJsonAsync(Uri uri)
{
Console.WriteLine("Before await");
using (var client = new HttpClient())
{
var jsonString = await client.GetStringAsync(uri).ConfigureAwait(true);
return JObject.Parse(jsonString);
}
}
// My "top-level" method.
public void Button1_Click(...)
{
var jsonTask = GetJsonAsync(...);
textBox1.Text = jsonTask.Result;
}
Run Code Online (Sandbox Code Playgroud)
他的解释是,顶级方法正在阻塞等待GetJsonAsync完成的 UI 线程,同时GetJsonAsync正在等待 UI 线程被释放,以便它可以完成执行。
我的问题是,不是GetJsonAsync已经在 UI 线程上了吗?为什么需要等待它被释放?根据这篇文章,调用异步函数不一定会创建另一个线程来执行该方法。GetJsonAsync那么,如果一直在 UI 线程上执行,会如何导致 UI 线程出现问题呢?就像什么时候Console.WriteLine()执行,如果不在 UI 线程上,那么在哪里完成?我觉得我在这里错过了一些东西,但不知道是什么。
澄清:执行在什么时候离开 …
async-await ×1
asynchronous ×1
c# ×1
ecmascript-6 ×1
grafana ×1
javascript ×1
prometheus ×1
promql ×1
reactjs ×1
typescript ×1