Created
January 11, 2011 21:27
-
-
Save jbr/775181 to your computer and use it in GitHub Desktop.
in response to recent nodejs post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In response to this idiom | |
// (code copied from https://groups.google.com/d/topic/nodejs/wzSUdkPICWg/discussion): | |
mainWindow.menu("File", function(err, file) { | |
if (err) throw err; | |
file.openMenu(function(err, menu) { | |
if (err) throw err; | |
menu.item("Open", function(err, item) { | |
if (err) throw err; | |
item.click(function(err) { | |
if (err) throw err; | |
mainWindow.getChild(type('Window'), function(err, dialog) { | |
if (err) throw err; | |
//... | |
}); | |
}); | |
}); | |
}); | |
}); | |
// Here's a little helper function that simplifies that `if (err) throw err;` noise: | |
var throwErrors = function( fn ) { | |
return function( err, args ) { | |
if ( err ) throw err; | |
return fn.apply( this, Array.prototype.slice.call( arguments, 1 )); | |
}; | |
} | |
mainWindow.menu( "File", throwErrors( function( file ) { | |
file.openMenu( throwErrors( function( menu ) { | |
menu.item( "Open", throwErrors( function( item ) { | |
item.click( throwErrors( function() { | |
mainWindow.getChild( type( 'Window' ), throwErrors( function( dialog ) { | |
//... | |
})); | |
})); | |
})); | |
})); | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment