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

refactor: Unify generator store slices creation #39

Merged
merged 2 commits into from
Jul 17, 2024

Conversation

going-confetti
Copy link
Collaborator

No description provided.

Comment on lines 18 to 22
name: generateNewName(),
setName: (name: string) =>
set((state) => {
state.name = name
}),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps these could also be in their own slice, something like metadataSlice. Seems a bit excessive though

Comment on lines +27 to +28
allowList: [],
filteredRequests: [],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

filteredRequests is essentially a computed state, which means storing both allowList and filteredRequests is a bit error prone. Perhaps we can use a memoized selector instead?

Copy link
Member

Choose a reason for hiding this comment

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

I think this might be a little complicated 🤔

When saving the State to the file we do no care about filteredRequests.
The interface for State will need validation so it might become a zod type object.
Should we have the State and the extra State (filteredRequests..) as separated state objects or will it make things even more complex 😕

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We may need to write some adapter functions that will turn the state into a file: it's not just that the state has some runtime properties (like filteredRequests or showAllowListDialog), but also some slices has extra properties (like load profile)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there will be 2 separate types of state: State for app use and GeneratorFile type, which won't include internal props like selectedRunId. And 2 functions to convert between them.

As for filteredRequests - agree that it should be a memoized selector 👍

Comment on lines +5 to +18
interface State {
rules: TestRule[]
selectedRuleId: string | null
}

interface Actions {
createRule: (type: TestRule['type']) => void
updateRule: (rule: TestRule) => void
cloneRule: (id: string) => void
deleteRule: (id: string) => void
selectRule: (id: string) => void
}

export type RulesSliceStore = State & Actions
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 feel like having internal State and Actions improves readability, while exporting a store type means we can use it elsewhere as before

selectRule: (id: string) => void
}

export type RulesSliceStore = State & Actions
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

RulesSliceStore vs RulesSliceState vs RulesSliceType - what's your choice?

Copy link
Member

Choose a reason for hiding this comment

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

we might have to discuss the requirements more before deciding 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you think about moving store hooks to a different folder? src/store?

Comment on lines +27 to +28
allowList: [],
filteredRequests: [],
Copy link
Member

Choose a reason for hiding this comment

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

I think this might be a little complicated 🤔

When saving the State to the file we do no care about filteredRequests.
The interface for State will need validation so it might become a zod type object.
Should we have the State and the extra State (filteredRequests..) as separated state objects or will it make things even more complex 😕

import { ProxyData } from '@/types'
import { ImmerStateCreator } from '@/utils/typescript'

interface State {
Copy link
Member

Choose a reason for hiding this comment

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

any specific reason for dropping the prefix to the name ?
As it will be used outside it might make sense to keep it 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not exported, so the prefix is dropped for readability

selectRule: (id: string) => void
}

export type RulesSliceStore = State & Actions
Copy link
Member

Choose a reason for hiding this comment

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

we might have to discuss the requirements more before deciding 🤔

Copy link
Collaborator

@e-fisher e-fisher left a comment

Choose a reason for hiding this comment

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

Nice and clean 👌

@going-confetti going-confetti merged commit d915adf into main Jul 17, 2024
1 check passed
@going-confetti going-confetti deleted the refactor/generator-store branch July 17, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants