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

fluxcapacitor

v1.0.11

Published

A bunch of tools to implement apps the Flux way

Downloads

18

Readme

Flux Capacitor

Just a bunch of tools to implement apps the Flux way.

Install

npm install fluxcapacitor --save

Exemple

'use strict';

const FluxCapacitor = require('fluxcapacitor');
const _ = FluxCapacitor.lodash;

let users = [];

const actions = FluxCapacitor.createActions([
  'createUser',
  'deleteUser',
  'updateUser'
]);

const events = FluxCapacitor.createEvents([
  'notifyUserListUpdated'
]);

const unsubscribe = events.notifyUserListUpdated.listen(() => console.log(users));  

const unsubscribe1 = actions.createUser.listen(user => {
  users.push(user);
  events.notifyUserListUpdated();
});

const unsubscribe2 = actions.deleteUser.listen(user => {
  users = users.filter(u => user._id !== u._id);
  events.notifyUserListUpdated();
});

const unsubscribe3 = actions.updateUser.listen(user => {
  users = users.map(u => u._id === user._id ? user : u);
  events.notifyUserListUpdated();
});

const id = FluxCapacitor.uuid();
actions.createUser({ _id: id, name: 'John Doe', age: 42 });
actions.updateUser({ _id: id, name: 'John Doe', age: 52 });
actions.deleteUser({ _id: id });

unsubscribe();
unsubscribe1();
unsubscribe2();
unsubscribe3();

const store = FluxCapacitor.createStore([actions], {
  users: [],
  events: FluxCapacitor.createEvents(['notifyUserListUpdated']),
  onCreateUser: (user) => {
    this.users.push(user);
    this.events.notifyUserListUpdated();
  },
  onDeleteUser: (user) => {
    this.users = this.users.filter(u => user._id !== u._id);
    this.events.notifyUserListUpdated();
  },
  onUpdateUser: (user) => {
    this.users = this.users.map(u => u._id === user._id ? user : u);
    this.events.notifyUserListUpdated();
  }
});

// FluxCapacitor.createStore([actions], function(theStore) { ... }) works too !

const unsubscribe4 = store.events.notifyUserListUpdated.listen(() => console.log(store.users));  
actions.createUser({ _id: id, name: 'John Doe', age: 42 });
actions.updateUser({ _id: id, name: 'John Doe', age: 52 });
actions.deleteUser({ _id: id });

store.shutdown();
unsubscribe4();

You can use ES6 class style for Stores

'use strict';

const FluxCapacitor = require('fluxcapacitor');
const _ = FluxCapacitor.lodash;
const id = FluxCapacitor.uuid();

const actions = FluxCapacitor.createActions([
  'createUser',
  'deleteUser',
  'updateUser'
]);

class TestStore extends FluxCapacitor.Store {

  constructor(actionArray) {
    super(actionArray);
    this.users = [];
    this.events = FluxCapacitor.createEvents(['notifyUserListUpdated']);
  }

  getUsers() {
    return this.users;
  }

  onCreateUser(user) {
    this.users.push(user);
    this.events.notifyUserListUpdated();
  }

  onDeleteUser(user) {
    this.users = this.users.filter((u) => user._id !== u._id);
    this.events.notifyUserListUpdated();
  }

  onUpdateUser(user) {
    this.users = this.users.map((u) => u._id === user._id ? user : u);
    this.events.notifyUserListUpdated();
  }
}

const store = new TestStore([actions]);

const unsubscribe4 = store.events.notifyUserListUpdated.listen(() => {
  console.log('[STORE] ' + JSON.stringify(store.getUsers()));
});

actions.createUser({ _id: id, name: 'Jane Doe', age: 42 });
actions.updateUser({ _id: id, name: 'Jane Doe', age: 52 });
actions.deleteUser({ _id: id });

store.shutdown();
unsubscribe4();

React mixins

var myStore = FluxCapacitor.createStore(actions, {
  events: FluxCapacitor.createEvents(['somethingChanged']),
  ...
});

var myOtherStore = FluxCapacitor.createStore(actions, {
  events: FluxCapacitor.createEvents(['otherSomethingChanged']),
  ...
});

var Component1 = React.createClass({
  mixins: [FluxCapacitor.Mixins.AutoListenAt(myStore.events.somethingChanged, 'onSomethingChanged')],
  onSomethingChanged: function(something) {
    this.setState({
      something: something
    });
  },
  render: function() {
    ...
  }
});

var Component2 = React.createClass({
  mixins: [FluxCapacitor.Mixins.AutoListen],
  listenTo: [myStore.events, myOtherStore.events]
  onSomethingChanged: function(something) {
    this.setState({
      something: something
    });
  },
  onOtherSomethingChanged: function(othersomething) {
    this.setState({
      othersomething: othersomething
    });
  },
  render: function() {
      ...
  }
});

var Component3 = React.createClass({
  mixins: [FluxCapacitor.Mixins.AutoState(myStore.events.somethingChanged, 'something')],
  render: function() {
    // here use this.state.something
  }
});

var Component4 = React.createClass({
  mixins: [FluxCapacitor.Mixins.AutoStates],
  stateFrom: [store.events.notifyUserListUpdated], // notify and updated are escaped as well as on, set, change, changed
  getInitialState: function() {
    return {
      userList: []
    };
  },
  render: function() {
    // use this.state.userList
  }
});

API

FluxCapacitor.invariant = function(condition: bool, message: string, args...): void
FluxCapacitor.invariantLog = function(condition: bool, message: string, args...): void
FluxCapacitor.uuid = function(): String
FluxCapacitor.keyMirror = function(keys: object): object
FluxCapacitor.createDispatcher = function(): Dispatcher
FluxCapacitor.createStore = function(actions: Actions, store: object): object
FluxCapacitor.Store = Store(actions: Actions) // ES6 class to inherit
FluxCapacitor.createActions = function(names: array): Actions
FluxCapacitor.createEvents = function(names: array): Events
FluxCapacitor.createAction = function(name: string): Action
FluxCapacitor.createEvent = function(name: string): Event
FluxCapacitor.withDebug = function(debug: bool): FluxCapacitor
FluxCapacitor.lodash = { ... }
FluxCapacitor.Mixins = {
  AutoListen: object
  AutoListenAt: function(event: Event, functionName: string)
  AutoState: function(event: Event, stateFieldName: string)
  AutoStates: object
}

Dispatcher.on = function(channel: string, callback: function): function
Dispatcher.off = function(channel: string, callback: function): void
Dispatcher.trigger = function(channel: string, payload: object): void
Dispatcher.triggerAsync = function(channel: string, payload: object): Promise

Action = function(payload: object): void
Action.triggerAsync = function(payload: object): Promise
Action.listen = function(callback: function): function
Action.off = function(callback: function): void

Actions.bindTo = function(target: object, [config: object]): function

Event = function(payload: object): void
Event.triggerAsync = function(payload: object): Promise
Event.listen = function(callback: function): function
Event.off = function(callback: function): void

Events.bindTo = function(target: object, [config: object]): function