Skip to content

Instantly share code, notes, and snippets.

@tristaaan
Created February 17, 2016 23:31
Show Gist options
  • Save tristaaan/ae71ca9f9bfbb0bfa982 to your computer and use it in GitHub Desktop.
Save tristaaan/ae71ca9f9bfbb0bfa982 to your computer and use it in GitHub Desktop.
//react 0.14.7
saveModel() {
this.downloadFile(JSON.stringify(this.props.data, null, ' '));
},
downloadFile(contents) {
var newFileContent = new Blob([contents], {type: 'application/octet-binary'}),
downloadURL = window.URL.createObjectURL(newFileContent),
downloadLink = document.getElementById('file-download-link');
downloadLink.href = downloadURL;
downloadLink.download = this.props.data.type + '.json';
downloadLink.click();
// Free memory
setTimeout(function(){
window.URL.revokeObjectURL(downloadURL);
}, 1000);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment