utility library for async iterable iterators

Overview

⚠️ This library is no longer maintained, and should not be used in production applications.

Build Status Coverage Status Join the chat at https://gitter.im/crcn/mesh.js

Mesh is a utility library for async iterable iterators.

Motivation

This library was originally created to handle complex data flows, and unify how applications communicate internally and externally. It also serves as a single channel for all communication which makes it more easy to control & reason about how your application is passing around data asynchronously.

Mesh provides a set of higher order functions that you can use to build your data flows out. Here's an example of that:

import { when, wrapAsyncIterableIterator, fallback } from "mesh";
import { 
  DS_FIND, 
  DS_INSERT, 
  DS_REMOVE, 
  DS_UPDATE, 
  dataStore, 
  DSFindMessage,
  whenCollection,
  DSInsertMessage,
  DSRemoveMessage,
  DSUpdateMessage,
} from "mesh-ds";

const insertTodoItem = (message: DSInsertMessage) => (
  wrapAsnycIterableIterator(fetch('/api/todos', {
    method: 'POST',
    body: message.data
  }))
);

const insert = fallback(
  whenCollection('todos', insertTodoItem),

  // more collections below
  // whenCollection('users', insertUser),
  // whenCollection('items', insertItem),
);

const dsDispatch = dataStore({
  [DS_INSERT] : insert,

  // other operations - similar code to insert
  //[DS_REMOVE] : remove,
  //[DS_UPDATE] : update,
  //[DS_FIND]   : find
});

Installation

NPM: npm install mesh
Bower: bower install mesh

Resources

Comments
  • change mesh.child to something else

    change mesh.child to something else

    because of cases like this:

    var bus = mesh.parallel();
    users = mesh.child(bus, { collection: "user" });
    friends = mesh.child(bus, { collection: "friend" });
    

    something that describes that properties are getting attached to each operation. Ideas:

    glue, attach, addon, bind, copy, merge, hitch

    Hitch seems like the most appropriate name to use as an alternative

    opened by crcn 4
  • consider more explicit approach to ending a stream

    consider more explicit approach to ending a stream

    Instead of this:

    if (!(yield response.read())) console.log("done!");
    

    do this:

    if (!(yield response.read().done)) console.log("done!");
    

    Just to maintain some standard with es6 stuff (streams & iterators).

    See this: https://streams.spec.whatwg.org/#reader-read and this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols

    maybe 
    opened by crcn 2
  • mesh.idle

    mesh.idle

    useful for waiting on asynchronous data. E.g: async react rendering.

    bus = mesh.idle(bus, onIdle);
    

    Example:

    server.get("/home", function(req, res) {
    
      var component = React.createElement(ComponentWithAsyncStuff, { 
        bus: mesh.idle(bus, function() {
          res.send(React.renderToString(component));
        })
      });
    
      // do a render
      component.render();
    });
    
    feature high priority completed 
    opened by crcn 2
  • race condition with limit

    race condition with limit

    bus = mesh.limit(1, bus);
    
    // fallback is async - second arg gets hit first
    bus = mesh.accept("load", mesh.fallback(bus), bus); 
    bus(mesh.op("load")); 
    bus(mesh.op("insert")); // this gets executed first
    

    Fix is to put limit at the end. This is a bit awkward though.

    bug wontfix 
    opened by crcn 2
  • intercept adapter

    intercept adapter

    something like this - not fully fleshed out yet

    var db = localdb();
    
    var db = crudlet.intercept(db, condition, function (operation) {
      if (someConditionIsMet) return some
    });
    
    adapter completed 
    opened by crcn 2
  • operations should be streamable

    operations should be streamable

    var op = crudlet.operation("insert", { filename: "/gridfs.txt", file: fs.readFile("/file/to/add") });
    crudlet.stream(db).write(op);
    
    feature wontfix 
    opened by crcn 2
  • CallbackBus alias for WrapBus

    CallbackBus alias for WrapBus

    This is more clear than using WrapBus for the same thing:

    const actor = new CallbackBus(action => console.log(action.type));
    actor.execute(new Action("doSomething"));
    
    feature wontfix 
    opened by crcn 1
  • is this ready for near term production use?

    is this ready for near term production use?

    Hi Craig, I have been following the development of mesh for about a month (since you pointed it out on the sift list). Can you give any guidance on current readiness for a near term production use (by an outside party)? Are the basic interfaces stable? I noticed you moved a lot of specific bus implementations into 'packages', and I suspect you will continue evolving those more aggressively, but are the core Bus and Response interfaces 'stable' at this point.

    This seems like (another) really useful core tech.

    Thanks, JohnL

    question 
    opened by johnwillyn 1
  • ability to pause responses

    ability to pause responses

    var response = new AsyncResponse(function(writable) {
        var chunks = ["i", "o", "u"];
    
        function pump() {
            if (!chunks.length) return writable.end();
    
            // wait for readable to take chunk written
            writable.write(chunks.shift()).then(pump);
        }
        pump();
    });
    
    // read the chunk
    response.read();
    
    setTimeout(function() {
            // signal write
        response.read(); 
    }, 500);
    
    feature wontfix 
    opened by crcn 1
  • deprecate mesh.attach

    deprecate mesh.attach

    Change to mesh.transform instead, or similar:

    mesh.transform(extend.bind({ name: "someOpName" }), bus);
    mesh.transform(defaults.bind({ name: "someOpName" }), bus);
    
    wontfix cleanup 
    opened by crcn 1
Releases(6.0.0)
Owner
Craig Condon
Craig Condon
JavaScript's utility _ belt

__ /\ \ __ __ __ ___ \_\ \ __ _ __ ____ ___ ___ _ __

Jeremy Ashkenas 26.7k Jan 4, 2023
A Javascript library for working with native objects.

Sugar A Javascript library for working with native objects. Install Upgrading Getting Started Documentation Custom Builds Browser npm Modules Date Loc

Andrew Plummer 4.5k Dec 24, 2022
utility library for async iterable iterators

⚠️ This library is no longer maintained, and should not be used in production applications. Mesh is a utility library for async iterable iterators. Mo

Craig Condon 1k Jul 29, 2022
A workshop about JavaScript iteration protocols: iterator, iterable, async iterator, async iterable

JavaScript Iteration protocol workshop A workshop about JavaScript iteration protocols: iterator, iterable, async iterator, async iterable by @loige.

Luciano Mammino 96 Dec 20, 2022
Utility functions for iterators. Inspired by Rust's `std::iter::Iterator` trait.

iter-funcs About Utility functions for iterators. Inspired by Rust's std::iter::Iterator trait. This library uses JavaScript native iterators, so it's

Shuntaro Nishizawa 6 Dec 27, 2022
Async concurrent iterator (async forEach)

each-async Async concurrent iterator (async forEach) Like async.each(), but tiny. I often use async.each() for doing async operations when iterating,

Sindre Sorhus 107 Oct 21, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Typesafe API for processing iterable data in TypeScript and JavaScript.

Stream API Type-safe API for processing iterable data in TypeScript and JavaScript similarly to Java 8 Stream API, LINQ or Kotlin Sequences. Unlike Rx

Norbert Szilagyi 31 Aug 4, 2022
Well-tested utility functions dealing with async iterables

aitertools This library provides a well-tested collection of small utility functions dealing with async iterables. You can think of it as LINQ or aite

Hong Minhee (洪 民憙) 11 Aug 15, 2022
A utility for creating toggleable items with JavaScript. Inspired by bootstrap's toggle utility. Implemented in vanillaJS in a functional style.

LUX TOGGLE Demo: https://jesschampion.github.io/lux-toggle/ A utility for creating toggleable dom elements with JavaScript. Inspired by bootstrap's to

Jess Champion 2 Oct 3, 2020
FieldVal - multipurpose validation library. Supports both sync and async validation.

FieldVal-JS The FieldVal-JS library allows you to easily validate data and provide readable and structured error reports. Documentation and Examples D

null 137 Sep 24, 2022
An async control-flow library that makes stepping through logic easy.

Step A simple control-flow library for node.JS that makes parallel execution, serial execution, and error handling painless. How to install Simply cop

Tim Caswell 2.2k Dec 22, 2022
A platformer game using Phaser3 library and Vanilla JS. This project features the knowledge of Webpack, ES6, JS Modules, Async code, DOM, JSON and Jest tests.

RUNNING BUNNY A platformer game using Phaser3 library and Vanilla JS. This project features the knowledge of Webpack, ES6, JS Modules, Async code, DOM

Ana Paula Hübner 27 Mar 29, 2022
A regular table library, for async and virtual data models.

A Javascript library for the browser, regular-table exports a custom element named <regular-table>, which renders a regular HTML <table> to a sticky p

J.P. Morgan Chase & Co. 285 Dec 16, 2022
Async utilities for node and the browser

Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed f

Caolan McMahon 27.8k Dec 31, 2022
A solid, fast Promises/A+ and when() implementation, plus other async goodies.

when.js When.js is a rock solid, battle-tested Promises/A+ and when() implementation, including a complete ES6 Promise shim. It's a powerful combinati

The Javascript Architectural Toolkit 3.4k Dec 18, 2022
Expressive middleware for node.js using ES2017 async functions

Expressive HTTP middleware framework for node.js to make web applications and APIs more enjoyable to write. Koa's middleware stack flows in a stack-li

Koa.js 33.5k Jan 4, 2023
CSP channels for Javascript (like Clojurescript's core.async, or Go) THIS IS AN UPSTREAM FORK

js-csp Communicating sequential processes for Javascript (like Clojurescript core.async, or Go). Examples var csp = require("js-csp"); Pingpong (porte

James Long 283 Sep 22, 2022