小编Ron*_*ere的帖子

等待最后一条指令有用吗

我看到了下面的代码,想知道除了强制该方法具有关键字之外async,在最后一条指令上指定等待是否有用?例子

async example(){
  //... whatever code

  //Last instruction
  await functionReturningAPromise()
}
Run Code Online (Sandbox Code Playgroud)

请注意,在这里我怀疑退货丢失了,但即使有退货,我的问题仍然存在。

async example(){
  //... whatever code

  //Last instruction
  return await functionReturningAPromise() //Is this useful ? or should we return directly
}
Run Code Online (Sandbox Code Playgroud)

我个人认为没有真正的兴趣。

javascript function promise async-await ecmascript-6

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

GWT MVP更新地方变更的活动状态

在地方变更上更新活动状态的最佳做法是什么?想象一下,您有一个带有视图的活动,该活动显示类别列表和类别中的项目列表.如果选择了不同的类别,则应用程序将转到具有类别ID的新位置.我想要只刷新项目,而不是创建也重新读取类别列表的新活动.

我目前的做法是这样的:

public class AppActivityMapper implements ActivityMapper {

    private ItemListActivity itemListActivity;

    ...

    public Activity getActivity(final Place place) {
        final Activity activity;

        if (place instanceof ItemListPlace) {
            if (itemListActivity == null) {
                itemListActivity = new ItemListActivity((ItemListPlace) place, clientFactory);
            } else {
                itemListActivity.refresh((ItemListPlace) place);
            }
            activity = itemListActivity;
        } else {
            itemListActivity = null;
        }

        ...
        return activity;
    }

    ...
Run Code Online (Sandbox Code Playgroud)

mvp gwt gwt-mvp gwt-activities gwt-places

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

Stub es6 getter setter 与 sinon

如果您对 getter/setter 使用以下 es6 语法

class Person {
  constructor(name) {
    this._name = name;
  }

  get name() {
    return this._name.toUpperCase();
  }

  set name(newName) {
    this._name = newName;
  } 
}
Run Code Online (Sandbox Code Playgroud)

您将如何存根 getter 方法?

const john = new Person('john')
sinon.createSandbox().stub(john, 'name').returns('whatever')
Run Code Online (Sandbox Code Playgroud)

似乎不起作用。

javascript sinon ecmascript-6

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