我正在React中编写一个应用程序,无法避免出现一个超级常见的陷阱,该陷阱正在调用setState(...)after componentWillUnmount(...)。
我非常仔细地查看了我的代码,并尝试放置一些保护子句,但是问题仍然存在,并且我仍在观察警告。
因此,我有两个问题:
Warning: Can't perform a React state update on an unmounted component.
This is a no-op, but it indicates a memory leak in your application.
To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount
method.
in TextLayerInternal (created by Context.Consumer)
in TextLayer (created by PageInternal) index.js:1446
d/console[e]
index.js:1446
warningWithoutStack
react-dom.development.js:520
warnAboutUpdateOnUnmounted
react-dom.development.js:18238
scheduleWork
react-dom.development.js:19684
enqueueSetState
react-dom.development.js:12936
./node_modules/react/cjs/react.development.js/Component.prototype.setState
react.development.js:356
_callee$
TextLayer.js:97
tryCatch
runtime.js:63
invoke
runtime.js:282
defineIteratorMethods/</prototype[method]
runtime.js:116
asyncGeneratorStep …Run Code Online (Sandbox Code Playgroud) 我想问你的问题很广泛但同时它非常具体.首先,我必须说,我最感兴趣的是适用于.net环境的答案.
好吧,我想提高我生成的代码级别.现在我主要使用TDD和静态代码分析来确保我的代码是正确的.最近我听了Dino Esposito关于代码合同的演讲,现在我想将它与其他技术结合使用.在听Dino的同时我也回忆起了Debug.Assert()和Trace.Assert().
具体来说,我会问几个问题:
Debug.Assert()吗?什么时候可以使用它们?(例如,请注意.net中的不变量仅在公共方法/属性出口处进行检查.那么,通过简单方法在方法中间进行一些检查是否可以Assert()?)据我了解,我的Google云功能可以全球访问.如果我想控制对它们的访问,我需要将授权作为函数本身的一部分来实现.说,我可以使用基于承载令牌的方法.这将保护此功能背后的资源免受未经授权的访问.
但是,由于该功能在全球范围内可用,它仍然可以由坏人进行DDoS编辑.如果攻击不如谷歌的防御强,我的功能/服务可能仍然是响应.这很好.但是,我不想支付我未授权访问该功能的一方所做的功能调用.(因为计费是每个函数调用的数量).这就是为什么在我负责收费之前了解Google云端功能是否检测到DDoS攻击以及启用反措施对我来说非常重要.
ASP.NET Core 2.1.1为appBuilder提供了一些看似相关的扩展方法:
UseStaticFiles 从 Microsoft.AspNetCore.StaticFilesUseSpaStaticFiles 从 Microsoft.AspNetCore.SpaServices.ExtensionsUseSpa 从 Microsoft.AspNetCore.SpaServices.Extensions请帮助我理解他们的目的和彼此之间的关系吗?
另外,如果我以不同的顺序(例如app.UseStaticFiles() -> app.UseSpaStaticFiles() -> app.UseSpa()vs app.UseSpa() -> app.UseSpaStaticFiles() -> app.UseStaticFiles())运行这些方法,那么从服务器执行的角度来看有什么不同吗?
Jest 允许通过it.each前缀变量在测试用例的数据中使用。name$
下面的代码产生如下输出:
\n\n PASS src/array-functions/find-pairwise.spec.ts\n findPairwise\n \xe2\x88\x9a should return [1, 2] for [1, 2, 3] and [Function anonymous] (7ms)\n \xe2\x88\x9a should return [1, 2] for [1, 2, 3] and [Function anonymous] (1ms)\n \xe2\x88\x9a should return [2, 3] for [1, 2, 3] and [Function anonymous]\n \xe2\x88\x9a should return [2, 3] for [1, 2, 3] and [Function anonymous] (1ms)\n \xe2\x88\x9a should return [undefined, undefined] for [1, 2, 3] and [Function anonymous]\n\nTest Suites: 1 passed, …Run Code Online (Sandbox Code Playgroud) 虽然 @MrUpsidedown 在评论部分提供了一些相关问题,但他们都没有真正回答我在这里试图强调的部分:如何安全地提供 API 密钥?
\n在阅读了链接问题中的所有答案后,我倾向于自己写一个答案。
\n我是一名非常新的 Flutter 开发人员,尝试将 Google 地图集成到演示应用程序中。
\n为了节省时间,我决定尝试我能找到的最流行的 Google 地图 Widget 库,即google_maps_flutter. 该库的简洁文档显示了 Android 和 iOS 使用示例,并且都说明了 API 密钥是内联提供的,作为代码库的一部分:
import UIKit\nimport Flutter\nimport GoogleMaps\n\n@UIApplicationMain\n@objc class AppDelegate: FlutterAppDelegate {\n override func application(\n _ application: UIApplication,\n didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?\n ) -> Bool {\n GMSServices.provideAPIKey("YOUR KEY HERE") // <------------------------------------ O--\xd0\xbf\xd0\xbf\n GeneratedPluginRegistrant.register(with: self)\n return super.application(application, didFinishLaunchingWithOptions: launchOptions)\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n<manifest ...\n <application ...\n …Run Code Online (Sandbox Code Playgroud) 这个问题与我最近以一个可怕的hack™ 关闭的另一个问题有关.
我正在尝试编写一个脚本,可以在CI /构建管道的上下文中使用一个步骤.
该脚本应该为我们的Angular单页面应用程序(SPA)运行基于Protractor的端到端测试.
该脚本需要执行以下操作(按顺序):
- 运行名为"App"的.NET Core微服务
- 运行名为"Web"的.NET Core微服务
- 运行SPA
- 运行一个执行Protractor测试的命令
- 在步骤4完成后(成功或出错),终止在步骤1-3中创建的进程.这绝对是必要的,否则构建将永远不会在CI中完成和/或将会出现僵尸Web/App/SPA进程,这将破坏未来的构建管道执行.
我还没有开始处理第4步("e2e测试"),因为我真的想确保第5步("清理")按预期工作.
正如你猜的那样(右),清理步骤不起作用.具体来说,进程"App"和"Web"不会因某种原因而被杀死并继续运行.
顺便说一句,我确保我的gulp脚本以提升(管理员)权限执行.
我刚刚发现问题的直接原因(我认为),我不知道究竟是什么原因.按照我的预期,有5个进程而不是1个进程.例如,对于App流程,在流程管理器中观察到以下流程:
{
"id": 14840,
"binary": "cmd.exe",
"title": "Console"
},
{
"id": 12600,
"binary": "dotnet.exe",
"title": "Console"
},
{
"id": 12976,
"binary": "cmd.exe",
"title": "Console"
},
{
"id": 5492,
"binary": "cmd.exe",
"title": "Console"
},
{
"id": 2636,
"binary": "App.exe",
"title": "Console"
}
Run Code Online (Sandbox Code Playgroud)
同样,为Web服务创建了五个进程而不是一个进程:
{ …Run Code Online (Sandbox Code Playgroud) 如何修复在通过命令行运行 .NET Core 测试时收到的令人讨厌的警告dotnet test?
在dotnet --version返回3.1.101。
Run Code Online (Sandbox Code Playgroud)$ dotnet test watch : Started C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(151,5): warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically. Otherwise, the PackageReference should be replaced with a FrameworkReference. [C:\github\demo\Demo\SmartHome.API\SmartHome.API.csproj] C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(151,5): warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, …
我正在尝试使用和/ 使用可观察字段进行基于select/ option的下拉工作.我的代码出了点问题,因为在运行时控制台会输出一个(请参见下图).asyncPipe[ngModel](ngModelChange)[object Object]
令我困惑的是,如果我使用[value]="payPeriod.id"它,它工作正常,数字id成功接收setSelectedPayPeriod(...).
component.html
<select [ngModel]="selectedPayPeriod | json" (ngModelChange)="setSelectedPayPeriod($event)">
<option *ngFor="let payPeriod of (payPeriodList | async)" [value]="payPeriod">{{ payPeriod.endDate }}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
component.ts
get payPeriodList(): Observable<PayPeriod[]> {
return this._contextService.payPeriodList;
}
get selectedPayPeriod(): Observable<PayPeriod> {
return this._contextService.selectedPayPeriod;
}
setSelectedPayPeriod(newValue: PayPeriod): void {
console.warn(newValue);
this._contextService.setSelectedPayPeriod(newValue);
}
Run Code Online (Sandbox Code Playgroud)
对不起,我对plunker不是很熟悉,也无法快速找到我可以解决的Angular 2模板.
[ngValue],而不是[value]对option元素.[ngModel]="selectedPayPeriod | async",而不是[ngModel]="selectedPayPeriod | json" …我需要找到正则表达式来找到一个用 grep 重复 4 次或更多次的字符。
我知道表达式是 {n,},所以如果我需要查找行,例如,当字符“g”重复 4 次或更多次时,理论上 grep 手册页是:
grep "g{4,}" textsamplefile
Run Code Online (Sandbox Code Playgroud)
但不起作用。有什么帮助吗?
字符可以有其他字母。例如,有效匹配是:
g示例g of g有效g匹配g
g其他g有效g匹配g是g这里g
GGGG其他
c# ×3
javascript ×3
asp.net-core ×2
typescript ×2
.net ×1
.net-core ×1
angular ×1
api-key ×1
assert ×1
dart ×1
fail-fast ×1
flutter ×1
google-maps ×1
grep ×1
gulp ×1
jestjs ×1
lodash ×1
node.js ×1
process ×1
reactjs ×1
regex ×1
repeat ×1
security ×1
setstate ×1
testing ×1
unit-testing ×1
warnings ×1
windows ×1