Hi,
I am working on a small library. The goal of the library is to have a native LiveView data table.
I am a beginner in Elixir but I managed to do everything I’ve planned so far. But there is one thing that I am struggling with and that is API design. Now my API of the library looks like this:
DefaultLiveTable.render(
data: &get_data/1,
columns: [
%{field: :name, filtering: %{enable: true, variant: :multiple_select, options: %{a: "a", b: "b"}}},
%{field: :surname, filtering: %{enable: true, variant: :string}}
],
actions: [
%{
value: "Edit",
patch: Routes.default_path(socket, :index)
}
]
)
But I am not sure if it wouldn’t be better to use keyword lists instead of maps like this:
DefaultLiveTable.render(
data: &get_data/1,
columns: [
[field: :name, filtering: [enable: true, variant: :multiple_select, options: [a: "a", b: "b"]]],
[field: :surname, filtering: [enable: true, variant: :string]]
],
actions: [
[
value: "Edit",
patch: Routes.default_path(socket, :index)
]
]
)
I found working with maps easier because they work better with pattern matching and elements are accessible by dot syntax. But keyword lists are easier to write, and users wouldn’t need to wonder where to use maps and where lists.
What do you think?