这是我的代码。https://stackblitz.com/edit/angular-tq2vaa
constructor(private host: ElementRef) {
}
get element() {
return this.host.nativeElement;
}
private editModeHandler() {
const clickOutside$ = fromEvent(document, 'click').pipe(
filter(({ target }) => {
console.log('parent', this.element, 'child', target)
const ans = this.element.contains(target) === false
console.log(ans)
return ans
}),
take(1)
)
}
Run Code Online (Sandbox Code Playgroud)
这是它在控制台中打印的内容。正如你所看到的,app-editable-component 包含 h3,它是目标,但为什么 ans 是 true???
我有这个代码:
public class Compiler {
public void compile(String template, Object o, Object params) {
//...
context(o, params);
//...
}
private void context(Object o, Object params) {
//...
substitue(o, params);
//...
}
private void substitue(Object o, Object params) {
//...
print(params);
//...
}
private void print(Object params) {//use parameter params here, only here
//...
System.out.println(params);
//...
}
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,该参数params
仅在方法中使用print
,而不是在compile
,context
或 中使用substitue
。问题是将 添加params
到所有方法的签名中,直至print
。
一般来说,当我遇到这个问题时,我会重构我的代码,如下所示:
public class Compiler {
public …
Run Code Online (Sandbox Code Playgroud) 我有一个简单的比较器,它通过日期和时间字段比较Action对象:
static final Comparator<Action> COMPARATOR = comparing(Action::date,
nullsLast(naturalOrder())).thenComparing(Action::time,
nullsLast(naturalOrder()));
Run Code Online (Sandbox Code Playgroud)
结果示例如下所示:
{hour: 01/01/2019, time: 15:55}
{hour: 01/01/2019, time: null}
{hour: 03/01/2019, time: 11:11}
{hour: 08/01/2019, time: 11:11}
{hour: 08/01/2019, time: null}
{hour: null, time: null}
{hour: null, time: null}
Run Code Online (Sandbox Code Playgroud)
比较器需要再包含三个字段。nullsLast(naturalOrder())
每次重复都让我无休止。
在不使用第三方库的情况下,如何简化比较器的使用?
我有这个 Rxjs 测试代码。它故意失败,因为我想向您展示失败的日志。我发现这很难理解,或者至少我不能流利地阅读它。
有人可以解释我什么意思:$[i].frame = i' to equals i''
?
import { delay } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';
describe('Rxjs Testing', () => {
let s: TestScheduler;
beforeEach(() => {
s = new TestScheduler((actual, expected) => {
expect(actual).toEqual(expected);
});
});
it('should not work', () => {
s.run(m => {
const source = s.createColdObservable('-x-y-z|');
const expected = '-x-y-z|'; // correct expected value is '---x-y-z|'
const destination = source.pipe(delay(2));
m.expectObservable(destination).toBe(expected);
});
});
});
Run Code Online (Sandbox Code Playgroud)
我已经按照几篇文章使用 java 类创建 zip 文件ZipOutputStream
。zip 已创建,但我无法打开它。在我的 Mac 上,当我使用以下命令打开它时,我收到此消息unzip
:
未找到中央目录结尾签名。该文件要么不是 zip 文件,要么构成多部分存档的一张磁盘。在后一种情况下,中央目录和 zip 文件注释将在此存档的最后一个磁盘上找到。
unzip: 在 /Users/xxxx/Downloads/iad.zip 或 /Users/xxxx/Downloads/iad.zip.zip 之一中找不到 zipfile 目录
,并且找不到 /Users/xxxx/Downloads/iad.zip.ZIP,期间。
我的java课程:
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import static java.util.Arrays.stream;
@Slf4j
@UtilityClass
public class ZipCreator {
public byte[] compressAll(String... files) throws IOException {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zipOut = new ZipOutputStream(baos)) {
stream(files)
.forEach(file -> addToZip(zipOut, file));
return …
Run Code Online (Sandbox Code Playgroud) java ×4
rxjs ×2
angular ×1
comparator ×1
dom ×1
java-8 ×1
java-stream ×1
refactoring ×1
rxjs-marbles ×1
rxjs6 ×1
testing ×1
typescript ×1
zip ×1