fbonetti/elm-phoenix-socket
소개
Pure Elm state manager for Phoenix channels
웹 및 앱 개발측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalelm-phoenix-socket
This library is a pure Elm interpretation of the Phoenix.Socket library that comes bundled with the Phoenix web framework. It aims to abstract away the more tedious bits of communicating with Phoenix, such as joining channels, leaving channels, registering event handlers, and handling errors.
Setup
Phoenix connections are stateful. The Socket module will manage all of this for you, but you need to add some boilerplate to your project to wire everything up.
Import all three
Phoenixmodulesimport Phoenix.Socket import Phoenix.Channel import Phoenix.PushAdd a socket to your model
type alias Model = { phxSocket : Phoenix.Socket.Socket Msg }Initialize the socket. The default path for Phoenix in development is
"ws://localhost:4000/socket/websocket".init = { phxSocket = Phoenix.Socket.init "PATH_TO_SERVER" }Add a PhoenixMsg tag to your Msg type
type Msg = UpdateSomething | DoSomethingElse | PhoenixMsg (Phoenix.Socket.Msg Msg)Add the following to your update function
PhoenixMsg msg -> let ( phxSocket, phxCmd ) = Phoenix.Socket.update msg model.phxSocket in ( { model | phxSocket = phxSocket } , Cmd.map PhoenixMsg phxCmd )Listen for messages
subscriptions : Model -> Sub Msg subscriptions model = Phoenix.Socket.listen model.phxSocket PhoenixMsg
Take a look at examples/Chat.elm if you want to see an example.
Contributing
Pull requests and issues are greatly appreciated! If you think there's a better way to implement this library, I'd love to hear your feedback. I basically tried to model this library after the official javascript one, but that may not be the best approach.
관련 프로젝트 살펴보기
불러오는 중…