1.0.48 • Published 5 years ago

strim-js v1.0.48

Weekly downloads
1
License
UNLICENSED
Repository
-
Last release
5 years ago

STRIM 🌊

Streaming Transports Relay Isomorphic Modules

Installation

npm i -S strim-js

or

yarn add strim-js

Usage

Write a module in your modules directory

// myModules/myAmazingModule/package.json
// myModules/myAmazingModule/index.js

Server side (only if you need to run some of your modules on the server)

// server.js
const http = require('http')
const express = require('express')
const { setStrimModules, setWs } = require('strim-js/dist/strimModules');

const app = express()

setStrimModules(app, { modulesPath: './myStrimModules' });
const httpServer = http.createServer(app);

setWs(httpServer);
httpServer.listen(80);

Client side

// client.js

Full Example

import Strim from 'strim-js'

new Strim()
  .pipe({
    module: 'myAmazingModule',
    func: 'get',
    args: [1, 2, 4],
  })
  .toServer()
  .pipe({
    module: 'myAmazingModule',
    func: 'runningSum',
  })
  .subscribe(
    value => {
      console.log('Current Value:', value)
    },
    err => {
      console.error('Error Occurred:', err)
    },
    () => {
      console.log('Done')
    },
  )

API

Strim

The core class which activates the strim flow

Strim instance public methods

constructor(options)
  • options: An object containing general strim options.
    • wsUrl (Default 'ws://localhost:4321/strim'): The websocket url.:
    • modulesDir: define where the modules directory
pipe(options)
  • options: An object containing piped function options.
    • module (Default 'global'): The module name that will be imported for use of the pipe.
    • func (Default 'default'): The function name within the module.:
    • env (Default last func's environment): The environment in which we want the function to run in (can be Environment.Client or Environment.Server).:
    • args: arguments that will be sent to the piped function.
toClient(worker)
  • worker (Default false): Whether to open in a worker or not.
toServer(worker)
  • worker (Default false): Whether to open in a worker or not.
subscribe(onNext, onError, onComplete)
  • onNext (Default console.log): callback function that will occur every time a new value is received.
  • onError (Default console.error): callback function that will occur when an error is received.
  • onComplete: callback function that will occur the strim is complete.

setStrimModules(app, options)

  • app: The Express application to set up strim on.
  • options (Optional): An object containing further options.
    • wsRoute (Default '/strim'): The route path for strim's endpoint.
    • modulesPath (Default 'node_modules'): The path to the directory of the modules.

Development

This module is written as part of Wix guild week, we'll be happy to have people help.

just clone the repo, yarn and yarn test

1.0.48

5 years ago

1.0.47

5 years ago

1.0.46

5 years ago

1.0.45

5 years ago

1.0.44

5 years ago

1.0.43

5 years ago

1.0.42

5 years ago

1.0.41

5 years ago

1.0.40

5 years ago

1.0.39

5 years ago

1.0.38

5 years ago

1.0.37

5 years ago

1.0.36

5 years ago

1.0.35

5 years ago

1.0.34

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago