-
Notifications
You must be signed in to change notification settings - Fork 0
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/service method #381
Open
Paulijuz
wants to merge
15
commits into
main
Choose a base branch
from
refactor/use-service-method
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…viceMethodTypes.ts
…ms and remove direct calls after bind params
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refactors the implementation of service methods. This makes life easier and also simplifies the implementation of tests.
Major changes include:
ServiceMethod
andServiceMethodHandler
into one as they were almost identical.Action
andActionNoData
bindParams(action, ...)
andbindData(action, ...)
as a replacment foraction.bind(null, ...)
. They are functions which take in an action as their first argument and bind the relevant argument.**withData
when creating service methods. This is inferred from whether or not a data validation is present..client('NEW')
has been changed to.newClient()
. The latter takes fives keystrokes (.
+n
+tab
+(
+)
) as opposed to eight (.
+n
+tab
+(
+'
+N
+tab
+)
).*Note on params validation: I have currently implemented param validation with bare zod schemas. I did not use Validations as two steps of validation is unnecessary for params I think (and also maybe for data?). I did not change the Validation as that would be out of the scope of this PR. We need to discuss how it should be implemented properly as having two ways of creating validation is messy.
**Note on binding: I did not manage to implement the binding functions with dot notation as server actions cannot be objects, nor can they be functions with custom properties, thus this was the only way to implement something close to what we wanted. Another thing: Since server actions will be "normal functions" I also think that we should only bind arguments wherever necessary, as opposed to binding them first and the calling them immediately as was done previously. I.e. we should avoid writing
bindParams(action, ...)()
(the new version ofaction.bind(null, ...)()
, and simply doaction(...)
instead.***Note on index files for service: I think ideally all services for a model should be defined in the same file (
index.ts
or maybeservice.ts
, we need to decide on a name. I think Johan doesn't like index files if I'm not mistaken), in stead of it importing all the functions fromcreate.ts
,read.ts
,update.ts
anddestroy.ts
. I have not had the time to do this so I have simply removed these files for now.Minor changes include:
Things that I think still need to be done:
create.ts
,read.ts
,update.ts
,destroy.ts
in services into one file. Where alle the definitions of the service methods live in a single object. Preferably with a naming convention likeuserService
,lockerService
,cmsImageService
, etc...create.ts
,read.ts
,update.ts
,destroy.ts
in actions into one file. Most files with the new system will be only a few lines, so fragmenting the definitions will be more disorganized than organized I think.