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

simfluxy

v1.0.4

Published

A simplified version of redux for state management including async operation in actions

Downloads

21

Readme

SimFluxy

A simple javascript library implementing the flux architecture.

Features

  • Unidirectional data flow
  • Asynchronous dispatches using wait(promise, actionType)
  • Supports multiple reducers
  • Subscribe to state changes in the store

Simluxy does not use any middleware to support asynchronous tasks before dispatch. It exposes a method called wait() which dispatches a specified action once the promise argument to it resolves

Visualization

Visual

Installation

Use: npm i --save simfluxy

Getting Started

// Basic usage:
import Simfluxy from 'simfluxy'

// Initial setup:
const myStore = new Simfluxy(reducers) /* reducers: { state property: () => { returns new state property }, } */
myStore.initState(initialState) /* initialState: Plain object */

// Dispatch actions:
myStore.dispatch(action) /* action: { type: string, [<other-props(data)>: { ... }] } */

// Read the state:
myStore.getState()

// Subscribe to state changes:
const unsubscribe = myStore.subscribe(handler) /* handler: a function that receives the state */
unsubscribe() // unsubscribe

// Async: Dispatch promise responses with wait():
myStore.wait(aPromise, actionType) /* promise: An es6 promise that resolves/rejects, actionType: string */

Documentation

  • Store(reducers)
    • A constructor function that initializes the store
    • reducers: A plain object containing keys that reflect the high level store properties. Each key must be a method that receives two parameters:
      • Reference to the initial or existing state property (and not the entire state)
      • An action (String) that specifies the type of dispatch()
    • Each reducer returns a new state (without mutating the old one). This new state replaces existing state
    • No explicit return value (undefined)
  • getState()
    • Returns the current state in the store
    • Do not mutate this state. Only use it for read purposes
  • initState(initialState)
    • initialState: Must be a plain object
    • Returns true if initialized, else false
  • dispatch(action)
    • action: A plain object that contains type (String) property indicating the action type. Pass your data through other properties
    • Applies action to all the reducers, and the subscribers get notified with the final state value
    • This method internally publishes the state changes i.e notifies subscribers
    • No explicit return value (undefined)
  • subscribe(handler)
    • handler: A function that will receive the state once it gets notified
    • Returns a function to unsubscribe the handler from notifications
  • wait(aPromise, actionType)
    • aPromise: An ES6 promise. The resolved data is sent as payload through an internal dispatch()
    • actionType: The same string value used with dispatch() in order to identify an action
    • No explicit return value (undefined)

FAQs

  • Can we use this library instead of other tools like redux/mobx?

If your use case does not extend beyond multiple reducers, simple dispatches, and async disptaches, then yes!

  • How is async dispatch handled?

Simfluxy does not use any middleware. You will have to make your async calls via a promise passed to wait() which dispatches the resolved response as payload to the action specified

  • How does it handle concurrent async dispatches?

Simfluxy will handle the dispatches in the order they are received. Async dispatches are received in the order that the promises to wait() are resolved, adhering to the race-condition.

We can even have async dispatches within other async dispatches (wait() inside wait()). Again, the race condition applies here as well

  • What is the size of this library?

It can be considered as a micro-library not exceeding 5KB (Minified). Gzipping should yield a much smaller size.

Contributing

https://github.com/pushkar100/simfluxy

Linting, testing, and code coverage: npm run validate

Author(s)

Pushkar DK