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
Server side (only if you need to run some of your modules on the server)
const express = require('express')
const { setStrimModules } = require('strim-js/dist/strimModules');
const app = express()
setStrimModules(app, { modulesPath: './myStrimModules' });
Client side
Full Example
import Strim from 'strim-js'
new Strim()
.pipe({
module: 'globals',
func: 'get',
args: [1, 2, 4],
})
.toServer()
.pipe({
module: 'globals',
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.:
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