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

modulajs

v1.1.0

Published

A modularization framework to manage application states using an immutable model tree

Downloads

23

Readme

ModulaJS

NPM version Build Status Coverage Status Node version Apache V2 License

ModulaJS is created to provide an intuitive and simple way of manage complex state. It introduces Model (an immutable tree) to represent the application state tree. Both actions and reactions are handled inside Model, as well as the communications and side effects. It makes the components in view layer very simple, pure and stateless.

ModulaJS works perfectly with React, or any other view library, or vanilla JavaScript.

Influences

ModulaJS is inspired by Elm and Redux, and built upon redux. Most redux middlewares and the redux dev tools should work seamlessly with ModulaJS.

Installation

Prerequisites: Node.js (>=6.0), npm version 3+.

yarn add modulajs

Or use NPM

npm install --save modulajs

Documentation

Introduction

Examples

Taking the counter example in redux, the following code implements a ModulaJS version.

The whole state is stored in Model tree of the single store, and the ONLY way to mutate a state is dispatching an action in model sender. The receiver, which handles the corresponding reaction, usually appear in pair of the sender, in the same Model class.

// counter_model.js
import { createModel, createConstants } from 'modulajs';
import PropTypes from 'prop-types';

export const ActionTypes = createConstants('COUNTER', {
  INCREMENT: null,
  DECREMENT: null
});

export const CounterModel = createModel({
  displayName: 'CounterModel',

  propTypes: {
    value: PropTypes.number.isRequired
  },

  defaults: {
    value: 0
  },

  sendIncrement() {
    this.dispatch({ type: ActionTypes.INCREMENT });
  },

  recvIncrement() {
    return {
      type: ActionTypes.INCREMENT,
      update(model) {
        const newModel = model.set('value', value => value + 1);

        return [ newModel ];
      }
    };
  },

  sendDecrement() {
    if (this.get('value') > 0) {
      this.dispatch({ type: ActionTypes.DECREMENT });
    }
  },

  recvDecrement() {
    return {
      type: ActionTypes.DECREMENT,
      update(model) {
        const newModel = model.set('value', value => value - 1);

        return [ newModel ];
      }
    };
  }
});

// app.js
import { createStore } from 'modulajs';
import { CounterModel } from './counter_model';

// Create a ModulaJS store to hold state in the decorated model
const store = createStore(CounterModel);

// Subscribe to store changing, then notify the listeners
store.subscribe(() => {
  console.log('Store has changed. The new state is:', store.getState());
});

// Bootstrap the state tree in root model
store.getState().sendInit();

// Dispatch an action with a model instance
// This is the ONLY way to mutate a state in the Store.
const getCounterModel = () => store.getState().get('decoratedModel');

getCounterModel().sendIncrement();
getCounterModel().get('value'); // 1

getCounterModel().sendDecrement();
getCounterModel().get('value'); // 0

Contributing

Please read our contributing guide for details on how to contribute to our project.

License

Apache-2.0