11'use strict' ;
22
3- const when = require ( 'when' ) ;
43const React = require ( 'react' ) ;
4+ const through = require ( 'through2' ) ;
55const { Menu, MainButton, ChildButton } = require ( 'react-mfb-iceddev' ) ;
66
77require ( 'react-mfb-iceddev/mfb.css' ) ;
@@ -12,8 +12,12 @@ const DeleteConfirmOverlay = require('./overlays/delete-confirm');
1212
1313const styles = require ( './styles' ) ;
1414
15+ let boards = { } ;
16+
1517const FileOperations = React . createClass ( {
1618 handleError : function ( err ) {
19+ // leaving this in for better debugging of errors
20+ console . log ( err ) ;
1721 const toast = this . props . toast ;
1822
1923 toast . show ( err . message , { style : styles . errorToast } ) ;
@@ -67,24 +71,38 @@ const FileOperations = React.createClass({
6771 download : function ( devicePath ) {
6872 const toast = this . props . toast ;
6973 const space = this . props . workspace ;
74+ const logger = this . props . logger ;
7075 const overlay = this . props . overlay ;
71- const programmer = this . props . programmer ;
76+ const Board = this . props . Board ;
7277 const name = space . filename . deref ( ) ;
78+ const source = space . current . deref ( ) ;
7379
7480 if ( ! devicePath ) {
7581 return ;
7682 }
7783
78- programmer . compile ( { source : space . current . deref ( ) } )
79- . then ( function ( memory ) {
80- var options = {
81- path : devicePath ,
82- board : 'bs2' ,
83- memory : memory
84- } ;
84+ const boardOpts = {
85+ path : devicePath ,
86+ revision : 'bs2' ,
87+ readAfterProgram : true
88+ } ;
89+
90+ let board ;
91+ if ( boards [ devicePath ] ) {
92+ board = boards [ devicePath ] ;
93+ } else {
94+ board = boards [ devicePath ] = new Board ( boardOpts ) ;
95+ }
96+
97+ const log = through ( function ( chunk , enc , cb ) {
98+ logger ( chunk . toString ( ) ) ;
99+ cb ( null , chunk ) ;
100+ } ) ;
85101
86- return programmer . bootload ( options ) ;
87- } )
102+ board . compile ( source )
103+ . tap ( ( ) => logger . clear ( ) )
104+ . then ( ( memory ) => board . bootload ( memory ) )
105+ . then ( ( ) => board . read ( ) . pipe ( log ) )
88106 . tap ( ( ) => toast . clear ( ) )
89107 . tap ( ( ) => this . handleSuccess ( `'${ name } ' downloaded successfully` ) )
90108 . catch ( this . handleError )
0 commit comments