Skip to content

Commit

Permalink
refactor: unify the use of emit/makeRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
eri24816 committed Mar 23, 2024
1 parent a3840cc commit 1de9b1b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
11 changes: 3 additions & 8 deletions backend/src/grapycal/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,8 @@ def _setup_objectsync(self):
self._objectsync.register_service("exit", self._exit)
self._objectsync.register_service("interrupt", self._interrupt)
self._objectsync.register_service("slash_command", lambda name,ctx: self.slash.call(name,CommandCtx(**ctx)))

self._objectsync.on(
"ctrl+s", lambda: self._save_workspace(self.path), is_stateful=False
)
self._objectsync.on(
"open_workspace", self._open_workspace_callback, is_stateful=False
)

self._objectsync.register_service("ctrl+s", lambda: self._save_workspace(self.path))
self._objectsync.register_service("open_workspace", self._open_workspace_callback)

def _setup_slash_commands(self):
self.slash.register("save workspace", lambda ctx: self._save_workspace(self.path))
Expand Down Expand Up @@ -204,6 +198,7 @@ def _setup_store(self):
main_store.next_id = self._next_id
main_store.vars = self._vars
main_store.record = self._objectsync.record
main_store.slash = self.slash

def _load_or_create_workspace(self):
"""
Expand Down
10 changes: 5 additions & 5 deletions backend/src/grapycal/extension/extensionManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def __init__(self,objectsync_server:objectsync.Server) -> None:
self._imported_extensions_topic = self._objectsync.create_topic('imported_extensions',objectsync.DictTopic,is_stateful=False)
self._avaliable_extensions_topic = self._objectsync.create_topic('avaliable_extensions',objectsync.DictTopic,is_stateful=False)
self._not_installed_extensions_topic = self._objectsync.create_topic('not_installed_extensions',objectsync.DictTopic,is_stateful=False)
self._objectsync.on('import_extension',self.import_extension,is_stateful=False)
self._objectsync.on('unimport_extension',self.unimport_extension,is_stateful=False)
self._objectsync.on('update_extension',self.update_extension,is_stateful=False)
self._objectsync.on('refresh_extensions',self._update_available_extensions_topic,is_stateful=False)
self._objectsync.on('install_extension',self._install_extension,is_stateful=False)
self._objectsync.register_service('import_extension',self.import_extension)
self._objectsync.register_service('unimport_extension',self.unimport_extension)
self._objectsync.register_service('update_extension',self.update_extension)
self._objectsync.register_service('refresh_extensions',self._update_available_extensions_topic)
self._objectsync.register_service('install_extension',self._install_extension)

def start(self) -> None:
'''
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function startObjectSync(wsUrl:string){
}
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() == 's') {
event.preventDefault();
objectsync.emit('ctrl+s');
objectsync.makeRequest('ctrl+s');
}
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() == 'q') {
event.preventDefault();
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/sobjects/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class Workspace extends CompSObject{
}

public openWorkspace(path:string){
this.objectsync.emit('open_workspace',{path:path})
this.objectsync.makeRequest('open_workspace',{path:path})
}

public callSlashCommand(name:string,ctx:any){
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/ui_utils/extensionsSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class ExtensionsSetting extends Componentable{
})

document.getElementById('refresh-extensions').addEventListener('click',()=>{
this.objectsync.emit('refresh_extensions')
this.objectsync.makeRequest('refresh_extensions')
})
}

Expand All @@ -101,22 +101,22 @@ export class ExtensionsSetting extends Componentable{
const cardContent = card.querySelector<HTMLDivElement>('.card-content')
if(status == 'imported'){
this.addButtonToCard(card,this.removeButtonTemplate,()=>{
this.objectsync.emit('unimport_extension',{extension_name:newExtension.name})
this.objectsync.makeRequest('unimport_extension',{extension_name:newExtension.name})
})
this.addButtonToCard(card,this.reloadButtonTemplate,()=>{
this.objectsync.emit('update_extension',{extension_name:newExtension.name})
this.objectsync.makeRequest('update_extension',{extension_name:newExtension.name})
})
}

if(status == 'avaliable'){
this.addButtonToCard(card,this.importButtonTemplate,()=>{
this.objectsync.emit('import_extension',{extension_name:newExtension.name})
this.objectsync.makeRequest('import_extension',{extension_name:newExtension.name})
})
}

if(status == 'not_installed'){
this.addButtonToCard(card,this.installButtonTemplate,()=>{
this.objectsync.emit('install_extension',{extension_name:newExtension.name})
this.objectsync.makeRequest('install_extension',{extension_name:newExtension.name})
})
}

Expand All @@ -127,14 +127,14 @@ export class ExtensionsSetting extends Componentable{
popup.openAt(e.clientX,e.clientY)
if(status == 'imported'){
popup.addOption('Reload',()=>{
this.objectsync.emit('update_extension',{extension_name:newExtension.name})
this.objectsync.makeRequest('update_extension',{extension_name:newExtension.name})
})
popup.addOption('Remove from workspace',()=>{
this.objectsync.emit('unimport_extension',{extension_name:newExtension.name})
this.objectsync.makeRequest('unimport_extension',{extension_name:newExtension.name})
})
}else{
popup.addOption('Import to workspace',()=>{
this.objectsync.emit('import_extension',{extension_name:newExtension.name})
this.objectsync.makeRequest('import_extension',{extension_name:newExtension.name})
})
}
})
Expand Down

0 comments on commit 1de9b1b

Please sign in to comment.