我有一个使用React& amp;的电子应用程序。 Redux,所以我有动作创作者,减少者等。
我的渲染器文件(nodejs)中也有一个函数可以执行一些异步操作。
我想从我的动作创建者中调用此函数。我想我将不得不为此或其他异步库使用redux-thunk,但是,我不太确定如何在渲染器进程中访问此函数并在我的react.redux应用程序中使用它?
所以,例如对于动作创建者:
export const downloadFromYoutube = (download) => {
//I want to call the function here
};
我的渲染器文件只包含这一个执行异步操作的函数:
var YoutubeMp3Downloader = require('youtube-mp3-downloader');
function downloadFromYoutube() {
console.log("Hello");
//Configure YoutubeMp3Downloader with y our settings
var YD = new YoutubeMp3Downloader({
"ffmpegPath": "/usr/local/Cellar/ffmpeg/3.2.2/bin/ffmpeg", // Where is the FFmpeg binary located?
"outputPath": "/Users/dominik/Coding/youtube-downloader-papa/downloads/", // Where should the downloaded and encoded files be stored?
"youtubeVideoQuality": "highest", // What video quality should be used?
"queueParallelism": 2, // How many parallel downloads/encodes should be started?
"progressTimeout": 2000 // How long should be the interval of the progress reports
});
console.log("Downloading");
//Download video and save as MP3 file
YD.download("jhjPSj-qnyg");
YD.on("finished", function(data) {
console.log(data);
});
YD.on("error", function(error) {
console.log(error);
});
YD.on("progress", function(progress) {
console.log(progress);
});
}
}