import * as actions from "@nteract/actions" ; import { Save , SaveFailed , SaveFulfilled , SetAppHostAction , SetGithubTokenAction } from "@nteract/actions" ; import { AppRecord , AppRecordProps , makeAppRecord } from "@nteract/types" ; import { RecordOf } from "immutable" ; function setGithubToken ( state , action ) { return state . set ( "githubToken" , action . payload . githubToken ) ; } function save ( state ) { return state . set ( "isSaving" , true ) ; } function saveFailed ( state ) { return state . set ( "isSaving" , false ) ; } function saveFulfilled ( state ) { return state . set ( "isSaving" , false ) . set ( "lastSaved" , new Date ( ) ) ; } function setAppHost ( state , action ) { return state . set ( "host" , action . payload . host ) ; } export default function handleApp ( state = makeAppRecord ( ) , action ) { switch ( action . type ) { case actions . SAVE : return save ( state ) ; case actions . SAVE_FAILED : return saveFailed ( state ) ; case actions . SAVE_FULFILLED : return saveFulfilled ( state ) ; case actions . SET_GITHUB_TOKEN : return setGithubToken ( state , action ) ; case actions . SET_APP_HOST : return setAppHost ( state , action ) ; default : return state ; } }