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 🙏

© 2025 – Pkg Stats / Ryan Hefner

bobflux

v11.1.0

Published

Bobflux is pure functional implementation of FLUX architecture.

Downloads

39

Readme

Bobflux

  • is pure functional implementation of FLUX architecture
  • is inspired by Flux, Reflux and Redux
  • fits and depends on Bobril

Installation

npm i bobflux --save

How to run example through bobril-build

npm install bobril-build -g

bb

Fun-model

  • is core of bobflux,
  • is independent on bobril, can be used for React applications,
  • there is fun-model you can see some notes about flux, immutability etc.

Common keywords in Bobflux application

  • one store for one application state
  • application state:
  • is global state
  • is composition of sub states
  • actions are create by action factory with specified cursor and handler. Handler creates new instance of state or it can return the same state
  • Bobril is here for "rendering" (View)
  • Bobril component context (b.IBobrilCtx) should be used for intermediate state (drag & drop, input border color on focus etc.)

Lifecycle

Getting started video [cz]

Getting started video

State

  • is object
  • is global state of application
  • one instance is held in store
  • default state must be set before firts usage
//state.ts
import * as f from 'bobflux';

export interface ITodo {
    id: number;
    isDone: boolean;
    name: string;
}

export interface ITodosState extends f.IState {
    editedTodo: ITodo;
    todos: ITodo[];
}
//app.ts - main application file in bobril-build or systemjs
import * as f from 'bobflux';
import * as s from './states';

f.bootstrap(s.default());

Views/Pages

  • can be pure bobril components or can be created by bobflux

Bobflux Components

  • is derived component from Bobril
  • gets state through cursor which has been specified in creation
  • sets last state into component context
  • offers state property in context (ctx.state)
  • component should not have data
  • all data should be passed by state
  • why?
  • implements shouldChange and holds last state from last rendering
  • protects against useless rendering parts in your application
  • there are two kinds of components:
  • component
    • is common component which has state in context
  • routeComponent
    • is fitted for bobril router and has state in context
    • is virtual component which wrappes bobflux component
    • bobflux component cannot be used in router beacause you can not specify cursor in route handler. Creation is invoked by router.
  • if you operate with b.invalidate(ctx) in your component you can force shouldChange by ctx.forceShouldChange
import * as b from 'bobril';
import * as gui from 'bobril-css-bootstrap';
import * as f from 'bobflux';
import * as s from './states';
import * as a from './actions';
import * as c from './cursors';

export let create = f.createRouteComponent<s.ITodosState, any>({
    render(ctx: f.IContext<s.ITodosState>, me: b.IBobrilNode, oldMe?: b.IBobrilCacheNode) {
        me.children = [
            addForm(c.editedTodo),
            table(c.todos)
        ]
    }
})

let addForm = f.createComponent<s.ITodo, any>({
    render(ctx: f.IContext<s.ITodo>, me: b.IBobrilNode, oldMe?: b.IBobrilCacheNode) {
        me.children = gui.form({
            isInlined: true,
            content: [
                gui.inputFormField('', ctx.state.name, a.updateNewTodoName),
                gui.button({ label: 'Add', onClick: () => { a.addTodo(); return true; } })
            ]
        })
    }
})

Cursor

  • has key which specifies path to target propery of objects or subobjects in global application state
  • there are two kinds of cursors:
  • for maps - "all objects/classes" in js
export let editedTodoName: f.ICursor<string> = {
    key: 'todoSection.editedTodo.name'
}

export let todos: f.ICursor<s.ITodo[]> = {
    key: 'todoSection.todos'
}
  • for array items with static cursor key
export let firstTodo: f.ICursor<s.ITodo> = {
    key: 'todoSection.todos.0'
}

export let firstTodoName: f.ICursor<string> = {
    key: 'todoSection.todos.0.name'
}
  • for array items with dynamic cursor key
export let todosIndexFactory: f.ICursorFactory<s.ITodo, number> = {
    create: (index) => {
        return { key: `todoSection.todos.${index}` };
    }    
}

export let todoNameThroghtIndexFactory: f.ICursorFactory<string, number> = {
    create: (index) => {
        return { key: `todoSection.todos.${index}.name` };
    }    
}

Action

  • returns new instances of modified state and its sub states
  • beware on array operations like push etc.
  • use as much as possible specific cursors
  • if you want to modify more sub states then you should create two actions with specified cursors. Then invoke actions synchronously. b.invalidate waits for both actions. If actions take a long time then intermediate state will be rendered between actions.
  • function should not be passed through parameters into action

Common creation and invoking

  • implementation:
export let removeTodo = f.createAction<s.ITodo[], number>(c.todos, (todos, id) => {
    return [...todos.filter(t => t.id !== id)];
});
  • invoking:
actions.removeTodo(t.id);

Without parameters

  • implementation:
export let removeTodoId1 = bobflux.createAction(cursors.todos, (todos: states.ITodo[]): states.ITodo[] => {
    return [...todos.filter(t => t.id !== 1)];
});
  • invoking:
actions.removeStaticTodo();

If you need pass more parameters into action

  • implementation:
export interface IChangeDoneStatusParams {
    id: number;
    isDone: boolean;
}

export let changeDoneStatus = f.createAction<s.ITodo[], IChangeDoneStatusParams>(c.todos, (todos, params) => {
    return todos.map(t => {
        if (t.id === params.id)
            return f.shallowCopy(t, (nT) => {
                nT.isDone = params.isDone;
                return nT;
            });
        return t;
    })
});
  • invoking:
 actions.changeDoneStatus({ id: t.id, isDone: value })

With cursor factory

  • implementation:
let testAction = af.createAction<tds.ITodo, tds.ITodoParams>(
    {
        create: (params) => {
            return { key: `todos.${params.index}` };
        }
    },
    (state, params) => { return params.todo }
);
  • invoking:
testAction({ index: 1, todo: { done: false, name: 'New second todo' } });

Issues

  • beware on invoking because params of actions are optional!!! Compiler cannot check this mistake.