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

Suggestions #10

Open
ravensiris opened this issue May 22, 2023 · 0 comments
Open

Suggestions #10

ravensiris opened this issue May 22, 2023 · 0 comments

Comments

@ravensiris
Copy link

Table of Contents

  1. CRUD
    1. Opt in over opt out
    2. Function naming
      1. Ways of generating names
      2. Move function naming inside context to delegateall
    3. Extensibility
  2. Developer experience
  3. Adding an example app

CRUD

Opt in over opt out

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)

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

[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`

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:

defmodule Contexted.Action.Get do
    defmacro __using__(opts) do
        quote do
          def get(...) do
            ...
          end
        end
    end
end

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:

  • better automated docs
  • LSP integration
  • better errors when passing wrong options to `use` macros

The LSP in particular would make using the library easier. For example

defmodule MyApp.Account.Users do
  use Contexted, naming_scheme: # <TAB> autocomplete
end

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

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

No branches or pull requests

1 participant