Allow for multiple flash messages with the same key

22 de afișări
Accesați primul mesaj necitit

ali...@feerasta.net

necitită,
1 iun. 2020, 18:06:1701.06.2020
– phoenix-core
Right now, Phoenix uses a map to store flashes. Therefore, it is not possible to set multiple flash messages for the same key (`info`, `error`, etc...)

What do you think about changing the underlying data structure to a keyword list, so that there is no such limitation.

Chris McCord

necitită,
2 iun. 2020, 12:25:4802.06.2020
– phoeni...@googlegroups.com
Please see previous discussions on this. Thanks!

On Jun 1, 2020, at 6:06 PM, alizain via phoenix-core <phoeni...@googlegroups.com> wrote:

Right now, Phoenix uses a map to store flashes. Therefore, it is not possible to set multiple flash messages for the same key (`info`, `error`, etc...)

What do you think about changing the underlying data structure to a keyword list, so that there is no such limitation.

--
You received this message because you are subscribed to the Google Groups "phoenix-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phoenix-core...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/phoenix-core/eed72dc1-38b2-4ee0-b627-14f8eeded119%40googlegroups.com.

ali...@feerasta.net

necitită,
2 iun. 2020, 13:51:5302.06.2020
– phoenix-core
Thanks Chris!

I couldn't find anything relevant before I posted the question.

Looking more closely now, I can only find mention of a limitation that we need flashes to be JSON serializable?

If that's the case, I believe that we could change the underlying data structure to be an array of maps, which are JSON serializable, without much detriment, IMHO.

The downside would be that access by key (`:info`, `:error`) becomes less efficient. However, my guess is that the majority of access patterns for flashes are that you need to render all of them, so a list should work fine. I haven't come across many cases where you need to access a particular flash message by a known key, I'm not sure if you have?



On Tuesday, June 2, 2020 at 12:25:48 PM UTC-4, Chris McCord wrote:
Please see previous discussions on this. Thanks!
On Jun 1, 2020, at 6:06 PM, alizain via phoenix-core <phoeni...@googlegroups.com> wrote:

Right now, Phoenix uses a map to store flashes. Therefore, it is not possible to set multiple flash messages for the same key (`info`, `error`, etc...)

What do you think about changing the underlying data structure to a keyword list, so that there is no such limitation.

--
You received this message because you are subscribed to the Google Groups "phoenix-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phoeni...@googlegroups.com.

ali...@feerasta.net

necitită,
3 iun. 2020, 10:16:0303.06.2020
– phoenix-core
I found some more discussions in GitHub issues/pull-requests.

https://github.com/phoenixframework/phoenix/issues/497

It sounds like the rationale was to keep the `flash` and `session` APIs consistent with each other as simple KV stores.

That makes sense.

For more context, where we need multiple `info` or `errors` messages, our approach does something like this:

# Defined somewhere
def random_key, do: ...


# In the controller
put_flash
(conn, random_key(), {:error, message})


# In the view
<%= for {type, message} <- get_flash(conn) do %>
   
...
<% end %>

We can live with this so that the simpler uses cases are, well, simpler :)
Răspundeți tuturor
Răspundeți autorului
Redirecționați
0 mesaje noi