Skip to content

Instantly share code, notes, and snippets.

@tristaaan
Created February 17, 2016 23:31
Show Gist options
  • Select an option

  • Save tristaaan/ae71ca9f9bfbb0bfa982 to your computer and use it in GitHub Desktop.

Select an option

Save tristaaan/ae71ca9f9bfbb0bfa982 to your computer and use it in GitHub Desktop.

Revisions

  1. tristaaan created this gist Feb 17, 2016.
    20 changes: 20 additions & 0 deletions file_save.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    //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);
    },