小编Tre*_*ama的帖子

跟Go的Appengine:是否有一个http.Handle prehook或类似的东西?

假设我有以下init函数路由请求.

func init() {
    http.HandleFunc("/user", handler1)
    http.HandleFunc("/user/profile", handler2)
    http.HandleFunc("/user/post", handler3)
    ....
    ....
}
Run Code Online (Sandbox Code Playgroud)

所有这些都要求我拥有用户的个人资料.

我知道我可以

func handler1(w http.ResponseWriter, r *http.Request) {
    getUserdata()
    //Actual handler code
    ...
    ...
}
Run Code Online (Sandbox Code Playgroud)

但是,有没有一种方法可以在不将函数调用放入每个处理程序的情况下获取数据?这首先是Go会要求你做的事情吗?

google-app-engine go

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

如何在 Ember 中的组件上测试计算属性?

我有一个组件,foo-table我正在传递一个名为myList. 我正在对列表进行排序的组件上设置计算属性。见下文:

// app/components/foo-table.js
export default Component.extend({
  sortedList: computed('myList', function foo() {
    const myList = this.getWithDefault('myList', []);
    return myList.sortBy('bar');
  }),
});
Run Code Online (Sandbox Code Playgroud)

如何编写测试以确保计算属性已排序?这是我到目前为止:

// tests/integration/foo-table-test.js
const MY_LIST = ['foo', 'bar', 'baz']

test('it renders company industry component', function (assert) {
  this.set('myList', MY_LIST);

  this.render(hbs`
    {{foo-table myList=myList}}
  `);

  // TODO
  assert.equal(true, false);
});
Run Code Online (Sandbox Code Playgroud)

integration-testing ember.js

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