11angular . module ( 'javascriptcom' ) . factory ( 'jsCommand' , [ '_' , 'jsCommandFactory' , 'jsChallengeProgress' , function ( _ , jsCommandFactory , jsChallengeProgress ) {
2- return function jsCommand ( successCallback , errorCallback , messages ) {
2+ return function jsCommand ( successCallback , errorCallback ) {
33 var vm = this ;
4- vm . messages = messages ;
54
6- function setErrorMessageType ( message , fallback ) {
7- message = _ . isArray ( message ) ? message [ 1 ] . content . textContent : message ;
8-
9- return message . match ( / s y n t a x e r r o r / i) ? 'error' : 'default' ;
10- }
11-
12- function formatResponse ( content , vm , report , type ) {
13- vm . messages . push ( { value : _ . isArray ( content ) ? content [ 1 ] . content . textContent : content , type : ! type ? setErrorMessageType ( content ) : type } )
14- report ( { content : _ . isArray ( content ) ? content [ 0 ] . content : '' } ) ;
5+ function jsReportAdapter ( content ) {
6+ if ( _ . isArray ( content ) ) { return content ; }
7+ if ( _ . isObject ( content ) && content [ 'content' ] ) { return [ content ] ; }
8+ return [ { content : content } ] ;
159 }
1610
1711 vm . handler = function parseCommand ( line , report ) {
@@ -20,10 +14,10 @@ angular.module('javascriptcom').factory('jsCommand', ['_', 'jsCommandFactory', '
2014 var challenge = jsChallengeProgress . activeChallenge ( ) ;
2115
2216 command ( challenge , line ) . then ( function ( content ) {
23- formatResponse ( content , vm , report , 'success' )
17+ report ( jsReportAdapter ( content ) ) ;
2418 successCallback ( challenge ) ;
2519 } , function ( content ) {
26- formatResponse ( content , vm , report )
20+ report ( jsReportAdapter ( content ) ) ;
2721 errorCallback ( challenge ) ;
2822 } ) ;
2923 }
0 commit comments