所以在这个应用程序中,我使用的是MediaRecorder api(https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder).我试图使用React-Redux作为网站的框架.以下是我的reducer的简化版本来说明我的问题:
(state = {}, action) => {
switch(action.type){
case "START_RECORDING":
return new MediaRecorder(...).start();
case "STOP_RECORDING":
state.stop(); <--- is this ok?
return {};
}
return state;
})
Run Code Online (Sandbox Code Playgroud)
所以我读到redux状态应该是不可变的.但是,我必须以某种方式停止媒体录制器,以便它停止录制内容.这样state.stop() 好吗?
我一直在尝试 div 溢出。我遇到了 div 未“正常”显示的问题。这是一个简单的 HTML 和 CSS,我希望有人能解释我的问题吗?
我期望这些框显示在同一行中。
<div class='content'>
<div class='box'>
hihi
</div>
<div class='box'>
</div>
</div>
...
Run Code Online (Sandbox Code Playgroud)
所以我在http://www.typescriptlang.org/play/上玩弄打字稿.发现我们实际上可以执行以下操作直接获取对象的属性/数组元素.
例:
function([first: int, second: int]): int{
return first + second;
}
function([first: any, person: {name: string}]): string{
return name;
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法在网上找到有关这种"模式匹配"特征的任何地方.(我喜欢模式匹配;还有haskell.)
这个功能非常强大.我想知道他们在打字稿中叫什么.这样我就可以进一步阅读.
提前致谢.
我知道 async 不是并行的,但我现在遇到了一个非常有趣的情况。
async function magic(){
/* some processing here */
await async () => await prompt_for_user(); // 1st prompt
await async () => await prompt_for_user(); // 2nd prompt
}
magic(); // first
magic(); // second
magic(); // third
Run Code Online (Sandbox Code Playgroud)
从上面的程序中,我们可以很容易地预测出所有提示同时弹出。我尝试使用具有以下实现的队列来解决它:
const Queue = () => {
let promise;
return async (f) => {
while(promise) await promise;
promise = f();
const res = await promises;
promise = undefined;
return res;
};
};
const queue = Queue();
async function magic(){
/* some …Run Code Online (Sandbox Code Playgroud) asynchronous ×1
css ×1
html ×1
javascript ×1
node.js ×1
promise ×1
react-redux ×1
redux ×1
typescript ×1