You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instead of using `exclude`, explicitly state functinalities
[include: [:get,:create,:delete]]
This will lead to smaller compiled binaries(due to reducing dead code generated by macro)
and to more clarity(devs will know at glance what functions are inside the subcontext)
[naming_scheme: :prefix][naming_scheme: :suffix][naming_scheme: &String.to_atom("${&1}_${&2}${&3}")]# where &1 is action(get, list) and &2 is resource name and &3 is resource name plural
Move function naming inside context to delegate_all
Instead of forcing users to follow a scheme of naming things like `list_users`. Allow them to call functions as they want to inside the subcontext: e.g `list`
So instead of using `delegate list_users, to: MyApp.Account.Users` use `delegate list_users, to: MyApp.Account.Users, as: :list`.
This will make managing name changes of resources and prevent someone from creating `list_posts` inside `MyApp.Account.Users` as it would be exposed as `list_posts_users`
Table of Contents
CRUD
Opt in over opt out
Instead of using `exclude`, explicitly state functinalities
This will lead to smaller compiled binaries(due to reducing dead code generated by macro)
and to more clarity(devs will know at glance what functions are inside the subcontext)
Function naming
Ways of generating names
Instead of generating functions with names like `list_posts` or `get_post` like this:
https://github.com/curiosum-dev/contexted/blob/main/lib/contexted/crud.ex#L67
Allow the user to pass in something like
Move function naming inside context to delegate_all
Instead of forcing users to follow a scheme of naming things like `list_users`. Allow them to call functions as they want to inside the subcontext: e.g `list`
So instead of using `delegate list_users, to: MyApp.Account.Users` use `delegate list_users, to: MyApp.Account.Users, as: :list`.
This will make managing name changes of resources and prevent someone from creating `list_posts` inside `MyApp.Account.Users` as it would be exposed as `list_posts_users`
Extensibility
Instead of having a huge quote block
https://github.com/curiosum-dev/contexted/blob/main/lib/contexted/crud.ex#L58
Refactor each action into a separate module such as `Subcontexted.Action.Get`
Like this:
And then include actions based on the [include: [:get]]
Further functionalities would be easier to implement with this approach such as allowing users to define their own actions
Developer experience
Developer experience could be further improved by using https://github.com/ash-project/spark which would provide great tooling for:
The LSP in particular would make using the library easier. For example
The tab autocomplete then would list `:prefix` and `:suffix`
Adding an example app
Adding an example app using `Contexted` and hosting the generated exdoc would make it easier to understand the idea behind the project
The text was updated successfully, but these errors were encountered: