99 getCrateType ,
1010 runAsTest ,
1111 useWebsocketSelector ,
12- baseUrlSelector ,
1312} from './selectors' ;
1413import State from './state' ;
1514import {
@@ -35,7 +34,9 @@ import {
3534 Crate ,
3635} from './types' ;
3736
38- const routes = {
37+ import { performGistLoad } from './reducers/output/gist' ;
38+
39+ export const routes = {
3940 compile : '/compile' ,
4041 execute : '/execute' ,
4142 format : '/format' ,
@@ -118,12 +119,6 @@ export enum ActionType {
118119 RequestMacroExpansion = 'REQUEST_MACRO_EXPANSION' ,
119120 MacroExpansionSucceeded = 'MACRO_EXPANSION_SUCCEEDED' ,
120121 MacroExpansionFailed = 'MACRO_EXPANSION_FAILED' ,
121- RequestGistLoad = 'REQUEST_GIST_LOAD' ,
122- GistLoadSucceeded = 'GIST_LOAD_SUCCEEDED' ,
123- GistLoadFailed = 'GIST_LOAD_FAILED' ,
124- RequestGistSave = 'REQUEST_GIST_SAVE' ,
125- GistSaveSucceeded = 'GIST_SAVE_SUCCEEDED' ,
126- GistSaveFailed = 'GIST_SAVE_FAILED' ,
127122 RequestCratesLoad = 'REQUEST_CRATES_LOAD' ,
128123 CratesLoadSucceeded = 'CRATES_LOAD_SUCCEEDED' ,
129124 RequestVersionsLoad = 'REQUEST_VERSIONS_LOAD' ,
@@ -235,13 +230,13 @@ const receiveExecuteFailure = ({ error }: { error?: string }) =>
235230
236231type FetchArg = Parameters < typeof fetch > [ 0 ] ;
237232
238- function jsonGet ( url : FetchArg ) {
233+ export function jsonGet ( url : FetchArg ) {
239234 return fetchJson ( url , {
240235 method : 'get' ,
241236 } ) ;
242237}
243238
244- function jsonPost < T > ( url : FetchArg , body : Record < string , any > ) : Promise < T > {
239+ export function jsonPost < T > ( url : FetchArg , body : Record < string , any > ) : Promise < T > {
245240 return fetchJson ( url , {
246241 method : 'post' ,
247242 body : JSON . stringify ( body ) ,
@@ -733,83 +728,6 @@ export function performMacroExpansion(): ThunkAction {
733728 } ;
734729}
735730
736- interface GistSuccessProps {
737- id : string ;
738- url : string ;
739- code : string ;
740- stdout : string ;
741- stderr : string ;
742- channel : Channel ;
743- mode : Mode ;
744- edition : Edition ;
745- }
746-
747- const requestGistLoad = ( ) =>
748- createAction ( ActionType . RequestGistLoad ) ;
749-
750- const receiveGistLoadSuccess = ( props : GistSuccessProps ) =>
751- createAction ( ActionType . GistLoadSucceeded , props ) ;
752-
753- const receiveGistLoadFailure = ( ) => // eslint-disable-line no-unused-vars
754- createAction ( ActionType . GistLoadFailed ) ;
755-
756- type PerformGistLoadProps =
757- Pick < GistSuccessProps , Exclude < keyof GistSuccessProps , 'url' | 'code' | 'stdout' | 'stderr' > > ;
758-
759- export function performGistLoad ( { id, channel, mode, edition } : PerformGistLoadProps ) : ThunkAction {
760- return function ( dispatch , getState ) {
761- dispatch ( requestGistLoad ( ) ) ;
762-
763- const state = getState ( ) ;
764- const baseUrl = baseUrlSelector ( state ) ;
765- const gistUrl = new URL ( routes . meta . gistLoad , baseUrl ) ;
766- const u = new URL ( id , gistUrl ) ;
767-
768- jsonGet ( u )
769- . then ( gist => dispatch ( receiveGistLoadSuccess ( { channel, mode, edition, ...gist } ) ) ) ;
770- // TODO: Failure case
771- } ;
772- }
773-
774- const requestGistSave = ( ) =>
775- createAction ( ActionType . RequestGistSave ) ;
776-
777- const receiveGistSaveSuccess = ( props : GistSuccessProps ) =>
778- createAction ( ActionType . GistSaveSucceeded , props ) ;
779-
780- const receiveGistSaveFailure = ( { error } : CompileFailure ) => // eslint-disable-line no-unused-vars
781- createAction ( ActionType . GistSaveFailed , { error } ) ;
782-
783- interface GistResponseBody {
784- id : string ;
785- url : string ;
786- code : string ;
787- }
788-
789- export function performGistSave ( ) : ThunkAction {
790- return function ( dispatch , getState ) {
791- dispatch ( requestGistSave ( ) ) ;
792-
793- const state = getState ( ) ;
794- const code = codeSelector ( state ) ;
795- const {
796- configuration : {
797- channel, mode, edition,
798- } ,
799- output : {
800- execute : {
801- stdout = '' ,
802- stderr = '' ,
803- } ,
804- } ,
805- } = state ;
806-
807- return jsonPost < GistResponseBody > ( routes . meta . gistSave , { code } )
808- . then ( json => dispatch ( receiveGistSaveSuccess ( { ...json , code, stdout, stderr, channel, mode, edition } ) ) ) ;
809- // TODO: Failure case
810- } ;
811- }
812-
813731const requestCratesLoad = ( ) =>
814732 createAction ( ActionType . RequestCratesLoad ) ;
815733
@@ -1018,12 +936,6 @@ export type Action =
1018936 | ReturnType < typeof requestMacroExpansion >
1019937 | ReturnType < typeof receiveMacroExpansionSuccess >
1020938 | ReturnType < typeof receiveMacroExpansionFailure >
1021- | ReturnType < typeof requestGistLoad >
1022- | ReturnType < typeof receiveGistLoadSuccess >
1023- | ReturnType < typeof receiveGistLoadFailure >
1024- | ReturnType < typeof requestGistSave >
1025- | ReturnType < typeof receiveGistSaveSuccess >
1026- | ReturnType < typeof receiveGistSaveFailure >
1027939 | ReturnType < typeof requestCratesLoad >
1028940 | ReturnType < typeof receiveCratesLoadSuccess >
1029941 | ReturnType < typeof requestVersionsLoad >
0 commit comments