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

s-flux

v0.0.3

Published

A `simple flux` lib

Downloads

9

Readme

s-flux:a simple flux lib (测试版)

介绍

一个简单的flux工具库,支持单页应用和多页应用,支持同步action和异步action。

安装

依赖'es6-promise', npm模块指向dist/s-flux.common.jsdist/s-flux.jsdis/s-flux.min.js为浏览器直接引用,为UMD模块,es6-promise已经打包在内。

  • 浏览器直接引用:
<script src="s-flux/dist/s-flux.min.js"></script>
<script>
var Store = SFlux.Store;
var createAction = SFlux.createAction;
//...
</script>
  • commonjs模块引用:
import {Store, createAction} form 's-flux';
// or
var SFlux = require('s-flux');

API

  • Store: 数据仓库基类
// app-store.js
import {Store} from 's-flux';

// 创建一个store
var appStore = module.exports = new Store({
  // 初始化状态
  initialState = {},

  // 数据更新: mutation => {type: 'mutation type', data: 'mutation data'}
  mutation = function(state, mutation) {
    return state;
  },

  // 子模块:{key: childStore}
  modules = {},

  // 中间件
  middlewares = [],

  // store名,便于调试用
  name = 'store'
});
  • createMutationTypes: 创建一组数据更新常量
// mutation-types.js
import {createMutationTypes} from 's-flux';

module.exports = createMutationTypes({
  'INCREMENT',
  'DECREMENT',
  'OTHER',
  'BEFORE_SUBMIT',
  'SUBMIT'
});
  • createAction: 创建一个action
// actions.js
import {createAction} from 's-flux';

export var submit = createAction(function(params, {store, error, dispatch}) {
  dispatch({
    type: 'BEFORE_SUBMIT'
  }, true);

  //异步action
  setTimeout(function() {
    dispatch({
      type: 'SUBMIT',
      data: '111'
    });
  });
});
  • setGlobalStore: 注册一个全局store, 这样不要每次调用action的时候传入
// app.js
import {setGlobalStore} from 's-flux';
import appStore from './app-store';
import mutationTypes from './mutation-types';
import {submit} from './actions';

// 注册全局store
setGlobalStore(appStore);

// 调用action
console.log('loading……')
submit({})
  .then(function(data) {
    console.log('success……')
  })
  .catch(function(error) {
    /console.log('error……')
  });