TL; DR:
说明:
我正在使用DynamicComponentLoader的loadIntoLocation()函数动态创建Angular 2组件.
插入由此函数生成的组件的位置由其anchorName参数确定,该参数除了传递
Template Variable Name(作为字符串)之外.
所以在他们<div #child></div>在模板中使用的示例中,然后传递'child'.哪个工作正常.
但是,我不想将生成的组件链接到具有硬编码到模板中的变量名称的元素,而是希望能够将它们附加到可变大小的列表中.
现在,NgFor页面显示您可以访问索引变量:<li *ng-for="#item of items; #i = index">...</li>.所以它会工作,如果我可以分配这个指标或类似,即使用的列表项等模板变量名#child1,#child2等等.
所以我倾向于尝试<div #{{foo}}></div>使用app变量foo "child".我在调试时遇到了麻烦,因为前端并没有在DOM中真正显示这些模板变量名,但似乎这种动态分配失败,导致错误"Could not find variable ...".
可能有办法做我想做的事吗?甚至可以template variable name从浏览器中查看已分配的s进行调试?
我在VM中尝试Kafka(0.8.2.1),但是遇到了问题:虽然一切都很好,但机器仍然打开(即使我重新启动ZK/Kafka),如果我重新启动机器(优雅地关闭后)在ZK/Kafka看来,似乎所有Kafka主题都丢失了.
我可能在这里遗漏了一些基本的东西,因为这可能不应该发生.可能是什么?
cd /vagrant/kafka_2.11-0.8.2.1
bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 10 --topic foo
bin/kafka-topics.sh --list --zookeeper localhost:2181
# foo
# ^C then resume ZooKeeper, Kafka, or both
bin/kafka-topics.sh --list --zookeeper localhost:2181
# foo
# ^C both, reboot machine, boot ZK/Kafka again
bin/kafka-topics.sh --list --zookeeper localhost:2181
# no topics
Run Code Online (Sandbox Code Playgroud) 我有一个函数,并希望获取其参数类型和返回类型以供在Scala宏中使用.
scala> val fn = (a: String, b: Double) => 123
fn: (String, Double) => Int = <function2>
scala> fn.getClass
res1: Class[_ <: (String, Double) => Int] = class $anonfun$1
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,参数类型和返回类型已经在两行打印,但我不知道如何访问它们.即使toString我会坚持的<function2>,并class $anonfun$1在部分权=标志-否则有点难看字符串解析的可能已经完成.
我发现MethodSymbolApi提供了一种方法来提取方法的信息,但似乎这可能对这种特殊情况没有帮助.
我目前正在研究AST解析(作为其中的一部分scala.meta)来提取信息,但我认为这个问题看起来很基本,可以被标准反射库覆盖,尽管我没有在那里找到我想要的东西. .有任何想法吗?
根据@ johanandren的回答编辑:
我还没有找到一种更简洁的方法从TypeTag/Type中提取它们,但这确实有效.:)
scala> val fn = (a: String, b: Double) => 123
scala> import scala.reflect.runtime.{universe => ru}
scala> def getTypeTag[T: ru.TypeTag](obj: T) = ru.typeTag[T]
scala> getTypeTag(fn).tpe.toString.split(" => ")
res179: Array[String] = Array((String, …Run Code Online (Sandbox Code Playgroud) 我有一个使用Better Errors的Rails应用程序,但错误页面不会加载binding_of_caller交互式shell(REPL).相反,它仍然只显示:
Tip: add gem "binding_of_caller" to your Gemfile to enable the REPL and local/instance variable inspection.
Run Code Online (Sandbox Code Playgroud)
我的Gemfile有:
group :development, :test do
gem 'debugger'
gem 'better_errors'
gem 'binding_of_caller' #, :platforms=>[:mri_19, :mri_20, :rbx]
Run Code Online (Sandbox Code Playgroud)
我试过的最后一部分是注释还是未注释.在Rails控制台中尝试"require'binding_of_caller'"时,它返回false而不是错误,这意味着它已正确加载.Gemfile.lock显示以下版本:
rails (4.1.0.rc2)
better_errors (1.1.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
Run Code Online (Sandbox Code Playgroud)
可能有什么问题?我应该提供哪些其他代码才能找到出错的线索?
我正在尝试测试我的Angular 2组件,实例化new MyComponent().但是,对于采用@Inputs的组件,我如何通过?然后,如果实例化,说我想改变输入.这只是重新分配我传入的变量的问题吗?
背景:
我试图通过动态创建/组合Scala中的匿名函数的部分函数(case ...)来减少代码并改进Akka中的代码重用.
要创建这些部分函数,我需要访问函数的参数类型(使用类型参数T),但遗憾的是这受到类型擦除的影响.
我发现使用TypeTags或TypeClasses我可以处理它,这很好.但是,我不是一次一个地将我的功能转换为部分功能,而是希望批量使用.map().
然而,这似乎是失败的; 当通过地图使用该功能时,似乎突然变成T Nothing,导致我的功能功能失常(没有双关语意).
TL; DR:我可以得到lst(0)给String吗?
import scala.reflect.ClassTag
def fn = (s: String) => {}
def check[T](fn: T => Unit)(implicit ct: ClassTag[T]) = ct
check(fn)
//scala.reflect.ClassTag[String] = java.lang.String
val lst = List(fn).map(check)
lst(0)
//scala.reflect.ClassTag[Nothing] = Nothing
Run Code Online (Sandbox Code Playgroud)
对于Akka好奇,我的实际功能,而不是上述check():
def caseFn[T](fn: T => Unit)(implicit ct: ClassTag[T]): Actor.Receive = {
case ct(msg: T) => {
fn(msg)
}
}
Run Code Online (Sandbox Code Playgroud) 根据其文档,Haskell 的lens库_1为元组提供了一个镜头。
对于数据记录,还有其他几个功能,例如makeLenses,根据记录的字段名称自动生成镜头。
不幸的是,我正在处理没有命名字段的数据类,这makeLenses对我来说意味着意义。这让我感到奇怪。_1看起来很方便,但正如其文档中暗示的那样,似乎不适用于数据类。是否有同等程度的便利?
> :set -package lens
> import Control.Lens
> (1,2) ^. _1
1
> data Bar = Bar String deriving Show
> bar = Bar "abc"
> bar ^. _1
<interactive>:271:1: error:
• Non type-variable argument in the constraint: Field1 Bar Bar b b
(Use FlexibleContexts to permit this)
• When checking the inferred type
it :: forall b. Field1 Bar Bar b b => …Run Code Online (Sandbox Code Playgroud) 如果我理解正确[1],在Firebase中无法限制用户访问他们拥有的数据,也无法隐藏敏感列.在新发布的Firestore中这样更好吗?它有解决方法吗?
我能想到的另一种选择是通过云功能路由此类请求,以便根据需要进行过滤,而不是允许直接访问.可能有用吗?
[1] 使用安全规则限制子/域访问
在Scala中,我正在尝试:
import scala.reflect.runtime.{universe => ru}
def foo[T <: Any]: ru.WeakTypeTag[T] = ru.weakTypeTag[String]
Run Code Online (Sandbox Code Playgroud)
但这让我产生了:
<console>:34: error: type mismatch;
found : reflect.runtime.universe.WeakTypeTag[String]
required: reflect.runtime.universe.WeakTypeTag[T]
def foo[T <: Any]: ru.WeakTypeTag[T] = ru.weakTypeTag[String]
Run Code Online (Sandbox Code Playgroud)
什么在这里?我相对肯定String应该满足T派生的类型约束Any...
我想String无法绑定到Ttype参数.在我的用例中,其他类型也可以返回,但我不确定如何在执行函数之前预先得到编译器的答案,如果这是它所期望的.
在 Haskell 中,我想计算给定参数类型的给定函数的返回类型。所以对于例如带有签名a -> a和参数类型的函数Bool,我想获得返回类型Bool。现在,这有效:
-- $ ghci -XScopedTypeVariables
> import Test.QuickCheck
> import Data.Typeable
> fn = id
> param :: Bool <- generate arbitrary
> typeOf $ fn param
Bool
Run Code Online (Sandbox Code Playgroud)
但是,如果目标只是获取其返回类型,那么必须实例化参数类型然后执行该函数感觉有点大材小用。
我想,知道 param type Bool,我们就会知道类型变量a也会变成Bool,因此我们也可以在返回类型中替换它a,以获得返回类型Bool。
有没有办法动态获取这样的函数返回类型而不必求助于执行函数?
haskell ×3
scala ×3
angular ×2
generics ×2
akka ×1
apache-kafka ×1
firebase ×1
haskell-lens ×1
lenses ×1
monads ×1
reflection ×1
scala-macros ×1
type-erasure ×1