0.2.6 • Published 6 years ago

redsock v0.2.6

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

socket.red

A websocket server for executing your apis, dispatching redux actions on clients and emitting events from server.

Installation

$ yarn add redsock $ npm install --save redsock

Usage

  • Starting the server
import { start } from 'redsock';

const url = 'redsock/:app/:token';
start({ port, url }, (session) => {
  
});
  • Declaring and binding your api
import { createScope } from 'redsock';

const demo = createScope('demo');

async function clap(numberOfHands) {
  if (!numberOfHands) {
    throw new Error('Cannot clap without any hands');
  }

  if (numberOfHands > 2) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        if (numberOfHands > 10) {
          reject(new Error('What kind of a monster are you?'));
        } else {
          resolve('Its difficult to clap with so many hands');
        }
      }, 500);
    });
  }

  return `Clap Clap Clap with ${numberOfHands}`;
}

// Expose clap via demo scope
demo(clap);
0.2.6

6 years ago

0.2.5

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago