From 9546dc2aa39ab096ccc723786e718a739d0bdaf9 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Thu, 27 Jan 2022 00:17:22 +0100 Subject: refactor: Coding conventions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure that files have a default import with the same name as the file whenever possible to reduce surprise. Also shuffles around some file names for better legibility. Signed-off-by: Kristóf Marussy --- packages/shared/src/index.ts | 21 +++++-------- packages/shared/src/schemas.ts | 44 +++++++++++++++++---------- packages/shared/src/stores/GlobalSettings.ts | 18 +++++++---- packages/shared/src/stores/Profile.ts | 14 ++++++--- packages/shared/src/stores/ProfileSettings.ts | 14 ++++++--- packages/shared/src/stores/Service.ts | 14 ++++++--- packages/shared/src/stores/ServiceSettings.ts | 18 +++++++---- packages/shared/src/stores/SharedStore.ts | 34 ++++++++++++--------- 8 files changed, 109 insertions(+), 68 deletions(-) (limited to 'packages/shared') diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index 55cf5ce..3d30488 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -22,40 +22,33 @@ export type { default as SophieRenderer } from './contextBridge/SophieRenderer'; export { MainToRendererIpcMessage, RendererToMainIpcMessage } from './ipc'; -export type { Action, BrowserViewBounds, ThemeSource } from './schemas'; -export { action, browserViewBounds, themeSource } from './schemas'; +export { Action, BrowserViewBounds, ThemeSource } from './schemas'; export type { - GlobalSettings, GlobalSettingsSnapshotIn, GlobalSettingsSnapshotOut, } from './stores/GlobalSettings'; -export { globalSettings } from './stores/GlobalSettings'; +export { default as GlobalSettings } from './stores/GlobalSettings'; -export type { Profile } from './stores/Profile'; -export { profile } from './stores/Profile'; +export { default as Profile } from './stores/Profile'; export type { - ProfileSettings, ProfileSettingsSnapshotIn, ProfileSettingsSnapshotOut, } from './stores/ProfileSettings'; -export { profileSettings } from './stores/ProfileSettings'; +export { default as ProfileSettings } from './stores/ProfileSettings'; -export type { Service } from './stores/Service'; -export { service } from './stores/Service'; +export { default as Service } from './stores/Service'; export type { - ServiceSettings, ServiceSettingsSnapshotIn, ServiceSettingsSnapshotOut, } from './stores/ServiceSettings'; -export { serviceSettings } from './stores/ServiceSettings'; +export { default as ServiceSettings } from './stores/ServiceSettings'; export type { - SharedStore, SharedStoreListener, SharedStoreSnapshotIn, SharedStoreSnapshotOut, } from './stores/SharedStore'; -export { sharedStore } from './stores/SharedStore'; +export { default as SharedStore } from './stores/SharedStore'; diff --git a/packages/shared/src/schemas.ts b/packages/shared/src/schemas.ts index 7fb9717..edf3741 100644 --- a/packages/shared/src/schemas.ts +++ b/packages/shared/src/schemas.ts @@ -20,43 +20,55 @@ import { z } from 'zod'; -const setSelectedServiceId = z.object({ +const SetSelectedServiceId = z.object({ action: z.literal('set-selected-service-id'), serviceId: z.string(), }); -export const browserViewBounds = z.object({ +export const BrowserViewBounds = z.object({ x: z.number().int().nonnegative(), y: z.number().int().nonnegative(), width: z.number().int().nonnegative(), height: z.number().int().nonnegative(), }); -export type BrowserViewBounds = z.infer; +/* + eslint-disable-next-line @typescript-eslint/no-redeclare -- + Intentionally naming the type the same as the schema definition. +*/ +export type BrowserViewBounds = z.infer; -const setBrowserViewBoundsAction = z.object({ +const SetBrowserViewBoundsAction = z.object({ action: z.literal('set-browser-view-bounds'), - browserViewBounds, + browserViewBounds: BrowserViewBounds, }); -export const themeSource = z.enum(['system', 'light', 'dark']); +export const ThemeSource = z.enum(['system', 'light', 'dark']); -export type ThemeSource = z.infer; +/* + eslint-disable-next-line @typescript-eslint/no-redeclare -- + Intentionally naming the type the same as the schema definition. +*/ +export type ThemeSource = z.infer; -const setThemeSourceAction = z.object({ +const SetThemeSourceAction = z.object({ action: z.literal('set-theme-source'), - themeSource, + themeSource: ThemeSource, }); -const reloadAllServicesAction = z.object({ +const ReloadAllServicesAction = z.object({ action: z.literal('reload-all-services'), }); -export const action = z.union([ - setSelectedServiceId, - setBrowserViewBoundsAction, - setThemeSourceAction, - reloadAllServicesAction, +export const Action = z.union([ + SetSelectedServiceId, + SetBrowserViewBoundsAction, + SetThemeSourceAction, + ReloadAllServicesAction, ]); -export type Action = z.infer; +/* + eslint-disable-next-line @typescript-eslint/no-redeclare -- + Intentionally naming the type the same as the schema definition. +*/ +export type Action = z.infer; diff --git a/packages/shared/src/stores/GlobalSettings.ts b/packages/shared/src/stores/GlobalSettings.ts index bd0155a..3a813b8 100644 --- a/packages/shared/src/stores/GlobalSettings.ts +++ b/packages/shared/src/stores/GlobalSettings.ts @@ -20,16 +20,22 @@ import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; -import { themeSource } from '../schemas'; +import { ThemeSource } from '../schemas'; -export const globalSettings = types.model('GlobalSettings', { - themeSource: types.optional(types.enumeration(themeSource.options), 'system'), +const GlobalSettings = types.model('GlobalSettings', { + themeSource: types.optional(types.enumeration(ThemeSource.options), 'system'), }); -export interface GlobalSettings extends Instance {} +/* + eslint-disable-next-line @typescript-eslint/no-redeclare -- + Intentionally naming the type the same as the store definition. +*/ +interface GlobalSettings extends Instance {} + +export default GlobalSettings; export interface GlobalSettingsSnapshotIn - extends SnapshotIn {} + extends SnapshotIn {} export interface GlobalSettingsSnapshotOut - extends SnapshotOut {} + extends SnapshotOut {} diff --git a/packages/shared/src/stores/Profile.ts b/packages/shared/src/stores/Profile.ts index bb058f6..256c33e 100644 --- a/packages/shared/src/stores/Profile.ts +++ b/packages/shared/src/stores/Profile.ts @@ -20,11 +20,17 @@ import { Instance, types } from 'mobx-state-tree'; -import { profileSettings } from './ProfileSettings'; +import ProfileSettings from './ProfileSettings'; -export const profile = types.model('Profile', { +const Profile = types.model('Profile', { id: types.identifier, - settings: profileSettings, + settings: ProfileSettings, }); -export interface Profile extends Instance {} +/* + eslint-disable-next-line @typescript-eslint/no-redeclare -- + Intentionally naming the type the same as the store definition. +*/ +interface Profile extends Instance {} + +export default Profile; diff --git a/packages/shared/src/stores/ProfileSettings.ts b/packages/shared/src/stores/ProfileSettings.ts index ec8da5f..9f2b27c 100644 --- a/packages/shared/src/stores/ProfileSettings.ts +++ b/packages/shared/src/stores/ProfileSettings.ts @@ -20,14 +20,20 @@ import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; -export const profileSettings = types.model('ProfileSettings', { +const ProfileSettings = types.model('ProfileSettings', { name: types.string, }); -export interface ProfileSettings extends Instance {} +/* + eslint-disable-next-line @typescript-eslint/no-redeclare -- + Intentionally naming the type the same as the store definition. +*/ +interface ProfileSettings extends Instance {} + +export default ProfileSettings; export interface ProfileSettingsSnapshotIn - extends SnapshotIn {} + extends SnapshotIn {} export interface ProfileSettingsSnapshotOut - extends SnapshotOut {} + extends SnapshotOut {} diff --git a/packages/shared/src/stores/Service.ts b/packages/shared/src/stores/Service.ts index 36acd3d..4a7334d 100644 --- a/packages/shared/src/stores/Service.ts +++ b/packages/shared/src/stores/Service.ts @@ -20,11 +20,11 @@ import { Instance, types } from 'mobx-state-tree'; -import { serviceSettings } from './ServiceSettings'; +import ServiceSettings from './ServiceSettings'; -export const service = types.model('Service', { +const Service = types.model('Service', { id: types.identifier, - settings: serviceSettings, + settings: ServiceSettings, currentUrl: types.maybe(types.string), canGoBack: false, canGoForward: false, @@ -37,4 +37,10 @@ export const service = types.model('Service', { indirectMessageCount: 0, }); -export interface Service extends Instance {} +/* + eslint-disable-next-line @typescript-eslint/no-redeclare -- + Intentionally naming the type the same as the store definition. +*/ +interface Service extends Instance {} + +export default Service; diff --git a/packages/shared/src/stores/ServiceSettings.ts b/packages/shared/src/stores/ServiceSettings.ts index 54cd7eb..6ba1dfa 100644 --- a/packages/shared/src/stores/ServiceSettings.ts +++ b/packages/shared/src/stores/ServiceSettings.ts @@ -20,19 +20,25 @@ import { Instance, types, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; -import { profile } from './Profile'; +import Profile from './Profile'; -export const serviceSettings = types.model('ServiceSettings', { +const ServiceSettings = types.model('ServiceSettings', { name: types.string, - profile: types.reference(profile), + profile: types.reference(Profile), // TODO: Remove this once recipes are added. url: types.string, }); -export interface ServiceSettings extends Instance {} +/* + eslint-disable-next-line @typescript-eslint/no-redeclare -- + Intentionally naming the type the same as the store definition. +*/ +interface ServiceSettings extends Instance {} + +export default ServiceSettings; export interface ServiceSettingsSnapshotIn - extends SnapshotIn {} + extends SnapshotIn {} export interface ServiceSettingsSnapshotOut - extends SnapshotOut {} + extends SnapshotOut {} diff --git a/packages/shared/src/stores/SharedStore.ts b/packages/shared/src/stores/SharedStore.ts index f301b9d..0cac3a5 100644 --- a/packages/shared/src/stores/SharedStore.ts +++ b/packages/shared/src/stores/SharedStore.ts @@ -26,26 +26,32 @@ import { SnapshotOut, } from 'mobx-state-tree'; -import { globalSettings } from './GlobalSettings'; -import { profile } from './Profile'; -import { service } from './Service'; - -export const sharedStore = types.model('SharedStore', { - settings: types.optional(globalSettings, {}), - profilesById: types.map(profile), - profiles: types.array(types.reference(profile)), - servicesById: types.map(service), - services: types.array(types.reference(service)), - selectedService: types.safeReference(service), +import GlobalSettings from './GlobalSettings'; +import Profile from './Profile'; +import Service from './Service'; + +const SharedStore = types.model('SharedStore', { + settings: types.optional(GlobalSettings, {}), + profilesById: types.map(Profile), + profiles: types.array(types.reference(Profile)), + servicesById: types.map(Service), + services: types.array(types.reference(Service)), + selectedService: types.safeReference(Service), shouldUseDarkColors: false, }); -export interface SharedStore extends Instance {} +/* + eslint-disable-next-line @typescript-eslint/no-redeclare -- + Intentionally naming the type the same as the store definition. +*/ +interface SharedStore extends Instance {} + +export default SharedStore; -export interface SharedStoreSnapshotIn extends SnapshotIn {} +export interface SharedStoreSnapshotIn extends SnapshotIn {} export interface SharedStoreSnapshotOut - extends SnapshotOut {} + extends SnapshotOut {} export interface SharedStoreListener { onSnapshot(snapshot: SharedStoreSnapshotIn): void; -- cgit v1.2.3-54-g00ecf