到目前为止,我一直在使用livereload,这样每当我更改JS或模板时,页面都会刷新,当我更改CSS时,它会在没有刷新的情况下热切换新的CSS.
我现在正在尝试使用webpack并且几乎达到相同的行为,但有一个例外:当CSS更改时,它会刷新整个窗口.有没有可能让它热切换CSS而不刷新?
到目前为止的配置:
var webpackConfig = {
entry: ["webpack/hot/dev-server", __dirname + '/app/scripts/app.js'],
debug: true,
output: {
path: __dirname + '/app',
filename: 'scripts/build.js'
},
devtool: 'source-map',
plugins: [
new webpack.HotModuleReplacementPlugin(),
new htmlWebpackPlugin({
template: __dirname + '/app/index.html',
inject: 'body',
hash: true,
config: config
}),
new webpack.ProvidePlugin({
'angular': 'angular'
}),
new ExtractTextPlugin("styles.css")
],
module: {
loaders: [
{
test: /\.scss$/,
loader: "style!css!sass?includePaths[]=" + __dirname + "/app/bower_components/compass-mixins/lib&includePaths[]=" + __dirname + '/instance/sth/styles&includePaths[]=' + __dirname + '/app/scripts'
}
]
}
};
Run Code Online (Sandbox Code Playgroud) 给出以下代码:
module MyModule {
export interface IMyInterface {}
export interface IMyInterfaceA extends IMyInterface {}
export interface IMyInterfaceB extends IMyInterface {}
function(my: IMyInterface): void {
if (my instanceof IMyInterfaceA) {
// do something cool
}
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误"找不到名字IMyInterfaceA".处理这种情况的正确方法是什么?
我有一个场景,其中有两个组件并排放置,ComponentA 和 ComponentB。它们都使用服务 Service。
ComponentB 包含一个按钮,它将使 Service 中的一个属性 Service.counter 增加 1。
ComponentA 呈现 Service.counter 的值。
但是,当我使用 ChangeDetectionStrategy.OnPush 时,无论我尝试什么,我都无法更新 ComponentA 中的值,即使从我尝试过的根组件中也是如此:
this.cdr.markForCheck();
this.cdr.detectChanges();
this.ar.tick();
this.zone.run(() => {});
Run Code Online (Sandbox Code Playgroud)
无需对 ComponentA 进行更改,如何确保它始终显示正确的值?
(真实世界的情况是,有很多像ComponentA的组件都呈现翻译值,并且当所选语言更改时,我需要所有这些翻译的值相应地更新。我不想将侦听器建立在每个单个组件中从那里调用detectChanges)
使用promises,实现队列以防止例如并行运行多个HTTP请求非常容易:
class Runner {
private promise;
constructor(http) {
this.promise = q.resolve();
}
getUrl() {
return this.promise = this.promise.then(() => http.get('http://someurl'))
}
}
var runner = new Runner(http);
var lastPromise;
for (var i = 0; i < 10; i++) {
lastPromise = runner.getUrl();
}
lastPromise.then(() => console.log("job's done!");
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何在Rxjs中做到这一点.如果我尝试类似于上面的内容,那么当我添加请求时,所有先前的HTTP调用都会重复,因为它只是添加到流中并重新运行整个事务.
我读了一些关于队列调度程序的东西,但这似乎不再存在(不再)了?
我试图找到一个行为类似于 的运算符concatMap,但丢弃介于两者之间的所有内容。例如, concatMap 执行以下操作:
- 下一个
- 开始处理
- 下一个 b
- 下一个 c
- 完成处理一个
- 开始处理 b
- 完成处理 b
- 开始处理 c
- 完成处理 c
相反,我正在寻找一种会 drop 的机制b,因为c已经进来了:
- 下一个
- 开始处理
- 下一个 b
- 下一个 c
- 完成处理一个
- (跳过 b)
- 开始处理 c
- 完成处理 c
有关更扩展的示例,请参阅此要点:https : //gist.github.com/Burgov/afeada0d8aad58a9592aef6f3fc98543
我希望红色框位于第二行,但随后我希望在其后定义的div继续第一行,以便所有黑色框实质上都包裹在黑色框周围。Flexbox可以实现吗?
它看起来应该像这样:
+---+---+---+---+---+
| 1 | 2 | 3 | 5 | 6 |
+---+---+---+---+---+
| 4 |
+---+---+---+---+---+
| 7 | 8 | 9 |10 |11 |
+---+---+---+---+---+
|12 |13 |
+---+---+
Run Code Online (Sandbox Code Playgroud)
+---+---+---+---+---+
| 1 | 2 | 3 | 5 | 6 |
+---+---+---+---+---+
| 4 |
+---+---+---+---+---+
| 7 | 8 | 9 |10 |11 |
+---+---+---+---+---+
|12 |13 |
+---+---+
Run Code Online (Sandbox Code Playgroud)
* {
box-sizing: border-box;
}
.container {
display: flex;
flex-wrap: wrap;
}
.a {
border: 1px …Run Code Online (Sandbox Code Playgroud)我最近升级到了最新版本的@angular/fire,一切工作正常,但现在我已经从 compat 库迁移出去,现在我陷入了这个问题。我在以下代码中收到此错误:
Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp()。
// ...
import {getAuth, provideAuth} from '@angular/fire/auth';
import {getFirestore, provideFirestore} from '@angular/fire/firestore';
import {initializeApp, provideFirebaseApp} from '@angular/fire/app';
// ...
@NgModule({
// ...
providers: [
// ...
provideFirebaseApp(() => initializeApp(window['firebase_config'])),
provideFirestore(() => getFirestore()),
provideAuth(() => getAuth()),
// ...
],
// ...
})
export class ApModule {
// ...
}
Run Code Online (Sandbox Code Playgroud)
这是堆栈跟踪:
Error: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
at …Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的测试设置一些测试用例:
public IEnumerable<TestCaseData> size_tests()
{
yield return new TestCaseData(new string[] { "XS", "XL", "M" })
.Returns(new SortedVariantAttributeModel {
Values = new string[] { "XS", "M", "XL" },
PrimaryValue = "XS"
});
}
[Test, TestCaseSource("size_tests")]
public SortedVariantAttributeModel Should_map_SortedVariantAttributes(string[] sizes)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行此测试时,我得到:
测试失败 - Should_map_SortedVariantAttributes("XS","XL","M")
消息:提供的参数数量错误
从错误来看,它似乎解开了数组并尝试将其应用于测试函数,但这当然会导致问题。我该如何解决这个问题?
我需要创建一个包含大约 1GB 数据的 zip 文件(但该数量将来会增加)。最初我用 AdmZip 构建了这个,但由于我们的虚拟机没有大量内存(也不需要它,除了创建这个 zip 文件时,所以我不想扩展),它运行内存不足并崩溃。
然后,我重新构建了该流程以便使用命令行zip,但是在完成所有设置并将其发布到服务器之后,我必须艰难地找出该命令在 Azure WebApp 上不可用。
所以现在我需要再次重建它。谁能推荐我合适的节点库来在磁盘上而不是在内存中进行压缩和解压缩?
(zip 文件格式不是硬性要求,因此如果任何其他文件格式更适合此目的,我愿意接受建议!)
请看下面的代码:
interface X {
a: string;
b: number;
c: boolean;
}
type A = {
prop: keyof X;
value: X[keyof X];
}
const a: A = { prop: 'a', value: 'a' }; // ok
const b: A = { prop: 'a', value: 1 }; // not ok, value should be string, because X['a'] is string
const c: A = { prop: 'b', value: 1 }; // ok
const d: A = { prop: 'c', value: 1 }; // not ok, …Run Code Online (Sandbox Code Playgroud) 当Automapper将转换为对象的DateTime转换为字符串时,它将使用ToString()方法以文化定义的格式返回字符串。如何配置它,使其始终映射到ISO字符串?
var data = new Dictionary<string, object>
{
{ "test", new DateTime(2016, 7, 6, 9, 33, 0) }
};
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<DateTime, string>().ConvertUsing(dt => dt.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"));
});
var mapper = config.CreateMapper();
Assert.AreEqual("2016-07-06T07:33:00Z", mapper.Map<string>(data["test"]));
Assert.AreEqual("2016-07-06T07:33:00Z", mapper.Map<IDictionary<string, string>>(data)["test"]);
Run Code Online (Sandbox Code Playgroud)
第一个断言很好,但是第二个断言失败:
Result Message:
Expected string length 20 but was 17. Strings differ at index 0.
Expected: "2016-07-06T07:33:00Z"
But was: "6-7-2016 09:33:00"
-----------^
Run Code Online (Sandbox Code Playgroud) 我最近将 Bull 添加到我的项目中,以卸载诸如将文档同步到第三方服务之类的事情,一切都运行良好,除了处理作业时发生的错误不会最终出现在 Sentry 中。他们只登录作业本身,但由于我们在多个配置上运行应用程序,这意味着我必须不断监视所有这些实例是否存在作业处理错误。
我知道我可以向处理器添加错误处理程序,但我已经有很多处理器了,所以我更喜欢另一个更全局的解决方案
有什么方法可以确保这些错误也发送到 Sentry 吗?
我正在设置一个新的 NestJS 应用程序,我刚刚添加了 class-validator 以验证控制器输入,但它似乎被完全忽略了。这是 DTO:
import {IsString} from 'class-validator';
export class CreateCompanyDto {
@IsString()
name: string | undefined;
}
Run Code Online (Sandbox Code Playgroud)
这是控制器:
import {
Body,
Controller,
InternalServerErrorException,
Post,
Request,
UseGuards, ValidationPipe
} from '@nestjs/common';
import * as admin from 'firebase-admin';
import {User} from 'firebase';
import {AuthGuard} from '../auth/auth.guard';
import {CurrentUser} from '../auth/current-user.decorator';
import {CreateCompanyDto} from './dto/create-company.dto';
@Controller('vendor')
export class VendorController {
@Post()
@UseGuards(AuthGuard)
async create(@CurrentUser() user: User, @Request() req: any, @Body(new ValidationPipe({ transform: true })) company: CreateCompanyDto) {
console.log(JSON.stringify(company));
throw new …Run Code Online (Sandbox Code Playgroud) angular ×2
c# ×2
nestjs ×2
rxjs ×2
typescript ×2
angularfire2 ×1
automapper ×1
bullmq ×1
css ×1
css3 ×1
firebase ×1
flexbox ×1
html ×1
javascript ×1
node.js ×1
nunit ×1
sentry ×1
unit-testing ×1
unzip ×1
webpack ×1
zip ×1