? .then(result)=>{?

Hello ,
I am getting an error here : }).then(result)=>{
“Malformed arrow function”
How do I fix it ?
Thanks

  ipcMain.handle('openBtn' , (event) => { 
  console.log("ipcMain.handle('openBtn' , (event)=>")
  dialog.showOpenDialog({
	  defaultPath:app.getPath("desktop") ,
	  buttonLabel:'Select File To Edit'
  }).then(result)=>{
    console.warn("result = ", result)
  };
  });

Here is the oart of the code having trouble:

Let’s clear out the then section, and start over.

  }).then();

The arrow-notation that you are wanting to use, has a result parameter:

(result) => {
    console.warn("result = ", result);
}

and we can now put that arrow-notation inside of the then part.

  }).then((result) => {
    console.warn("result = ", result);
});

I think you are missing a left and right parenthesis…

  ipcMain.handle('openBtn' , (event) => { 
	  console.log("ipcMain.handle('openBtn' , (event)=>")
	  dialog.showOpenDialog({
		  defaultPath:app.getPath("desktop") ,
		  buttonLabel:'Select File To Edit'
	  }).then((result) => { console.warn("result = ", result) }); //<-- Notice the addition of the two parenthesis
  });

Notice the left parenthesis before “result” and then the one after the second to last closing curly brace. (result) => is the parameter to your arrow function and the last ) is to finish off the then clause.

Now this isn’t to say all this will make everything magically work, but that should at least put you into syntax compliance.

Ah…Perfect , Thank you’s very much !

This is what I get back from
}).then((result) => { console.warn("result = ", result) });

result = {
canceled: false,
filePaths: [ ‘C:\Users\vmars\Desktop\myStuff\openBtn.txt’ ]
}

Any ideas how I can get hold of this part:
C:\\Users\\vmars\\Desktop\\myStuff\\openBtn.txt
Thanks

result.filePaths[0] (though… if we’re explaining basic object accessors, perhaps you’re in a bit over your head using asynchronous callback lambda functions.)

Thanks to you’s ,
Oops , I missed this :
filePaths String[] - An array of file paths chosen by the user. If the dialog is cancelled this will be an empty array.
didn’t realize it is an array .

gotta keep your eyes peeled when it comes to condensed syntax like object notation. Soon as you see a [, you’re talking about an array.

To help alleviate such issues, I find that it helps to extract named functions.

For example:

  const dialogConfig = {
    defaultPath:app.getPath("desktop"),
    buttonLabel:'Select File To Edit'
  };
  const logResult = (result) => console.warn("result = ", result);

  ipcMain.handle('openBtn' , (event) => { 
    console.log("ipcMain.handle('openBtn' , (event)=>")
    dialog.showOpenDialog(dialogConfig).then(logResult);
  });
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.