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
Discussion about Flash API #497
Comments
This is nice since users wouldn't need to worry about aliasing or importing it. What kind of API do you see in the view? Would a
The list approach was to allow multiple registrations. I was thinking in terms of plugs where independent plugs could register a :notice, or :error. With a regular k/v approach, you either overwrite the key, or you have to know in advance that multiple registrations are possible and write your plugs accordingly to handle things as a list. At the same time, then you also need to know in the template that your value is a list and handle accordingly. The Flash API was designed to give the same same k/v style put/get, but also support lists as needed. Is this a worthy tradeoff? We've gotten by fine in Rails with just k/v, so I'm not married to the current approach, but it does have pros. |
I prefer the module API for both flash and session. It scales better as you add more functionality. Why does flash and session need to have similar APIs though? I don't feel they have any overlap except that both are KV stores. |
@chrismccord for views we would have a flash() function in Phoenix.HTML.Flash or something of sorts. I thought the design was for multiple entries. I have two concerns:
@ericmj well, having similar APIs is easier for the user. It is more consistent, less to think about, etc. |
Another option is to name the functions flash, put_flash and so on but still have them in |
I've had this thought from time to time as well, but it would be app dependent. More often than not, it will be best as a single message.
This might be a happy middle ground. conn
|> put_flash(:notice, "Great Work!")
|> render("show.html") <%= get_flash(@conn, :notice) %> Looks nice.
I like the |
Should we do the same for session? My concern for session is that it would require someone setting up a plug and importing a module, is that ok? /cc @ericmj |
I still prefer namespacing the functions to modules. It's OK to go to other modules for functionality that is not "core" to the |
I like the idea of just renaming the Flash functions to |
Today the Flash API exits in its own module. This discussion is to make a counter-proposal to the existing API and in order to resemble more its session counterparts.
Instead of defining many modules,
Plug.Conn
hosts all helpers in a single module. For example, for manipulating the session, one should call:fetch_session/2
get_session/2
put_session/3
configure_session/2
delete_session/2
The Flash module in Phoenix however packs everything into one exclusive module. Here is a counter proposal to organize it as the session:
Flash.call/2
->fetch_flash/2
Flash.get/2
->flash/2
Flash.put/3
->put_flash/2
Flash.delete/2
->delete_flash/2
Flash.clear/1
->clear_flash/1
We have two options here:
Both approaches have their vantages and disadvantages.
In any case, I would also like to discuss the current design where flash messages are stored in a list. I would vote to keep the flash as a simple kv storage instead of storing each value in a list (flash should be general purpose as it is not used only for messages).
/cc @chrismccord @ericmj
The text was updated successfully, but these errors were encountered: