Skip to content

Commit

Permalink
clarify stream bulk insert (phoenixframework#3023)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen Deusch committed Jan 18, 2024
1 parent b3bc8ed commit f85318b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/phoenix_live_view.ex
Expand Up @@ -1532,6 +1532,19 @@ defmodule Phoenix.LiveView do
collection on the client. By default `-1` is used, which appends the items
to the parent DOM container. A value of `0` prepends the items.
Note that this operation is equal to inserting the items one by one, each at
the given index. Therefore, when inserting multiple items at an index other than `-1`,
the UI will display the items in reverse order:
stream(socket, :songs, [song1, song2, song3], at: 0])
In this case the UI will prepend `song1`, then `song2` and then `song3`, so it will show
`song3`, `song2`, `song1` and then any previously inserted items.
To insert in the order of the list, use `Enum.reverse/1`:
stream(socket, :songs, Enum.reverse([song1, song2, song3]), at: 0])
* `:reset` - the boolean to reset the stream on the client or not. Defaults
to `false`.
Expand Down

0 comments on commit f85318b

Please sign in to comment.