0.1.6 • Published 7 months ago

@x-qdo/phoenix-redux-saga v0.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

phoenix-redux-saga

Library adapter to use Phoenix.js as a saga. Inspired by @trixta/phoenix-to-redux

Known limitations

Library support only one socket at a time.

Modules

Channel

Phoenix.js Channel's adapter.

Channel.joinToChannelSaga(topic, opts)

Join to socket's channel Related Phoenix.js documentation.

Kind: static method of Channel

ParamTypeDescription
topicstringChannel's topic name
optsObjectOpts of socket's channel.
opts.eventsArray.<Object>Array of events to watch.
opts.events[].namestringEvent to listen to on current channel.
opts.events[].sagaGeneratorSaga to trigger on event.
opts.chanParamsObjectParameters for the channel, for example {token: roomToken}.
opts.onErrorSagaGeneratorSaga to trigger on error.

Channel.leaveChannelSaga(topic)

Leave socket's channel

Kind: static method of Channel

ParamTypeDescription
topicstringChannel's topic name

Channel.pushToChannelSaga(topic, event, payload, opts)

Push event to socket's channel

Kind: static method of Channel

ParamTypeDescription
topicstringChannel's topic name
eventstringEvent name, for example "phx_join"
payloadObjectThe payload, for example {user_id: 123}
optsObjectOptions of push event:
opts.onReplySagaGeneratorCallback saga to trigger on success response
opts.onErrorSagaGeneratorCallback saga to trigger on error response
opts.onTimeoutSagaGeneratorCallback saga to trigger on timeout
opts.timeoutnumberThe push timeout in milliseconds

Socket

Phoenix.js Socket's adapter.

Socket.connectToSocketSaga(endPoint, opts)

Create socket connection saga Phoenix.js socket options.

Kind: static method of Socket

ParamTypeDescription
endPointstringThe string WebSocket endpoint, ie, "ws://example.com/socket" , "wss://example.com" "/socket" (inherited host & protocol)
optsObjectOpts on socket connection.

Socket.disconnectSocketSaga(code, reason)

Disconnect from socket saga. Phoenix.js disconnect socket documentation.

Kind: static method of Socket

ParamTypeDescription
codeintegerA status code for disconnection (Optional) See Mozilla documentation for valid status codes..
reasonstringA textual description of the reason to disconnect.

Installation

Add ...newPhoenixReducer to your combineReducers functions;

import { phoenixReducer } from "@x-qdo/phoenix-redux-saga";
...

export const rootReducer = (history) => combineReducers({
    ...newPhoenixReducer,

    myOtherReducer,
    myOtherAmazingReducer,
})

© 2021-2023 X-QDO OÜ

0.1.6

7 months ago

0.1.5

11 months ago

0.1.4

12 months ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago