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

clearflux

v0.1.7

Published

A more clear simple flux. Store with loading and errors watching. Actions are only functions.

Downloads

14

Readme

clearflux NPM version Build Status Dependency Status Coverage percentage

Install

$ npm install --save clearflux

Usage

初始化 Store 和 Actions

// ES5
var Store = require('clearflux').Store;
var Actions = require('clearflux').Actions;

// ES6
import {Store, Actions} from 'clearflux';

var myStore = new Store({
  foo: 1,
  foo1: {a: 1}
});

var myAction = new Actions(myStore, {
  // myAction 初始化时会马上执行
  initStore() {
    // putStore 替换整个指定的属性,第一个参数,称作 Query。
    this.putStore('foo', 2);
    this.putStore('foo1.a', 2);

    // patchStore 不会删除数据,只会补充或者修改
    this.patchStore({foo1: {c: 1}});

    // putStore 和 patchStore 会触发 myStore.onChange() 监听的事件

    // 设置 'foo1.a' 为 loading 状态
    this.startLoading('foo1.a');

    // 设置 'foo1.a' 为非 loading 状态
    this.stopLoading('foo1.a');

    // startLoading 和 stopLoading 会触发
    // 使用 myStore.onChange(), myStore.onLoading() 监听的事件

    // 追加 'foo1.a' 的 errors 信息
    this.setErrors('foo1.a', 'Error Message');
    this.setErrors('foo1.a', ['Error Message']);

    // 移除'foo1.a' 所有的错误信息
    this.removeErrors('foo1.a');

    // setErrors 和 removeErrors 会触发
    // 使用 myStore.onChange(), myStore.onError() 监听的事件

    // putStore 的第二个参数为 promise 对象时,会自动改变 loading 和 error 状态
    this.putStore('foo', Promise.resovle(2));
    this.putStore('foo', Promise.reject('error'));
  },
  updateSomeThing() {
    // some actions
  }
});

Query

query 是一种查询对象属性的字符串。允许使用 'a.b.c' 表示 {a: {b: {c: 1}}} 中的 c 属性。 query 也可以是使用&拼接的多个属性。

使用 Action

Action 即正常的函数,可以直接调用,不需要额外的设置。

使用 Store

Store 可以使用 onChange、onLoading、onError 监听特定的事件。

  • Store.onChange(Query query, callback) 监听query的值、loading 状态、错误信息改变。 callback 接受一个包含 value, loading, errors 属性的对象。

    // 监听 myStore foo 属性的值、loading 状态、错误信息改变。loading 为 布尔值,errors 为数组
    myStore.onChange('foo', ({value: foo, loading, errors}) => {})
    
    // 监听 myStore foo 和 foo.a 属性的值、loading 状态、错误信息改变
    myStore.onChange('foo&foo.a', ({value: foo, loading, errors}) => {})
  • Store.onLoading(Query query, callback) 只监听query的 loading 状态改变。callback接受和 onChange 一样的参数

  • Store.onError(Query query, callback) 只监听query的 errors 值改变。callback接受和 onChange 一样的参数

ChangeLog

2016-05-03 v0.1.6

  • 去掉 validator,请使用 vajs
  • 升级 lodash to 4+

2016-05-03 v0.1.5

  • 添加 LightDB 工具
  • 补充部分文档

License

MIT © yuanwen