Angular dart 中的对象 runtimeType
Object runtimeType in Angular dart
我有一个组件,它提供了一个模型对象,这个模型对象可以有几种类型,它是什么类型决定了将在里面渲染什么组件:
<div [ngSwitch]="poolModel.runtimeType.toString()">
<template ngSwitchCase="CryptonoteMiningPool"><cryptonote-pool [model]="poolModel"></cryptonote-pool></template>
<template ngSwitchCase="DaggerHashimotoMiningPool"><dag-hash-pool [model]="poolModel"></dag-hash-pool></template>
</div>
这在调试模式下效果很好,但是一旦我编译发布运行时类型总是 returns "fS".
我有一个解决方案,本质上是在模型中设置一个常量并查看它,但如果我能避免的话,我宁愿没有这样的麻烦,因为我最终可能会维护多种类型的模型。
有没有办法让 runtimeType return 在发布模式下符合我的预期?
运行时类型不是我用于程序逻辑的东西。它根据编译器选项而变化,实际上即使使用它也会使您的应用程序(在 dart2js 中)的优化变得更加困难。
我们在 dart2js 性能指南中禁止使用它。
你最好创建某种基础 class:
abstract class DynamicRender {
String get renderType;
}
让你的 classes extend/mix/implement 改用它。
我有一个组件,它提供了一个模型对象,这个模型对象可以有几种类型,它是什么类型决定了将在里面渲染什么组件:
<div [ngSwitch]="poolModel.runtimeType.toString()">
<template ngSwitchCase="CryptonoteMiningPool"><cryptonote-pool [model]="poolModel"></cryptonote-pool></template>
<template ngSwitchCase="DaggerHashimotoMiningPool"><dag-hash-pool [model]="poolModel"></dag-hash-pool></template>
</div>
这在调试模式下效果很好,但是一旦我编译发布运行时类型总是 returns "fS".
我有一个解决方案,本质上是在模型中设置一个常量并查看它,但如果我能避免的话,我宁愿没有这样的麻烦,因为我最终可能会维护多种类型的模型。
有没有办法让 runtimeType return 在发布模式下符合我的预期?
运行时类型不是我用于程序逻辑的东西。它根据编译器选项而变化,实际上即使使用它也会使您的应用程序(在 dart2js 中)的优化变得更加困难。
我们在 dart2js 性能指南中禁止使用它。
你最好创建某种基础 class:
abstract class DynamicRender {
String get renderType;
}
让你的 classes extend/mix/implement 改用它。