小编Seb*_*ber的帖子

make和不必要的回调创建和分配(initialState ...)?

我不懂make工作的方式:

let component = ReasonReact.reducerComponent("Greeting");

let make = (~name, _children) => {
  ...component,
  initialState: () => 0, /* here, state is an `int` */
  render: (self) => {
    let greeting =
      "Hello " ++ name ++ ". You've clicked the button " ++ string_of_int(self.state) ++ " time(s)!";
    <div>{ReasonReact.stringToElement(greeting)}</div>
  }
};
Run Code Online (Sandbox Code Playgroud)

据我所知,make每次<Greeting>在父组件渲染方法中使用组件时都会调用它,因此它将被多次调用.

但这也意味着组件记录会创建多倍的initialState功能吗?

我不明白initialState每次创建React元素时分配一些函数是有意义的,而只有在元素被挂载时才会调用它,并且对更新没有影响.

initialState举一个例子,但也可以对其他生命周期回调也一样.

ocaml reason reason-react

2
推荐指数
1
解决办法
281
查看次数

JEE6如何在Observer和Observee之间建立联系(观察者模式)

我已经阅读了一些关于JEE6上Observer模式实现的博客文章,还有什么困扰我......我找不到任何信息,所以我问那里......

我发现了以下例子:

@Stateless
[...]
public class ParisJugService {

   @Inject
   Event event;

   public void helloParis(){
        System.out.println("Hello Paris");
        event.fire("hello Paris invoked!");
   }
}

@Stateless
public class EventReceiver {

    public void onHelloParis(@Observes String message){
        System.out.println("----------- " + message);
    }
}
Run Code Online (Sandbox Code Playgroud)

public class MyEvent {
    String data;
    Date eventTime;
    ....

}

public class EventProducer {

  @Inject @Any Event<MyEvent> event;


  public void doSomething() {
       MyEvent e=new MyEvent();
      e.data="This is a test event";
      e.eventTime=new Date();
      event.fire(e);

  }

}


public class EventConsumer {


    public void afterMyEvent(@Observes …
Run Code Online (Sandbox Code Playgroud)

java ejb cdi java-ee-6 ejb-3.1

1
推荐指数
1
解决办法
1782
查看次数

使用apply调用console.log

我正在尝试创建一个日志代理,其中每个日志语句都有一个前缀.

我想要做的是:

customDebug("xxx","yyy");
Run Code Online (Sandbox Code Playgroud)

在木头下它会做:

console.debug("prefix","xxx","yyy");
Run Code Online (Sandbox Code Playgroud)

我试过这样实现它:

prefixLogArguments: function(arg) {
    var array = _.toArray(arg);
    array.unshift( this.getPrefix() );
    return array;
},

customDebug: function() {
    var argArray = this.prefixLogArguments(arguments);
    console.debug.apply(undefined, argArray );
},
Run Code Online (Sandbox Code Playgroud)

它说Uncaught TypeError: Illegal invocation 因为看起来我们无法apply/call使用未定义的上下文调用本机代码.

有人能告诉我如何实现这一目标吗?

我可以做到console.debug(argArray);这一点并不是那么糟糕,但它不会产生与记录数组而不是记录参数列表相同的结果.

javascript

1
推荐指数
1
解决办法
581
查看次数

Flexbox行:根据内容不增长?

我有以下结构,我想了解为什么我的行不会随其内在内容而增长.

.row {
  border:solid red;
  display: flex;
  flex-direction: row;
}


.cell {
  border: solid green;
  flex: 0 0 400px;
}
Run Code Online (Sandbox Code Playgroud)
<div class="row">
  <div class="cell">
   cell 1
  </div>
  <div class="cell">
   cell 2
  </div>
  <div class="cell">
   cell 3
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

的jsfiddle

我不希望细胞生长或收缩,它们应该总是400px宽.父进程应该增长并溢出窗口,并且预计会出现水平滚动条.

在上面的示例中,红色边框应位于绿色边框周围.绿色边框具有预期尺寸,而不是红色边框.

出于与我的用例相关的可维护性原因,我不想为我的行设置静态宽度.

我对非flexbox解决方案持开放态度(参见内联块尝试),但会更喜欢一个flexbox(因为我需要align-items: center行上的行为)

css css3 flexbox

1
推荐指数
1
解决办法
376
查看次数

SBT不想输入我的项目(使用项目命令)

我的构建很简单:

  lazy val stampleWebProject = play.Project("stample-web", appVersion, appDependencies,path = file("stample-web"))
    .dependsOn(stampleCoreProject,stampleSearchProject)
    .aggregate(stampleCoreProject,stampleSearchProject)

  lazy val stampleCoreProject = Project(id = "stample-core",base = file("stample-core"))

  lazy val stampleSearchProject = Project(id = "stample-search",base = file("stample-search"))
Run Code Online (Sandbox Code Playgroud)

所有这些项目都有一个带有依赖项的build.sbt文件,没有任何scala构建(据我所知将被忽略)

启动SBT(12.4)时,我得到以下信息:

[info] Set current project to stample-core (in build file:/home/sebastien/Bureau/Stample/)

> projects
[info] In file:/home/sebastien/Bureau/Stample/
[info]   * stample-core
[info]     stample-search
[info]     stample-web

> project stample-search
[info] Set current project to stample-search (in build file:/home/sebastien/Bureau/Stample/)

> projects
[info] In file:/home/sebastien/Bureau/Stample/
[info]     stample-core
[info]   * stample-search
[info]     stample-web

> project stample-core …
Run Code Online (Sandbox Code Playgroud)

scala sbt

0
推荐指数
1
解决办法
2243
查看次数

为什么Guava InputSupplier/OutputSupplier不扩展供应商界面?

我的用例是能够在不创建文件的情况下创建FileOutputStream.所以我创建了这个基于Guava的OutputStream:

public class LazyInitOutputStream extends OutputStream {

  private final Supplier<OutputStream> lazyInitOutputStreamSupplier;

  public LazyInitOutputStream(Supplier<OutputStream> outputStreamSupplier) {
    this.lazyInitOutputStreamSupplier = Suppliers.memoize(outputStreamSupplier);
  }

  @Override
  public void write(int b) throws IOException {
    lazyInitOutputStreamSupplier.get().write(b);
  }

  @Override
  public void write(byte b[]) throws IOException {
    lazyInitOutputStreamSupplier.get().write(b);
  }

  @Override
  public void write(byte b[], int off, int len) throws IOException {
    lazyInitOutputStreamSupplier.get().write(b,off,len);
  }


  public static LazyInitOutputStream lazyFileOutputStream(final File file) {
    return lazyFileOutputStream(file,false);
  }

  public static LazyInitOutputStream lazyFileOutputStream(final File file,final boolean append) {
    return new LazyInitOutputStream(new Supplier<OutputStream>() {
      @Override
      public OutputStream …
Run Code Online (Sandbox Code Playgroud)

java guava

0
推荐指数
1
解决办法
205
查看次数

函数式递归与番石榴?

我有一个基本实现的MyService接口MyServiceImpl.我将其包装MyServiceImpl成一系列MyService装饰器.

为此,我创建了MyServiceDelegate一个抽象类,它接受一个MyService实例并将所有服务调用委托给提供的MyService实例.

但是在我的单元测试中,对于特定需求,我需要找回第一个真正的实现MyService,即MyServiceImpl,我只有一个MyService引用装饰器.

我只是想知道是否可以使用Guava,以功能性的方式进行递归,这将返回我已经装饰了很多层并且不是委托服务的"原始服务".我想使用像Function这样的函数来返回委托服务,如果是原始服务,则使用null,但不知道是否使用它.

我知道我可以通过while循环轻松完成,而且我不是在寻找替代解决方案.只想知道番石榴是否可以解决这些问题.

java recursion functional-programming guava

-1
推荐指数
1
解决办法
452
查看次数