From 4c065459528e234ffbd78e16d30749b3de59f8d5 Mon Sep 17 00:00:00 2001
From: muqiuhan 本快速入门文档参照 Turborepo 2.x 官方文档: https://turbo.build/repo/docs It’s hard to miss things when you don’t know different things exist The first problem is, and personally, I believe it’s the biggest JavaScript problem ever: we don’t know what can throw an error. From a JavaScript error perspective, it’s the same as the following: JavaScript doesn’t know; JavaScript doesn’t care. You should know. Second thing, this is perfectly viable code: No errors, no linters, even though this can break your app. Right now, in my head, I can hear, “What’s the problem, just use try/catch everywhere.” Here comes the third problem: we don’t know which one is thrown. Of course, we can somehow guess by the error message, but what about bigger services/functions with many places where errors can happen? Are you sure you are handling all of them properly with one try/catch? The most verbose of the three shown here and, ironically, the best one. So, first of all, Rust handles the errors using its amazing enums (they are not the same as TypeScript enums!). Without going into detail, what is important here is that it uses an enum called The summary here is that Rust always know where there might be an error. And it force you to deal with it right where it appears (mostly). No hidden ones, no guessing, no breaking app with a surprise face. And this approach is just better. By A MILE. We cannot make TypeScript errors work like the Rust. The limiting factor here is the language itself; it doesn’t have the proper tools to do that. But what we can do is try to make it similar. And make it simple: we do need a few try/catches. The good thing is we only need about two, not 100,000: This is just a wrapper with our New solution is longer, but it performs better because of the following reasons: It’s hard to miss things when you don’t know different things exist The first problem is, and personally, I believe it’s the biggest JavaScript problem ever: we don’t know what can throw an error. From a JavaScript error perspective, it’s the same as the following: JavaScript doesn’t know; JavaScript doesn’t care. You should know. Second thing, this is perfectly viable code: No errors, no linters, even though this can break your app. Right now, in my head, I can hear, “What’s the problem, just use try/catch everywhere.” Here comes the third problem: we don’t know which one is thrown. Of course, we can somehow guess by the error message, but what about bigger services/functions with many places where errors can happen? Are you sure you are handling all of them properly with one try/catch? The most verbose of the three shown here and, ironically, the best one. So, first of all, Rust handles the errors using its amazing enums (they are not the same as TypeScript enums!). Without going into detail, what is important here is that it uses an enum called The summary here is that Rust always know where there might be an error. And it force you to deal with it right where it appears (mostly). No hidden ones, no guessing, no breaking app with a surprise face. And this approach is just better. By A MILE. We cannot make TypeScript errors work like the Rust. The limiting factor here is the language itself; it doesn’t have the proper tools to do that. But what we can do is try to make it similar. And make it simple: we do need a few try/catches. The good thing is we only need about two, not 100,000: This is just a wrapper with our New solution is longer, but it performs better because of the following reasons: 虽然我早已不强求世界上有这么一个人, 但我会一直等待,甚至期待你的到来。 我叫韩暮秋,幸会。
最后一次编辑:二〇二四年九月二十七日下午六点〇七分try {
let data = “Hello”;
} catch (err) {
console.error(err);
}const request = { name: “test”, value: 2n };
const body = JSON.stringify(request);
const response = await fetch("https://example.com", {
method: “POST”,
body,
});
if (!response.ok) {
return;
}
+let greeting_file_result = File::open(“hello.txt”);
let greeting_file = match greeting_file_result {
Ok(file) => file,
Err(error) => panic!("Problem opening the file: {:?}", error),
};Result with two variants: Ok and Err. As you might guess, Ok holds a value and Err holds…surprise, an error :D.export type Safe<T> =
| {
success: true;
data: T;
}
| {
success: false;
error: string;
};export function safe<T>(promise: Promise<T>, err?: string): Promise<Safe<T>>;
export function safe<T>(func: () => T, err?: string): Safe<T>;
export function safe<T>(
promiseOrFunc: Promise<T> | (() => T),
err?: string,
): Promise<Safe<T>> | Safe<T> {
if (promiseOrFunc instanceof Promise) {
return safeAsync(promiseOrFunc, err);
}
return safeSync(promiseOrFunc, err);
}
async function safeAsync<T>(
promise: Promise<T>,
err?: string
): Promise<Safe<T>> {
try {
const data = await promise;
return { data, success: true };
} catch (e) {
console.error(e);
if (err !== undefined) {
return { success: false, error: err };
}
if (e instanceof Error) {
return { success: false, error: e.message };
}
return { success: false, error: "Something went wrong" };
}
}
function safeSync<T>(
func: () => T,
err?: string
): Safe<T> {
try {
const data = func();
return { data, success: true };
} catch (e) {
console.error(e);
if (err !== undefined) {
return { success: false, error: err };
}
if (e instanceof Error) {
return { success: false, error: e.message };
}
return { success: false, error: "Something went wrong" };
}
}Safe type as the return one. But sometimes simple things are all you need. Let’s combine them with the example from above.const request = { name: “test”, value: 2n };
const body = safe(
() => JSON.stringify(request),
“Failed to serialize request”,
);
if (!body.success) {
// handle error (body.error)
return;
}
const response = await safe(
fetch("https://example.com", {
method: “POST”,
body: body.data,
}),
);
if (!response.success) {
// handle error (response.error)
return;
}
if (!response.data.ok) {
// handle network error
return;
}
// handle response (body.data)
+
]]>try {
let data = “Hello”;
} catch (err) {
console.error(err);
}const request = { name: “test”, value: 2n };
const body = JSON.stringify(request);
const response = await fetch("https://example.com", {
method: “POST”,
body,
});
if (!response.ok) {
return;
}
-let greeting_file_result = File::open(“hello.txt”);
let greeting_file = match greeting_file_result {
Ok(file) => file,
Err(error) => panic!("Problem opening the file: {:?}", error),
};Result with two variants: Ok and Err. As you might guess, Ok holds a value and Err holds…surprise, an error :D.export type Safe<T> =
| {
success: true;
data: T;
}
| {
success: false;
error: string;
};export function safe<T>(promise: Promise<T>, err?: string): Promise<Safe<T>>;
export function safe<T>(func: () => T, err?: string): Safe<T>;
export function safe<T>(
promiseOrFunc: Promise<T> | (() => T),
err?: string,
): Promise<Safe<T>> | Safe<T> {
if (promiseOrFunc instanceof Promise) {
return safeAsync(promiseOrFunc, err);
}
return safeSync(promiseOrFunc, err);
}
async function safeAsync<T>(
promise: Promise<T>,
err?: string
): Promise<Safe<T>> {
try {
const data = await promise;
return { data, success: true };
} catch (e) {
console.error(e);
if (err !== undefined) {
return { success: false, error: err };
}
if (e instanceof Error) {
return { success: false, error: e.message };
}
return { success: false, error: "Something went wrong" };
}
}
function safeSync<T>(
func: () => T,
err?: string
): Safe<T> {
try {
const data = func();
return { data, success: true };
} catch (e) {
console.error(e);
if (err !== undefined) {
return { success: false, error: err };
}
if (e instanceof Error) {
return { success: false, error: e.message };
}
return { success: false, error: "Something went wrong" };
}
}Safe type as the return one. But sometimes simple things are all you need. Let’s combine them with the example from above.const request = { name: “test”, value: 2n };
const body = safe(
() => JSON.stringify(request),
“Failed to serialize request”,
);
if (!body.success) {
// handle error (body.error)
return;
}
const response = await safe(
fetch("https://example.com", {
method: “POST”,
body: body.data,
}),
);
if (!response.success) {
// handle error (response.error)
return;
}
if (!response.data.ok) {
// handle network error
return;
}
// handle response (body.data)
-
]]>
衣服买大了,他们走路好急,地铁上只有老人没看手机,天怎么黑那么快是我起晚了吗,那个蹦蹦跳跳的女孩耳机里在听什么歌,我还在原地吗,我要再等等吗。
+家就像厚酒之后突然明晰的想象,时间不语,只是沉默,我沉默地走进时间,看着我和你的年龄相差越来越小。
+这雨天,世界都温柔的可以掐出水来。
]]>-]]> -韩暮秋,息止安所。
我闭上眼睛就能感受到不知道是过去还是未来的某个时刻,阳光从睫毛的缝隙钻进我的眼睛,闭上眼睛是一片光圈,我看不清周围,我也不需要看清周围,我只需要感觉到整个世界给我最热烈的拥抱。
+我睁开眼睛也能感受到过去还是未来的某个时刻,我开车穿梭在灰蒙蒙的细雨笼罩中的城市,细雨模糊了整个城市的夜空,在我的车窗前汇成水珠晕开了红绿灯的光线,再被雨刮器一扫而空。
]]>我闭上眼睛就能感受到不知道是过去还是未来的某个时刻,阳光从睫毛的缝隙钻进我的眼睛,闭上眼睛是一片光圈,我看不清周围,我也不需要看清周围,我只需要感觉到整个世界给我最热烈的拥抱。
-我睁开眼睛也能感受到过去还是未来的某个时刻,我开车穿梭在灰蒙蒙的细雨笼罩中的城市,细雨模糊了整个城市的夜空,在我的车窗前汇成水珠晕开了红绿灯的光线,再被雨刮器一扫而空。
+接收到的评论不必急于改变,先存起来,让它们陪着自己,跟着时间走,路上会慢慢的和其他的事情连结起来,这样就能择其善者而从之,其不善者而改之了。
应当早日从这喧扰的世界冷静下来,让脑子里满是憧憬和情爱的灵魂得到一丝陈酿,理性点抬头看看世界上方的二氧化碳,自己晃晃头打破能回到最初的样子再重来的梦。
爱你们。
+]]>世界同可怜的孩子一起闭上了眼睛,世界不那么开心,但是
++]]>这个世界,我真的爱你
+
岁月中的某个文明中的某个人,曾经也骑着骆驼向远方,又是哪个人,吟着佛门心语站在我身旁,我听见大漠的念经声。
我不是个有耐心的人, 抄经书对我来说是种折磨, 我只能选择把经文抄在大地上, 黄沙上, 用自己的双腿一点点写, 用耳去倾听狂风卷积的声音。
我生来就是为了把这个世界的消息和秘密带到下一个世界去。
-]]> -世界同可怜的孩子一起闭上了眼睛,世界不那么开心,但是
--]]>这个世界,我真的爱你
-
input事件监听器来捕获用户的输入变化。以下是一个简单的防抖函数示例:
+function debounce(func, wait) { |
假设你有一个输入框用于搜索患者:
+<script> |
通过这种方式,你可以实现一个高效的实时搜索功能,既能保证用户体验,又能减少服务器的负担。
+]]>input事件监听器来捕获用户的输入变化。以下是一个简单的防抖函数示例:
-function debounce(func, wait) { |
假设你有一个输入框用于搜索患者:
-<script> |
通过这种方式,你可以实现一个高效的实时搜索功能,既能保证用户体验,又能减少服务器的负担。
-]]>衣服买大了,他们走路好急,地铁上只有老人没看手机,天怎么黑那么快是我起晚了吗,那个蹦蹦跳跳的女孩耳机里在听什么歌,我还在原地吗,我要再等等吗。
-家就像厚酒之后突然明晰的想象,时间不语,只是沉默,我沉默地走进时间,看着我和你的年龄相差越来越小。
-这雨天,世界都温柔的可以掐出水来。
-]]>那些古人们认为不可能办到的事,我们要敢于尝试和创新,只有这样,才能发现是否是可以做到的。古人有古人的办法,新人有新人的办法。古人只知道不断添柴就可以让火苗不灭,而新人却可以在火车锅炉中放点干柴就可以让火车绕着地球跑。
-对于年势已高的老人家而言,不能仅凭年龄就说自己有资格成为年轻人的老师,因为他所失去的要比得到的多得多。任何人都有权怀疑,那些最聪明的人是否真正发现了生活的价值。
-说实话,老一辈人并没有什么至关重要的忠告留给年轻人,他们的生活经验如此不完美,他们的人生因为某种个人原因过得如此悲惨失败。也许阅历中还给了他们一些有悖于那种经验的信心,可惜他们已经不再年轻。我在这世上已经活了二十年零六天,却从没在我的长辈那里得到过一个有价值的忠告或建议。他们讲不出什么有意义的事情,却总是说一些不得要领的话来教训我。这就是生活,一个在很大程度上我并未尝试过的实验;他们尝试过了,对我来说却毫无益处。
]]>那些古人们认为不可能办到的事,我们要敢于尝试和创新,只有这样,才能发现是否是可以做到的。古人有古人的办法,新人有新人的办法。古人只知道不断添柴就可以让火苗不灭,而新人却可以在火车锅炉中放点干柴就可以让火车绕着地球跑。
+对于年势已高的老人家而言,不能仅凭年龄就说自己有资格成为年轻人的老师,因为他所失去的要比得到的多得多。任何人都有权怀疑,那些最聪明的人是否真正发现了生活的价值。
+说实话,老一辈人并没有什么至关重要的忠告留给年轻人,他们的生活经验如此不完美,他们的人生因为某种个人原因过得如此悲惨失败。也许阅历中还给了他们一些有悖于那种经验的信心,可惜他们已经不再年轻。我在这世上已经活了二十年零六天,却从没在我的长辈那里得到过一个有价值的忠告或建议。他们讲不出什么有意义的事情,却总是说一些不得要领的话来教训我。这就是生活,一个在很大程度上我并未尝试过的实验;他们尝试过了,对我来说却毫无益处。
+]]>