Skip to content

127labs/fawkes.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

Stars

Watchers

Forks

Packages

No packages published