我想检查我的 URL 内容并执行以下操作:
if (URL.include('path')) {
//do something
} else {
// do something else
}
Run Code Online (Sandbox Code Playgroud)
我可以这样检查我的网址
cy.url().should('include', 'path');
Run Code Online (Sandbox Code Playgroud)
但是当我将它粘贴到if运算符中时它不起作用。
我有一个从CSV文件操作导入产品的类,需要大约7个参数.这是进口商绝对需要的信息.
所有这些参数都具有相同的使用寿命.最后,我们必须有一个不可变对象.
我太害怕在构造函数中列出所有这些因为它对可读性的影响并且决定将其中的3个移动到setter注入.但显然这不是一个优雅的解决方案.
问题:
1)混合基于构造函数和基于setter的注射是不好的做法吗?
2)如何解决这个特殊问题?
我正在考虑应用Martin Fowler的"引入参数对象"重构,但这有一个问题.
4参数可以很容易地移动到Parameter对象(customerId,projectId,languageId等) - 所有整数.
其他3个参数是我注入的对象(模拟单元测试需要它).
/* error handler that will be used below in pipe with catchError()
* when resource fetched with HttpClient get() */
private _handleError<T> (operation: string, result?:T) {
return( error: any): Observable<T> => {
console.error( operation + ' ' + error.message );
// or something else I want to do
return of(result as T); // lets me return innocuous results
}
}
getObjects() {
return this.http.get<any[]>(this.myUrl).pipe(
catchError(this._handleError('my error', [])
);
}
Run Code Online (Sandbox Code Playgroud)
现在tap用于处理错误
getObjects() {
return this.http.get<any[]>(this.myUrl).pipe(
tap( objects => { …Run Code Online (Sandbox Code Playgroud) 是否有特定的习惯用法或实用程序用于undefined从 RxJS observables 中过滤?此代码具有我想要的行为:
obs.pipe(filter(x => x !== undefined))
Run Code Online (Sandbox Code Playgroud)
一些替代方案是
obs.pipe(filter(x => x)) // for all falsy values
obs.pipe(filter(Boolean)) // for falsy variables using Boolean ctor
Run Code Online (Sandbox Code Playgroud) I would like to delete a property and return a new object without mutating the original object.
I know we can do this easily with Lodash like this:
const profile = { name: 'Maria', age: 30 }
_.omit(profile, name) // it returns a new object without the property name {age: 30}
Run Code Online (Sandbox Code Playgroud)
However, I would like to know if it's possible to do it with vanilla JavaScript without assigning that value to undefined or using a filter?
我在我公司的代码库中注意到了它,它每周有 3000 万次下载,所以我很好奇它的重要性。
我正在尝试水平拉伸内部对象,以便它们填充容器的宽度。
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
height: 200px;
align-items: stretch;
background-color: DodgerBlue;
}
.flex-container > div {
background-color: #f1f1f1;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
</style>
</head>
<body>
<h1>The align-items Property</h1>
<p>The "align-items: stretch;" stretches the flex items to fill the container (this is default):</p>
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
由于以下属性,内部 div 元素的高度被拉伸:
align-items: stretch;
Run Code Online (Sandbox Code Playgroud)
如何拉伸这些元素的宽度?
我有 HTTP 拦截器。在那个拦截器中,在我更改请求之前,我需要打开一个加载程序。
真正让我担心的是我最终有很多switchMaps。
为什么?
我在装载机服务中做什么
public showLoader(message) {
return this.translateService.get(message).pipe(
switchMap((translatedMessage) => {
this.loader$ = from(
this.loadingController.create({ message: translatedMessage })
);
return this.loader$.pipe(
switchMap((loader) => {
return from(loader.present());
})
);
})
);
}
Run Code Online (Sandbox Code Playgroud)
在我的拦截器中
public intercept(request: HttpRequest<any>, next: HttpHandler) {
return this.loaderService.showLoader("WAITING").pipe(
take(1),
switchMap( ()=>{
Run Code Online (Sandbox Code Playgroud)
所以已经有 3 个嵌套的switchMaps。在它下面,我还需要 2 或 3 个switchMaps(一个用于从存储中获取令牌,另一个用于其他用途)。基本上最终有 5switchMap秒。
问题:嵌套所有这些switchMap被认为是一种反模式吗?
我将我的 Rails 应用程序迁移到 Rails 6.0.1,每次启动服务器时,我都会收到这些 Fog 弃用警告。我怎样才能摆脱它们?有趣的是我有这个应用程序的克隆版本,它没有给出这些警告......
[fog][DEPRECATION] Unable to load Fog::Atmos::Storage
[fog][DEPRECATION] The format Fog::Storage::Atmos is deprecated
[fog][DEPRECATION] Unable to load Fog::Clodo::Compute
[fog][DEPRECATION] The format Fog::Compute::Clodo is deprecated
[fog][DEPRECATION] Unable to load Fog::DigitalOcean::Compute
[fog][DEPRECATION] The format Fog::Compute::DigitalOcean is deprecated
[fog][DEPRECATION] Unable to load Fog::Dnsimple::DNS
[fog][DEPRECATION] The format Fog::DNS::Dnsimple is deprecated
[fog][DEPRECATION] Unable to load Fog::DNSMadeEasy::DNS
[fog][DEPRECATION] The format Fog::DNS::DNSMadeEasy is deprecated
[fog][DEPRECATION] Unable to load Fog::Fogdocker::Compute
[fog][DEPRECATION] The format Fog::Compute::Fogdocker is deprecated
[fog][DEPRECATION] Unable to load Fog::Dreamhost::DNS
[fog][DEPRECATION] The …Run Code Online (Sandbox Code Playgroud) 当发生未处理的错误时,前端会收到 500 错误,并且没有任何有关该错误的信息。它只是收到这个:
{
"statusCode": 500,
"message": "Internal server error"
}
Run Code Online (Sandbox Code Playgroud)
但是当我检查控制台时,我看到发生了什么以及错误消息是什么。在开发环境中还可以,但在生产环境中就很难搞清楚了。如何在生产中返回完整的错误消息,而不是像这样的简单消息"Internal server error"?
rxjs ×3
javascript ×2
angular ×1
css ×1
cypress ×1
flexbox ×1
fog ×1
lodash ×1
nestjs ×1
node.js ×1
object ×1
observable ×1
oop ×1
refactoring ×1
setter ×1
typescript ×1
web ×1