我正在测试这个减速器:
const todo = (state = {}, action) => {
switch(action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
}
case 'TOGGLE_TODO':
if(state.id !== action.id) {
return state;
}
return {...state, completed: !state.completed};
default:
return state;
}
}
const todos = (state = [], action) => {
switch(action.type) {
case 'ADD_TODO':
return [
...state,
todo(undefined, action)
]
case 'TOGGLE_TODO':
return state.map(item => todo(item, action));
default:
return state;
}
}
export default todos;
Run Code Online (Sandbox Code Playgroud)
通过这个测试:
import todos from './todos'; …Run Code Online (Sandbox Code Playgroud) 我发现我无法调用async函数$.proxy.我的情况是我代理了事件监听器,以便它们仍然具有相同的上下文,但是一旦我尝试代理一个async函数,它就没有被调用 - 而且,没有抛出任何错误.
任何人都可以解释为什么这不起作用?
下面的简单示例将允许您重现该问题.当async关键字存在时,将不会调用该函数.当你删除时async,它将开始工作.
$('div').on('click', $.proxy(example, this));
async function example() {
console.log('test');
}
Run Code Online (Sandbox Code Playgroud) 我应该如何编写导航栏,并考虑到语义?
我被建议将所有内容嵌套header,然后嵌入链接nav,但我不认为这是正确的方法.
<header>
<h3>Developer's Blog</h3>
<nav>
<a href="#">About</a>
<a href="#">Contact</a>
<a href="#">Press</a>
</nav>
</header>
Run Code Online (Sandbox Code Playgroud)
要么
<nav>
<h3>Developer's Blog</h3>
<div>
<a href="#">About</a>
<a href="#">Contact</a>
<a href="#">Press</a>
</div>
</nav>
Run Code Online (Sandbox Code Playgroud)
哪一个是正确的?
async-await ×1
asynchronous ×1
html5 ×1
javascript ×1
jestjs ×1
jquery ×1
navbar ×1
phone-number ×1
redux ×1
standards ×1
unit-testing ×1