Skip to content

Easily export your unistore action logic to web worker threads.

Notifications You must be signed in to change notification settings

aareid10/uniops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Note: This package is no longer being maintained, migration to the lastest version of Stockroom is recommended.

A lightweight alternative to Stockroom. Get it here: UniOps. See it in action here: Demo.

Easily export your Unistore action to Web Workers for parallel computation/networking without impeding your UI.

Getting Started

General Process: Create Fx() Build( Assign( Fx().toString ) ) Bind( 'Build' ) Profit.

Create Example

const mapOperation = (a) => a * 25;

Build Example

const operators = {
  arrayOpMap : function(){
    let worker_init_msg  = "console.log('|UniOps| (%) arrayOpMap Worker: Initialized');";
    let worker           = uniops.buildOperator(...);
    return worker;
  },
}

Assign Example

uniops.buildOperator(
  worker_init_msg,
  uniops
    .assignOperator
    .array
    .map
)

Bind Example

uniops.bindOperator.replace(worker, store, 'storeAttr');

Profit


Drafting Explained

Create modular, encapsulated, atomic functions to be passed to the worker. The function's logic should be appropriate for the chosen assignment profile. Otherwise there are no conventions or limitations to consider.

Building Explained

Create a unique factory method to build a worker instance preconfigured with the following parameters:

  1. Initialization message
  2. UniOps Assignment Profile

Assigning Explained

Choose one of the following profiles to assign to the worker based on the execution goal. The point of these profiles is to offload operations that expensive or inconvenient for the UI/UX to both speed up the processing of the operation and also unblock the UI until the worker has completed the operation. A profile is loaded with custom logic which the determines the 'flavor' of that type of operation. For example, the array map profile ingests a function, which actually controls the nature of the map operation.

Assignment Profiles Explained

  • NETWORK: :
    • XHR:
      • GET: Execute an AJAX query.
    • GQL:
      • QUERY: Execute an Graph query.
  • ARRAY: :
    • Map: Map function across very large arrays.
    • Filter: Filter function across very large arrays.
    • Reduce: Reduce function across very large arrays.
    • Union (Underscore): Computes the union of the passed-in arrays: the list of unique items, in order, that are present in one or more of the arrays.
    • Intersection (Underscore): Computes the list of values that are the intersection of all the arrays. Each value in the result is present in each of the arrays.
    • Difference (Underscore): Similar to without, but returns the values from array that are not present in the other arrays.
    • Unique (Underscore): Produces a duplicate-free version of the array, using === to test object equality. In particular only the first occurrence of each value is kept. If you know in advance that the array is sorted, passing true for isSorted will run a much faster algorithm. If you want to compute unique items based on a transformation, pass an iteratee function.
    • Object (Underscore): Converts arrays into objects. Pass either a single list of [key, value] pairs, or a list of keys, and a list of values. Passing by pairs is the reverse of pairs. If duplicate keys exist, the last value wins.
  • CANVAS: :
    • Pixels: Convert a HTML5 Canvas element to Blob.
  • FILE: :
    • Upload: Upload a file.
    • Blob: Convert uploaded file to blob.

Binding Explained

Connect a built 'operator' (web worker w/ assigned profile) to a specified store attribute. Whenever the operator completes it's operation it will automatically update the store. There are two 'binding modes':

  1. Replace: Overwrites the store attribute.
  2. Modify: Partially updates the store attribute. (Coming Soon)

by Alex Reid

About

Easily export your unistore action logic to web worker threads.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published