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

fluxmax

v0.0.2

Published

2 phase events: update stores then views. 1 way flow. Static event deps checker.

Downloads

5

Readme

fluxmax

2 phase events: update stores then views. 1 way flow. Static event deps checker.

Quick features:

  • Update stores properly and naturally;
  • Static event deps checker and output (a typo in an event is caught at boot);
  • 1 way flow like flux by Facebook;

Quick view about the 2 phase system

2 phases

Install

npm install fluxmax --save-dev

API

Check the full API here.

Rationale

To understand the power of fluxmax we need to use multiple stores which depends on themselves.

Store A -> Store B
  |          |
  -<---<---<--

Example

Solve a complex situation like the following can be handled easily (See here the full source):

Rules:

  • When a task is added the user gets 1 point;
  • When a task is done manually or automatically the user gets a random number of points;
  • Each task has a threshold which defines the minimum of points the user needs to have to complete automatically; When this threshold is reached the task auto completes.
  • When a task passes from completed to not complete the user lose the points;

Flow:

  • User adds a new task which auto completes when the user has 2 points;
  • On adding a task the user receives 1 point;
  • User adds another task which adds 1 point and auto completes when the user has 5 points.
    • Now the user has a total of 2 points;
    • The first task is done.
    • When the first task is done the user receives 10 points;
    • This will also complete the 2nd task because the user now has 12 points;

Can you see how this is not a simple job to do in flux. When this is done in flux the code becomes complicated and doesn't feel natural, which increases the complexity of the app.

How it doesn't update the view multiple times?

A naive way to solve these problems is to be able to make the store A to update store B and then store B to update store A. But when store A changes the view updates so there is a problem: the store A changes twice after an action and the view that listen to the store A will update twice. This will be an issue when the application grow. So here is how this library solves this problem.

Each phase

There is a first event phase which only the stores listen to, which is called the "each" phase. In this phase store A emits twice, but the view doesn't listen to the "each" phase so it doesn't get updated.

Batch phase

The second phase is the "batch" phase which gets called on the next animation frame and dispatches only one event from store A. So if the store A dispatched the event "test" twice with data 1 and then data 2 the view will only only receive one "test" event with data [1, 2]. Notice how you don't lose any data along while grouping the events from the "each" phase.

Deeper understanding

The first phase is called each (because dispatches on each change) and the listeners receives the event as soon as it's dispatched. The second phase is called batch (because dispatches the events on batch) and the listeners receives the event only when the Fluxmax.emitBatchChanges method is called.

Dependencies

Fluxmax makes very easy to see how your app is wired internally, just open the console and you will see all the dependencies:

dependencies

Dependency defined in "store.task" on "actions" at type "ui.tasks.addTask" is valid. [each]

The first line says the task store listens on the entity actions on the event ui.tasks.addTask. The entity actions is used from the view/UI part of the app. The [each] part at the end tells that is listening on the each phase.

Dependency defined in "ui.user" on "store.user" at type "*" is valid. [batch]

The last line says the the ui.user entity, which is the view of the user which contains the points, listens on * events (this means that listen to all the events) on the user store. Notice that at the end now says [batch], this means that the view is listening on the batch phase.

How to use

Is not very easy to get started and there are a lot of rules to make it work. Because of this a tutorial here would not be a good approach to explain how it works. The best way to understand is to read the source code of the fluxmax-smart-css.