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

action-stream

v0.4.2

Published

A stream library for Model-View-Steram.

Downloads

16

Readme

action-stream

It is a library for realizing Model - View - Stream architecture.

Purpose

You can realize the Uni-direction data flow architecture using the Node Stream API. Presentation logic can be divided into multiple modules with common API.

All events of user intaraction and model modification are convert as a action objet. Actions flow in the stream. Modules of this architecture are in the stream. They respond to actions that have flowed through the stream.

The amount of source code increases.

See also

Model View Streamのご提案 - Qiita (Japanese)

Usage

Setup

npm install action-stream

Classes

ActionReadable

It converts View(user intaraction) events to actions and pushes that actions to the stream.

An action is an object with target property and type property.

example:

import {
  ActionReadable
}
from 'action-stream'

export default class extends ActionReadable {
  constructor(selector) {
    super(selector)
    this.name = 'ActionReaderSample'
  }
  _bindComponent(selector, push) {
    let component = document.querySelector(selector)

    component
      .querySelector('.button')
      .addEventListener('click', e => push({
        target: 'some',
        type: 'any'
      }))
}

FunnelStream

It bundles multiple action streams into the stream.

example:

import {
  FunnelStream
}
from 'action-stream'
import ActionStream1 from './ActionStream1'
import ActionStream2 from './ActionStream2'

let funnel = new FunnelStream(true)

new ActionStream1(selector.INPUT_NODE).pipe(funnel)
new ActionStream2(selector.EDIT_NODE).pipe(funnel)

export default funnel

If you set the first argument of the constructor to true, it output passing actions by console.log.

ActionTransform

It responds to the action flowing through the stream and modify the Model and View.

Example 1 Model

Whether it reacts to an action is distinguished by the action's taget and type.

Specify a target to react to the first argument of bindActions method. The second argument to the bindActions method is an array consisting of a pair of type and a function to be executed.

The arguments of the callback function are the received action and the function to flow the action to the stream.

import {
  ActionTransform
}
from 'action-stream'

export default class extends ActionTransform {
  constructor(model) {
    super()
    this.name = 'ModelStream'

    this.bindActions('same', [
      ['any', (action, push) => madel.doAnything(action)]
    ])
  }
}
Example 2 View
import {
  ActionTransform
}
from 'action-stream'

export default class extends ActionTransform {
  constructor(selector) {
    super()
    let component = document.querySelectorAll(selector)

    bindActions('same', [
      ['any', (action, push) => {
        if (action.type === 'any')
          _component.innerHTML = `<div>${action.target}<div>`
      }]
    ])
  }
}

TailStream

It terminate the stream.

example:

import {
  TailStream
}
from 'action-stream'
import RenderStreamSample from './RenderStreamSample'

let stream = new RenderStreamSample(),
  tailStream = new TailStream(true)

stream
  .pipe(tailStream)

export default stream

If you set the first argument of the constructor to true, it output received actions by console.log. You can see all the actions going through the stream.

API document

https://doc.esdoc.org/github.com/ledsun/action-stream/

For development

Setup

npm install

Build

npm start

Test

npm test

Update the API document

  1. Open [ESDoc Hosting Service](https://doc.esdoc.org/-/generate.html)
  2. Input [email protected]:ledsun/action-stream.git
  3. Push Generate