127labs / fawkes.js

Event sourcing for Phoenix Channels

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Motivation

Handling PUSH events from Phoenix Channels can be trivial especially if you are using front-end state managers like Redux and a Side Effect model like Redux Saga that has a philosophy around PULLING the events. By event sourcing the official callbacks on Phoenix Channel client library. Fawkes ensures full control to take an event in the queue at any given time.

Example

import {call, fork} from 'redux-saga/effects'
import Fawkes from 'fawkes'

function * listenEvent$(event$) {
  while (true) {
    const message = yield call(event$.take)
    console.log(message)
  }
}

function * connectSocket(socket) {
  while (true) {
    if (!socket.isConnected()) {
      yield call([socket, socket.connect])
    }

    yield call(listenEvent$, Fawkes.createSocketEvent$(socket))
  }
}

export default function * (socket) {
  yield [
    fork(connectSocket, socket)
  ]
}

About

Event sourcing for Phoenix Channels


Languages

Language:JavaScript 100.0%