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

reflux-partial

v1.0.8

Published

Plugin for reflux-core to use part of state

Downloads

5

Readme

reflux-part

##What is it

Plugin for reflux-core to use part of state, extends at

1. Reflux.connectPart(store, propNames)

You can connect part of state from store to component. Because the componet only care about part of state, just like you only care about one of many girls in your class.

你可以将store中的部分state连接到组件中,因为组件很可能只关心部分state,就好像你只关注你们班里的某个女孩。

2. Store.triggerPart(partState)

You can update part of state, not full of state. This method will help you merge new part and old part in state, and update full of state automatically. For example, you have a state about user(include username, password, birthday, address), but you only change password, so just trigger password.

你可以更新部分state,而不是全部state。该方法可以帮你合并state中的新旧部分,从而自动更新全部state,保证旧部分的state不丢失。例如,你有一个关于用户的state(包含用户名、密码、生日、地址),但是你只修改了密码,因此只需要触发密码的更新。

3. Store.getState()

You can read the state by this.getState() in the store, just like this.state in the component.

你可以在store中用 this.getState() 来获得state,就好像你在组件中用 this.state 来获得state。

##How to use it

1. Install

npm install reflux-part@latest --save

2. Extend Reflux

To install partial state functionality do the following in your application's bootstrapper or in a file:

import Reflux from "reflux";
import RefluxPartial from "reflux-partial";

// Extend connect
Reflux.connectPart = RefluxPartial.connect;

// Extend store
Reflux.StoreMethods = Object.assign(Reflux.StoreMethods, RefluxPartial.StoreMethods);

export default Reflux;

3. Store

Define a store, and use triggerPart() to update part of state, use getState() to get full of state.

import Reflux from '../reflux'; // The Reflux extends by Step 2
import { notification } from 'antd';

var MenuActions = require('../actions/menu');
import api from '../api';

var MenuStore = Reflux.createStore({
  // this will set up listeners to all publishers in UserActions, using onKeyname (or keyname) as callbacks
  listenables: [MenuActions],
  getInitialState: function() {
    return {
      currentIndex: 0, // 当前点击的菜单key
      items: [], // 两级的菜单,以children来关联
      navpath: [] // 打开的菜单路径
    };
  },
  // 获得菜单
  onGetAllMenu: function(){
    api.post('/menu')
      .then((data) => {
        this.triggerPart({items: data.menus}); // update part of state
    }).catch((e) => {
      notification.error({
          message: 'Get all menu fail',
          description: e
      });
    });
  },
  // 更新菜单路径
  onUpdateNavPath: function(navpath, key){
    const {items} = this.getState(); // get state in store
    this.triggerPart({
        currentIndex: key,
        navpath
    });
  },
});

module.exports = MenuStore;

4. Component

Define a component, and connect store's state with this componet.

import React from 'react';
import ReactMixin from 'react-mixin';
import Reflux from '../../reflux'; // The Reflux extends by Step 2
import MenuActions from '../../actions/menu';
import MenuStore from '../../store/menu';

class Sidebar extends React.Component {

  componentDidMount () {
    MenuActions.getAllMenu();
  }

  render () {
    const { items, currentIndex } = this.state;
    return (
      <ol>
        {items.map((item, i) => {
          return <li>{item.name}</li>
        })}
      </ol>
    )
  }
}

// connect MenuStore's partial state('items' and 'currentIndex' property) with component Sidebar
// 将MenuStore中state的 'items' 与 'currentIndex' 属性,绑定到Sidebar组件中
ReactMixin.onClass(Sidebar, Reflux.connectPart(MenuStore,['items', 'currentIndex']));

export default Sidebar;