Messaging

messaging.channel()
Function

Returns a redux-saga Channel which emits for every message received.

Output

A redux-saga Channel which emits for every message received.

Example

function* readMessages() {
  const channel = rsf.messaging.channel();

  while(true) {
    const message = yield take(channel);
    yield put(showMessage(message));
  }
}

messaging.syncMessages(options)
Generator

Automatically dispatches a redux action every time a new message is received.

Arguments

TypeDescription
options
Optional

Object

An object to configure how the messages should be synchronised. It must contain at least the successActionCreator which must take a new message as a single argument. The other possible options are failureActionCreator which is called on channel errors and transform which is an optional transformer function to be applied to the value before it's passed to the action creator. Default to the identity function (x => x).

Example

import { showMessage } from '../actionCreators/messaging';

function* notificationsRootSaga() {
  yield fork(
    rsf.messaging.syncMessages,
    { successActionCreator: showMessage }
  );
}

messaging.syncToken(options)
Generator

Automatically dispatches a redux action every time a new registration token is received.

Arguments

TypeDescription
options
Optional

Object

An object to configure how the token should be synchronised. It must contain at least the successActionCreator which must take a single argument being the new registration token. The other possible options are failureActionCreator which is called on channel errors and transform which is an optional transformer function to be applied to the value before it's passed to the action creator. Default to the identity function (x => x).

Example

import { setToken } from '../actionCreators/messaging';

function* notificationsRootSaga() {
  yield fork(
    rsf.messaging.syncToken,
    { successActionCreator: setToken }
  );
}

messaging.tokenRefreshChannel()
Function

Returns a redux-saga Channel which emits every time the registration token is refreshed.

Output

A redux-saga Channel which emits every time the registration token is refreshed.

Example

function* refreshToken() {
  const channel = rsf.messaging.tokenRefreshChannel();

  while(true) {
    const token = yield take(channel);
    yield put(setToken(token));
  }
}