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

deef-plugin-build-common-component

v1.0.1

Published

用于封装大型公共业务组件

Readme

deef插件:build-common-component

用于封装大型公共业务组件

本插件在model中加入prefix字段,数据的读写都自动代理到相应prefix中,使用起来更简单,一个model即可解决deef(redux)中 公共业务组件中model会产生相互干扰的情况

特点

  • 除了model中加入prefix字段和组件实例化时额外插入一个prefix参数, 其他的写法完全与deef组件一致
  • 只有两个api($connect, $model),用法与之前的app.connect和app.model完全一致
  • 组件更易于维护
  • 数据之间不会产生干扰

原理

  • 在原来model的基础上加一个字段prefix,注入model时,同一份数据根据prefix被分发为多份
  • 引用组件时,传入prefix,格式为{namespace: prefix} 这个参数决定了
  1. getUIState,找到相应的namespace时,会映射到哪个prefix上的数据
  2. getState 会在找到相应的model后,找到哪个prefix上的数据
  3. dispatch 时会将action额外附加上这个参数,prefix
  4. reducer收到dispatch的action后,会根据action的prefix,决定最终更新哪个prefix下的state

如何用

app.js 引入deef-plugin-build-common-component

  1. 项目引用
import deef from 'deef';
import buildCommonComponent from 'deef-plugin-build-common-component';

const app = deef();

export const connect = app.connect;
export const {$model, $connect} = buildCommonComponent(app);

index.js 入口处注入公共组件的model

import app, {$model} from 'feedAds/app';
import modelList from './models';
import commonModelList from './commonModels';

const initApp = () => {
    modelList.map(model => app.model(model));
    commonModelList.map(model => $model(model)) // 在这里注入公共组件的model
} 
  1. 组件写法 eg: model todo.js 相对之前多加一个prefix字段,需为数组格式
export default {
    namespace: 'todo',
    prefix: ['todo1'], // 多加一个prefix字段
    state: {},
    reducers: {}
}

index.js 不同之处仅仅在于加了一个$

import {$connect} from 'app';
export default $connect(getUIState, callbacks)(UI); 

UI.js 引用时仅仅需要多传入一个参数prefix

import Component from './path/../';

export default () => {
    return <div>
    // otherElement
    <Component {{prefix: {todo: 'todo1'}}}/>
</div>
}