Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
refactor(client-core)(instanceserver service): remove action receptor…
Browse files Browse the repository at this point in the history
… usage (#8307)
  • Loading branch information
aditya-mitra authored Jul 20, 2023
1 parent 69a6420 commit 31e63e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 50 deletions.
53 changes: 9 additions & 44 deletions packages/client-core/src/admin/services/InstanceserverService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@ Ethereal Engine. All Rights Reserved.

import { InstanceServerPatch } from '@etherealengine/common/src/interfaces/Instance'
import multiLogger from '@etherealengine/common/src/logger'
import { matches, Validator } from '@etherealengine/engine/src/common/functions/MatchesUtils'
import { defineAction, defineState, dispatchAction, getMutableState } from '@etherealengine/hyperflux'

import { API } from '../../API'
import { Engine } from '@etherealengine/engine/src/ecs/classes/Engine'
import { defineState, getMutableState } from '@etherealengine/hyperflux'

const logger = multiLogger.child({ component: 'client-core:InstanceserverService' })

//State
export const AdminInstanceServerState = defineState({
name: 'AdminInstanceServerState',
initial: () => ({
Expand All @@ -42,50 +39,18 @@ export const AdminInstanceServerState = defineState({
})
})

const patchInstanceserverReceptor = (action: typeof AdminInstanceserverActions.patchInstanceserver.matches._TYPE) => {
const state = getMutableState(AdminInstanceServerState)
return state.merge({
patch: undefined,
fetched: false
})
}

const patchedInstanceserverReceptor = (
action: typeof AdminInstanceserverActions.patchedInstanceserver.matches._TYPE
) => {
const state = getMutableState(AdminInstanceServerState)
return state.merge({
patch: action.patch,
fetched: true,
lastFetched: Date.now()
})
}

export const InstanceServerSettingReceptors = {
patchInstanceserverReceptor,
patchedInstanceserverReceptor
}

//Service
export const InstanceserverService = {
patchInstanceserver: async (locationId: string, count: number) => {
try {
dispatchAction(AdminInstanceserverActions.patchInstanceserver({}))
const patch = await API.instance.client.service('instanceserver-provision').patch({ locationId, count })
dispatchAction(AdminInstanceserverActions.patchedInstanceserver({ patch }))
const patch = await Engine.instance.api.service('instanceserver-provision').patch({ locationId, count })

getMutableState(AdminInstanceServerState).merge({
patch,
fetched: true,
lastFetched: Date.now()
})
} catch (error) {
logger.error(error)
}
}
}

//Action
export class AdminInstanceserverActions {
static patchInstanceserver = defineAction({
type: 'ee.client.AdminInstanceserver.INSTANCESERVER_PATCH' as const
})
static patchedInstanceserver = defineAction({
type: 'ee.client.AdminInstanceserver.INSTANCESERVER_PATCHED' as const,
patch: matches.object as Validator<unknown, InstanceServerPatch>
})
}
6 changes: 0 additions & 6 deletions packages/client-core/src/systems/AdminSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { AdminBotCommandActions, AdminBotsCommandReceptors } from '../admin/serv
import { AdminBotsActions, AdminBotServiceReceptors } from '../admin/services/BotsService'
import { AdminBuildStatusActions, AdminBuildStatusReceptors } from '../admin/services/BuildStatusService'
import { AdminGroupActions, AdminGroupServiceReceptors } from '../admin/services/GroupService'
import { AdminInstanceserverActions, InstanceServerSettingReceptors } from '../admin/services/InstanceserverService'
import {
AdminInstanceActions,
AdminInstanceReceptors,
Expand Down Expand Up @@ -95,8 +94,6 @@ const fetchedHelmQueue = defineActionQueue(AdminHelmSettingActions.helmSettingRe
const patchedHelmQueue = defineActionQueue(AdminHelmSettingActions.helmSettingPatched.matches)
const fetchedHelmMainVersionsQueue = defineActionQueue(AdminHelmSettingActions.helmMainVersionsRetrieved.matches)
const fetchedHelmBuilderVersionsQueue = defineActionQueue(AdminHelmSettingActions.helmBuilderVersionsRetrieved.matches)
const patchInstanceserverQueue = defineActionQueue(AdminInstanceserverActions.patchInstanceserver.matches)
const patchedInstanceserverQueue = defineActionQueue(AdminInstanceserverActions.patchedInstanceserver.matches)
const projectSettingFetchedQueue = defineActionQueue(AdminProjectSettingsActions.projectSettingFetched.matches)
const fetchedSeverInfoQueue = defineActionQueue(AdminServerSettingActions.fetchedSeverInfo.matches)
const serverSettingPatchedQueue = defineActionQueue(AdminServerSettingActions.serverSettingPatched.matches)
Expand Down Expand Up @@ -193,9 +190,6 @@ const execute = () => {
for (const action of fetchedHelmMainVersionsQueue()) HelmSettingReceptors.helmMainVersionsRetrievedReceptor(action)
for (const action of fetchedHelmBuilderVersionsQueue())
HelmSettingReceptors.helmBuilderVersionsRetrievedReceptor(action)
for (const action of patchInstanceserverQueue()) InstanceServerSettingReceptors.patchInstanceserverReceptor(action)
for (const action of patchedInstanceserverQueue())
InstanceServerSettingReceptors.patchedInstanceserverReceptor(action)
for (const action of projectSettingFetchedQueue()) ProjectSettingReceptors.projectSettingFetchedReceptor(action)
for (const action of fetchedSeverInfoQueue()) ServerSettingReceptors.fetchedSeverInfoReceptor(action)
for (const action of serverSettingPatchedQueue()) ServerSettingReceptors.serverSettingPatchedReceptor(action)
Expand Down

0 comments on commit 31e63e0

Please sign in to comment.