Skip to content
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

Cleanup loading terminal fonts #6937

Merged
merged 3 commits into from
Jan 17, 2023
Merged

Conversation

Nokel81
Copy link
Collaborator

@Nokel81 Nokel81 commented Jan 13, 2023

Follow up #6913

  • Make list of possible fonts fully OCP
  • Only mark the loading of a font as 'causesSideEffects'
  • Make a view model for the terminal font preferences component
  • Move the TTF files next to where they are registered to help with finding them

Signed-off-by: Sebastian Malton sebastian@malton.name

- Make list of possible fonts fully OCP
- Only mark the loading of a font as 'causesSideEffects'
- Make a view model for the terminal font preferences component
- Move the TTF files next to where they are registered to help with finding them

Signed-off-by: Sebastian Malton <sebastian@malton.name>
@Nokel81 Nokel81 added this to the 6.4.0 milestone Jan 13, 2023
@Nokel81 Nokel81 requested a review from a team as a code owner January 13, 2023 17:01
@Nokel81 Nokel81 requested review from jansav and Iku-turso and removed request for a team January 13, 2023 17:01
Signed-off-by: Sebastian Malton <sebastian@malton.name>
ixrock
ixrock previously approved these changes Jan 14, 2023
Comment on lines +15 to +16
const terminalFonts = di.inject(terminalFontsInjectable);
const loadTerminalFont = di.inject(loadTerminalFontInjectable);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these be outside of run()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They could be, however I have found that for Runnable's having the di.inject calls within the run() causes less headaches. It is not that important here, but when there are runAfter's involved it is very important.

userStore: di.inject(userStoreInjectable),
logger: di.inject(loggerInjectable),
terminalFonts: di.inject(terminalFontsInjectable),
model: di.inject(terminalFontPreferenceModelInjectable),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where this model would be useful/utilized besides terminal settings?
Currently nowhere and probably would not need anywhere.. So why to make it complex from the beginning and split to maximum amount of files? No benefits currently, imho.

Copy link
Member

@ixrock ixrock Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an implementation of the https://en.wikipedia.org/wiki/Model-view-presenter pattern. Like similar patterns it helps make the view very passive and simple.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's kinda improvement I agree.
But maybe done too early before any real some needs/system optimizations requirements, meanwhile making a whole system a bit more complex for nothing.

Comment on lines +9 to +18
const redHatMonoTerminalFontInjectable = getInjectable({
id: "red-hat-mono-terminal-font",
instantiate: () => ({
name: "Red Hat Mono",
url: RedHatMono,
}),
injectionToken: terminalFontInjectionToken,
});

export default redHatMonoTerminalFontInjectable;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw: why do we need to name some injectable when it's name never used in many files? we could do direct default export like this:

export default getInjectable({
  id: "red-hat-mono-terminal-font",
  instantiate: () => ({
    name: "Red Hat Mono",
    url: RedHatMono,
  }),
  injectionToken: terminalFontInjectionToken,
});

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we could just do a export default since this will only ever be di.injectMany-ed. The reason to add the const ...; export default ...; is to help with intellisense and auto-import when using an injectable with di.inject(). This way it can easily be auto-imported if someone ever wants to import just this one injectable.

Comment on lines 37 to 40
current: computed(() => userStore.terminalConfig.fontFamily),
set: action(selection => {
userStore.terminalConfig.fontFamily = selection?.value ?? defaultTerminalFontFamily;
}),
Copy link
Member

@ixrock ixrock Jan 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: better readability + set() should not know anything about SelectOption, better to pass just a font value:

Suggested change
current: computed(() => userStore.terminalConfig.fontFamily),
set: action(selection => {
userStore.terminalConfig.fontFamily = selection?.value ?? defaultTerminalFontFamily;
}),
get fontFamily(){
return userStore.terminalConfig.fontFamily;
},
setFont: action(fontFamily => {
userStore.terminalConfig.fontFamily = fontFamily ?? defaultTerminalFontFamily;
}),

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can update the name of the functions sure but using computed(() => ...) better communicates the contract then a getter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better for who? Why end-user of this let's say api should care about computed that on that side or not?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words to distinguish observable this field or not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why end-user of this let's say api should care about computed that on that side or not?

So that the API user knows that they should only read the field in an observable context or that reading it multiple times outside of a context may result in different values.

Signed-off-by: Sebastian Malton <sebastian@malton.name>
@Nokel81 Nokel81 merged commit e635d82 into master Jan 17, 2023
@Nokel81 Nokel81 deleted the cleanup-loading-terminal-fonts branch January 17, 2023 13:11
@Nokel81 Nokel81 mentioned this pull request Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants