npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cycle-grid-driver

v0.1.3

Published

cycle.js grid driver

Downloads

12

Readme

NPM version Downloads

Cycle Grid

A driver providing "grid" for communcation between multiple "main cycle" components keeping them loosely coupled accross the application. Designed for creating an arhitecture (primarily for large-scale apps) where components could be separated to work “in parallel” rather than using them as children of a single main function.

This grid can be used as an API (in form of streams) for all "main cycle" components inside the application.

Why would I do that?

The idea of this concept is not to remove all parent-child relationships inside one cycle component, but if a child is not essential for parent to function and could be reused or removed it should then separated as a "indepented cycle"

For more info on the concept, check: Creating a Scalable JavaScript Application with Cycle.js

and bear in mind that this is primarily designed for creating large-scale applications.

Installation

npm install cycle-grid-driver

Usage

Basics:

import xs from 'xstream';
import {run} from '@cycle/xstream-run';
import {makeGridDriver} from 'cycle-grid-driver';

function main({ grid }) {
  // using stream "state" from grid
  const state$ = grid.get('state');

  // ... (magic occurs)
  const actions$ = somehow(); 

  return {
    grid: grid.send(actions$).with({ type: 'actions' })
      // .send(somethingElse$).with({type: 'something'})
      // .send(anotherOne$).with({label: 'another'})
  }
}

const drivers = {
  HTTP: makeGridDriver()
}

run(main, drivers);

As you can see, you can use grid to send or recieve streams. Suppose then, there are multiple components sending actions$ (labeling it using "with" object) from which we need to create state$

import xs from 'xstream';
import flattenConcurrently from 'xstream/extra/flattenConcurrently';
import {run} from '@cycle/xstream-run';
import {makeGridDriver} from 'cycle-grid-driver';

function main({ grid }) {
  // using grids "stream of streams"
  const allActions$ = grid.mainStream()
    .filter(stream => stream.with.group == 'actions')
    .compose(flattenConcurrently);

  const initialData$ = grid.mainStream()
    .filter(stream => stream.with.localStorage == true)
    .compose(flattenConcurrently);

  // ... (magic occurs)
  const state$ = somehowFrom(allActions$, initialData$); 

  return {
    grid: grid.register(state$).as('state')
      // .register(magicStream$).as('magic')
      // .send(sendAsWell$).with({ label: 'me'})
  }
}

const drivers = {
  HTTP: makeGridDriver()
}

run(main, drivers);

Multiple grid drivers

If for some reason you need to separate your streams in different grids you can do that by creating multiple grid instances. makeGridDriver() is equivalent to makeGridDriver('default') and it returns a 'default' grid instance so for creating another one just use a different id.

API

  • makeGridDriver (String): This is a function which, when called, returns a Grid Driver for Cycle.js apps. The driver is also a function, and it takes id as input, and outputs an Grid instance
  • grid.get (String): returns a stream registered as id (if stream is not created when called proxy which will imitate future stream will be returned)
  • grid.mainStream: returns a main grid stream (of streams) which are sent using grid.send. Returned stream also contains all streams that may be sent before calling this function (so it is not required to subscribe on main stream before sending anything from other components)
  • grid.send (Stream): used to send stream in grids main stream, returns object that contains with function for labeling your streams
  • grid.register (Stream): used to register stream in grid (but it is not in main stream), returns object that contains as function for assigning stream id