-
Notifications
You must be signed in to change notification settings - Fork 0
Just a discussion thread #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Yes, that's fine to start like this, you can add a TODO to remember that this should be moved to Providers which is indeed dedicated to holding all the common providers to avoid cluttering BrowserApp/LocalApp (which is dedicated to setting the different "bricks" specific to electron or the web-app).
That seems a good start! :)
It's indeed:
What I suggest is to make PRs on the MainFrame to add a few useCallbacks. Not necessarily on everything, just a few ones to avoid re-renders. It's a large component so we won't do everyhting in a single pass, but starting this could improve efficiency in the long run :) |
| }; | ||
|
|
||
| class CommandManager { | ||
| commands: Array<Command>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a lot of find/findIndex - which can becomes costly when we'll have 200 commands. Do you think we could store instead commands in an object ({[string]: Command}), indexed by the command name? This means that access will be done in constant time, whatever the number of commands.
|
Okay, so there is a possibly big issue. I just realized that the contents of tabs aren't really unmounted when the user switches to another tab - it just gets hidden. I know it's essential for instant tab switching, but now I somehow need to withdraw options when the user switches to another tab - I don't think I can know about that from inside of ObjectsList, can I? Info about whether a tab is open or hidden seems to be present at the One solution I see is to create a context at the By the way, there may be some goto commands that are odds amongst the rest - for example, the "Open recent project..." command. Unlike other goto commands, it has nothing to do with the current project at all, and has to be enabled regardless of whether a project is open or not. In fact, this command seems to be really different, since it doesn't seem to be related to a component. What should I do for such commands? |
Yep you're right.
Indeed you can't know it from ObjectsList (and you should not try to know it from here, it's not this component responsibility - the component must just expose the commands, it's the context responsibility to know what to do with these).
Correct, MainFrame controls which tab is active, and pass it to TabContentContainer and to the "EditorContainer",
I'm also thinking of this solution as a good one.
It's not necessarily less flexible. We can have three stuff:
It looks something like this: The important point is that it must expose the exact same interface as the top level context (see, it's a With this, it's now the job of I think it's both flexible and clean (there is a single context for the whole codebase, and just two different providers, the top levle one and the "scoped" one). If you properly write the scoped one, tabs will work out of the box. register: (cmdName: string, cmd: Command) => {
scopedCommands.current[cmdName] = cmd;
if (props.active) {
commandsManager.register(props.scopeName + ' > ' + cmdName, cmd); // Just an example, the scopeName could be passed differently.
}
},
Well these commands seems very related to a component to me :) This could even be in MainFrame, in this case in a custom hook |
@4ian I've created a very barebones prototype for simple commands. The code is not very clean, as it's just a prototype for now. I'll add a prototype for Goto Anything commands in a few days.
For now, I've created a separate context provider component in
CommandPanel/context.js, and used it in both BrowserApp and LocalApp. Later, I guess we can move it into the Providers component.I've added two commands in Mainframe. Everything seems to work - the
enabledproperty of commands is being updated properly and handlers are updated if the handling function changes (the sample Close Project command gets updated on each Mainframe rerender due to the point mentioned below).Some functions in Mainframe haven't been wrapped in a
useCallback(for eg,askToCloseProject). These functions are also used in ElectronMainMenu, which means some IPC listeners are probably reset on every Mainframe render. Doesn't break anything (thanks to the custom hook in ElectronMainMenu) but still, that should be fixed, right?This PR is just a discussion thread for the prototyping period. I guess we can shift to a proper draft PR in the main repo when the coding period starts, if that's okay.