pipe-core

Pipe is a framework for creating fast and responsive HTML5 applications.

Usage no npm install needed!

<script type="module">
  import pipeCore from 'https://cdn.skypack.dev/pipe-core';
</script>

README

Build Status

pipe-core

Pipe is a framework for creating fast and responsive HTML5 applications. It enables you to build an architecture which offloads work to Workers and SharedWorkers, and communicate easily between them.

Get the code

bower install KevinGrandon/pipe.js

Example Usage

Include pipe.js in your page

<script defer src="/bower_components/pipe-core/pipe.js"></script>

Requesting data

var pipe = new Pipe({src: '/myworker.js'});
pipe.request('myEventFetchSomeData').then(results => {
  results.forEach(result => {
    // Do something with the result.
  });
});

Listening for data, from a worker

importScripts('/bower_components/pipe-core/pipe.js');

var pipe = new Pipe();

pipe.handle('myEventFetchSomeData', () => {
  return new Promise(resolve => {
    resolve([/* ... */]);
  });
});

Multiple Workers

You can setup a pipe to communicate to multiple workers by passing an array of srcs into the constructor.

var pipe = new Pipe({src: [
    '/first_worker.js'
    '/second_worker.js'
]});
pipe.request('fetchFromOneWorker').then(results => {
  results.forEach(result => {
    // Do something with the result.
  });
});

Overriding Worker Types

You can override the worker types via configuration. For now this is how you would specify a SharedWorker.

var overrides = {
  '/second_worker.js': {
    WorkerClass: SharedWorker
  }
};

var pipe = new Pipe({src: [
    '/first_worker.js'
    '/second_worker.js'
],
overrides: overrides});