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

alt-ng

v1.3.1

Published

A new generation of the alt flux implementation

Downloads

10

Readme

alt-ng

Build Status Coverage Status

alt-ng is a Flux implementation that removes all the boilerplate traditionally associated to managing data. alt-ng is based on JavaScript classes, does not use switch statements and supports Promises out-of-the-box. Check out the tutorial, or jump straight into the documentation.

Features of alt-ng

  • Promises are first class citizens
  • Lightweight: A lot of code has been removed from the original alt implementation to make it even more lightweight
  • No constants or switch statements: Removes all the boilerplate of traditional Flux frameworks
  • Unidirectional flow of information: Enforces the basic principles in flux
  • Follows the Flux Standard Action standard.
  • Designed to work in both the client and server side
  • Actively maintained and being used in production.
  • Based on ES6 classes

Code example

With alt-ng, action results are automatically dispatched to methods in the stores:

alt.js

import Alt from "alt-ng";

// create our singleton instance
export default new Alt();

UserActions.js

import alt from './alt';

// Mock remote API
// The real thing would connect to the server using Fetch API or a polyfill
const MyUserApi = {
  fetch: function(userId) {
    console.log(`Retrieving user ${userId}`);
    return Promise.resolve({
      id: userId,
      name: `User ${userId}`
    });
  },
  save: function(user) {
    console.log(`Saving user ${user.id}`);
    return Promise.resolve(user);
  }
}

export default alt.createActions('UserActions', {

  // Promises are transparently resolved before dispatching to the Store
  fetchUser: function(userId) => {
    return MyUserApi.fetch(userId);
  }

  // more Promises
  saveUser: function(user) => {
    return MyUserApi.save(user);
  }

  // other values are dispatched directly to the Store
  onChange: function(attributeName, value) {
    let value = {};
    value[attributeName] = value;
    return value;
  }

})

The action methods will be used as constants while binding.

UserStore.js

import alt from './alt';
import UserActions from './UserActions';
import Store from 'alt-ng/Store';

// This Store will contain the User that is being edited right now as its 'state' attribute.
// The Store methods will be notified when the actions are dispatced
class UserStore extends Store {

  constructor() {
    this.state = {
      user: undefined
    };
    this.bindActions(UserActions);
  }

  fetchUser(user) {
    this.setState({ user });
  }

  saveUser(user) {
    this.setState({ user });
  }

  onChange(userField) {
    this.setState({
      user: Object.assign(this.getState().user, userField))
    });
  }

}
const userStore = alt.createStore('UserStore', new UserStore());
export { userACtions, userStore };

The easiest way to use this Store is to inject state as properties to the view:

import UserStore from "./UserStore";
import UserACtions from "./UserActions";
import AltContainer from "alt-ng/AltContainer";
import React from "react";

class UserData extends React.Component {
  constructor() {
    this.onChange = this.onChange.bind(this);
    this.onSubmit = this.onSubmit.bind(this);
  }

  onChange(e) {
    UserActions.onChange(e.name, e.value);
  }

  onSubmit(e) {
    e.preventDefault();
    // after a successful page save, send the browser somewhere else
    UserActions.save(this.props.user).then(() => {
      location.href = "/users";
    });
  }

  render() {
    const user = this.props.user;
    return (
      <form onSubmit={this.onSubmit}>
        <label>
          Name:
          <input name="name" value={user.name} onChange={this.onChange} />
        </label>
        <button type="submit" />
      </form>
    );
  }
}

class MyApp extends React.Component {
  render() {
    // inject userStore.state as UserData.props
    return (
      <AltContainer store={userStore}>
        <UserData />
      </AltContainer>
    );
  }
}

You can get the full story by reading the tutorial or the documentation.

License

Licensed under the MIT license

alt-ng is based on the great job by Josh Perez, the original author of Alt