Skip to content

Add update_selection/1 to dynamically update (append, filter etc) the selection #68

@shamanime

Description

@shamanime
          Thanks for the explanation. I'm starting to see the value in this approach.

Instead of using 2 new options, one to pass a filter and the other to append to the selection, my suggestion would be to generalize the approach by passing an update_selection/1 function that receives the whole selection and returns the new one:

append case:

values_to_append = [1, 2, 3]

send_update(LiveSelect.Component, id: live_select_id, update_selection: fn selection -> selection ++ values_to_append end)

filter case:

send_update(LiveSelect.Component, id: live_select_id, update_selection: fn selection -> Enum.filter(selection, & &1 > 2)
end)

2 birds with a stone. And this general approach will hopefully accommodate future use cases.

What do you think?

EDIT: this would also make sense in single mode

Originally posted by @maxmarcon in #64 (comment)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions