tl; dr:基本上我想将Angular ngOnDestroy
与Rxjs takeUntil()
运算符结合起来. - 那可能吗?
我有一个Angular组件,可以打开几个Rxjs订阅.当组件被销毁时,需要关闭它们.
一个简单的解决方案是:
class myComponent {
private subscriptionA;
private subscriptionB;
private subscriptionC;
constructor(
private serviceA: ServiceA,
private serviceB: ServiceB,
private serviceC: ServiceC) {}
ngOnInit() {
this.subscriptionA = this.serviceA.subscribe(...);
this.subscriptionB = this.serviceB.subscribe(...);
this.subscriptionC = this.serviceC.subscribe(...);
}
ngOnDestroy() {
this.subscriptionA.unsubscribe();
this.subscriptionB.unsubscribe();
this.subscriptionC.unsubscribe();
}
}
Run Code Online (Sandbox Code Playgroud)
这有效,但有点多余.我特别不喜欢那样 - 这unsubscribe()
是其他地方,所以你必须记住这些是相互关联的. - 组件状态受订阅污染.
我更喜欢使用takeUntil()
运算符或类似的东西,使它看起来像这样:
class myComponent {
constructor(
private serviceA: ServiceA,
private serviceB: ServiceB,
private serviceC: ServiceC) {}
ngOnInit() {
const destroy = Observable.fromEvent(???).first();
this.subscriptionA …
Run Code Online (Sandbox Code Playgroud) 我怎么能在Clojure中验证是否对数字列表进行了排序?
(def my-list (list 1 2 3 1 4 2 2 4))
Run Code Online (Sandbox Code Playgroud)
sorted?
仅当集合实现sorted
接口时才返回true .我正在寻找一种reduce
可以成对迭代列表的操作,例如(reduce < my-list)
.我知道我可以手动创建对并比较这些:
(letfn [(pair [l] (if (= (count l) 2) (list l) (cons (take 2 l) (pair (rest l)))))]
(every? #(apply < %) (pair my-list)))
Run Code Online (Sandbox Code Playgroud)
但这似乎不必要地复杂.在我看来,好像我错过了一个基本功能.
我写了一个虚拟模块my-component,它基本上导出了一个单独的Something类.我把它放在app/modules /中.现在我想用app/app.js中的导入语法来访问它:
import { Something } from 'my-component';
Run Code Online (Sandbox Code Playgroud)
期望:使用我当前的Webpack配置(下面),我希望这可以工作.
实际:这会抛出错误:
ERROR in [default] /<project_dir>/app/app.ts:1:26
Cannot find module 'my-component/Something'.
Run Code Online (Sandbox Code Playgroud)
我知道模块本身是正确定义的,因为
import { Something } from './my-component'
node_modules/my-component
.唯一失败的组合是导入它而没有来自我的modules /目录的相对路径.所以我认为问题可能是我的Webpack配置.
如下所示,我有两个目录列为resolve.root:
project_dir/app
project_dir/node_modules
它似乎设法解决node_modules
,而不是来自app
.
项目布局
Webpack
project_dir/
??? app/ context, resolve.root
? ??? app.ts
? ??? my-component/
? ??? index.ts
? ??? Something.ts
??? webpack.config.js
??? node_modules/ resolve.root …
Run Code Online (Sandbox Code Playgroud) 我有以下代码:
class SuperClass {
public static String getName() { return "super"; }
}
class SubClass extends SuperClass {
public static String getName() { return "sub"; }
}
public class Dummy<T extends SuperClass> {
public void print() {
System.out.println("SuperClass: " + SuperClass.getName());
System.out.println("SubClass: " + SubClass.getName());
System.out.println("T: " + T.getName());
}
public static void main(String[] args) {
new Dummy<SubClass>().print();
}
}
Run Code Online (Sandbox Code Playgroud)
此代码输出以下内容:
SuperClass: super
SubClass: sub
T: super
Run Code Online (Sandbox Code Playgroud)
我的问题是:为什么T.getName()不返回SubClass.getName()的值?毕竟,我指定了T == SubClass.或者静态函数调用对于泛型引用是否无效?
非常感谢提前!
我正在使用scrbook包编写Latex文档.
\documentclass[12pt,a4paper,oneside]{scrbook}
\pagestyle{plain}
Run Code Online (Sandbox Code Playgroud)
页码始终显示在页脚的中心.如何让它在右边对齐?我试过几次找到它的文档中,但说实话,我不完全理解,我的截止时间就是现在.
alignment ×1
angular ×1
clojure ×1
components ×1
extends ×1
generics ×1
import ×1
inheritance ×1
java ×1
javascript ×1
latex ×1
list ×1
module ×1
rxjs ×1
rxjs5 ×1
sorted ×1
static ×1
typescript ×1
webpack ×1