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

feat: implement flat_map #3

Merged
merged 3 commits into from
Jul 26, 2023
Merged

feat: implement flat_map #3

merged 3 commits into from
Jul 26, 2023

Conversation

rapidfsub
Copy link
Contributor

@rapidfsub rapidfsub commented Jul 26, 2023

Use case

- @impl Phoenix.LiveView
- def handle_event("save", %{"form" => form}, socket) do
-   socket.assigns.form
-   |> AshPhoenix.Form.validate(form)
-   |> AshPhoenix.Form.submit()
-   |> case do
-     {:ok, _result} -> {:noreply, push_navigate(socket, to: ~p"/")}
-     {:error, form} -> {:noreply, assign(socket, :form, form)}
-   end
- end
+ @impl Phoenix.LiveView
+ def handle_event("save", %{"form" => form}, socket) do
+   rail do
+     form = AshPhoenix.Form.validate(form, socket.assigns.form)
+     _result <- AshPhoenix.Form.submit(form)
+     {:noreply, push_navigate(socket, to: ~p"/")}
+   end
+   |> Rail.flat_map_error(fn form -> {:noreply, assign(socket, :form, form)} end)
+ end

@jechol jechol merged commit 67dda43 into jechol:main Jul 26, 2023
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants