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

umineko-nerv

v0.0.1

Published

CSP for React component

Downloads

2

Readme

js-csp(一种 CSP 模型的 JS 实现库)为基础,实现 React Component 间新的通信模式。

此通信库主要有两部分组成:

  • 大脑 Brain:主要承担接受外部信息和处理内部数据的任务。
  • 神经节点 NervNode:整个神经树上的一个节点,能够向神经树发送数据,也能从神经树中读取数据。

将神经节点(NervNode)注入到想其他组件进行数据通信的 Component 上,神经节点就会依赖 Component 树建立起一颗 NervTree。

API

下面使用 flow 的方式来声明 API。

insertNerv

inertNerv 用法与 Redux 的 connect 类似。

// 监听 NervNode 中 message 的函数,Message 类型见下
declare function listenMessageFunc(
  msg: Message, 
  props: Object
): Object 

// 内部 Dispatch 函数 
declare function NervDispatchFunc(msg: Message): void

declare function dispatchFunc(dispatch: NervDispatchFunc): { [any]: function }

declare function insertNerv(
  listenMessage: listenMessageFunc, 
  dispatchObject: { 
    up: dispatchFunc, 
    down: dispatchFunc 
  }
): void

样例

import React from 'react'
import { insertNerv, message } from 'umineko-nerv'

class TestComponent extends React.PureComponent {
  constructor(props) {
    super(props)
    this.times = 0
  }

  render() {
    return(
      <div onClick={() => {this.props.triggerTimes(this.times++)}} >
        { this.props.test }
      </div>
    )
  }
}

const listenMessage = (action) => {
  if (action.isMatch('hi.hello')) {
    return { test: action.preload.info }
  }
}

const mapUpDispatchToProps = (dispatch) => {
  return {
    triggerTimes: (times) => { message.data('test.times', { times: times }) }
  }
}

export const TestComponentNerv = insertNerv(listenMessage, { up: mapUpDispatchToProps })(TestComponentNerv)

Brain

Brain 与其 Provider 类似。

declare function loop(msg: Message): Message
declare function receptor(dispatch: NervDispatchFunc): void 

样例

<Brain loop={brainLoop} receptor={receptor}>
  <YourAppRoot />
</Brain>

Message

Message 是 NervTree 中基本数据单元类,也即是说在 NervTree 中传递的数据要使用 Message 来封装。

interface Message {
  type: string,
  prior: number,
  topic: string,
  data: Object,
  isMatch(pattern: string): boolean
  isEmpty(): boolean
  toString(): string
}

同时提供5个基础类型的 message 工厂函数以供使用

empty(): Message
data(topic: string, data: Object): Message
animation(topic: string, data: Object): Message
route(topic: string, params: Object): Message
sign(topic: string, data: Object): Message