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

@siyu/sdm2

v1.0.10

Published

GitHub:https://github.com/JstLkSiyu/sdm2

Downloads

6

Readme

GitHub:https://github.com/JstLkSiyu/sdm2

Npm:https://www.npmjs.com/package/@siyu/sdm2

一个提供React数据双向绑定(伪)功能以及globalStore功能的库,通过joinSdm向组件props注入$sdm变量,在组件内部直接修改$sdm属性的值,可以触发渲染更新,createGlobalSdm可以定义全局绑定数据,在$sdm值被改变时可以更新所有组件。

样例:

import React, { Component } from 'react';
import { joinSdm, createGlobalSdm, SDP } from '@siyu/sdm2';

const sdm = {
  hello: 'world'
}

const globalSdm = createGlobalSdm({
  font: {
    size: 12,
    color: 'green'
  },
  hello: 'world'
});

const FunctionComponentWithSdm = joinSdm<typeof sdm, {}>(function(props) {
  return (
    <div>
      <h1>Function Component With Local Sdm</h1>
      <p>{props.$sdm.hello}</p>
      <input value={props.$sdm.hello} onChange={($e) => props.$sdm.hello = $e.target.value} />
    </div>
  )
}, sdm);

const ClassComponentWithSdm = joinSdm(class extends Component<SDP<typeof sdm, {}>> {
  render() {
    return (
      <div>
        <h1>Class Component With Local Sdm</h1>
        <p>{this.props.$sdm.hello}</p>
        <input value={this.props.$sdm.hello} onChange={($e) => this.props.$sdm.hello = $e.target.value} />
      </div>
    )
  }
}, sdm);

const FunctionComponentWithGlobalSdm = joinSdm<typeof globalSdm, {}>(function(props) {
  let { color, size } = props.$sdm.font;
  return (
    <div>
      <h1>Function Component With Global Sdm</h1>
      <p style={{ color: color, fontSize: size + 'px' }}>{props.$sdm.hello}</p>
      <input value={props.$sdm.hello} onChange={($e) => {
        props.$sdm.hello = $e.target.value;
        props.$sdm.font = {
          size: 16,
          color: 'red'
        }
      }} />
    </div>
  )
}, globalSdm);

const ClassComponentWithGlobalSdm = joinSdm(class extends Component<SDP<typeof globalSdm, {}>> {
  render() {
    let { color, size } = this.props.$sdm.font;
    return (
      <div>
        <h1>Function Component With Global Sdm</h1>
        <p style={{ color: color, fontSize: size + 'px' }}>{this.props.$sdm.hello}</p>
        <input value={this.props.$sdm.hello} onChange={($e) => {
          this.props.$sdm.hello = $e.target.value;
          this.props.$sdm.font = {
            size: 16,
            color: 'red'
          }
        }} />
      </div>
    )
  }
}, globalSdm);

function App() {
  return (
    <div>
      <FunctionComponentWithSdm />
      <ClassComponentWithSdm />
      <FunctionComponentWithGlobalSdm />
      <ClassComponentWithGlobalSdm />
    </div>
  )
}

export default App

样例2:提供了composed global sdm功能,可以组合多个global sdm

import { createGlobalSdm, joinSdm, composeGlobalSdm } from './sdm2';
import React, { FC, useState } from 'react';

const sdm1 = createGlobalSdm({
  sdm1: 0
});

const sdm2 = createGlobalSdm({
  sdm2: 0
});

const sdm3 = createGlobalSdm({
  sdm3: 0
});

const composedSdm1 = composeGlobalSdm(sdm1, sdm2);
const composedSdm2 = composeGlobalSdm(sdm3, sdm2);

const Csdm1 = joinSdm<typeof composedSdm1, {  }>(function(props) {
  return (
    <div>
      <p>{props.$sdm.sdm1}</p>
      <p>{props.$sdm.sdm2}</p>
      <button onClick={() => props.$sdm.sdm2 ++}>change sdm2</button>
    </div>
  )
}, composedSdm1);

const Gsdm = joinSdm<typeof sdm2, {}>(function(props) {
  const [ _, renew ] = useState(false);
  console.log('renew')
  return (
    <div>
      <p>{props.$sdm.sdm2}</p>
      <button onClick={() => props.$sdm.sdm2 ++}>change sdm2</button>
      <button onClick={() => renew(_ => !_)}>renew</button>
    </div>
  )
}, sdm2);

const Csdm2 = joinSdm<typeof composedSdm2, {}>(function(props) {
  return (
    <div>
      <p>{props.$sdm.sdm2}</p>
      <button onClick={() => props.$sdm.sdm2 ++}>dd</button>
    </div>
  )
}, composedSdm2);

export const Main: FC<any> = function(props) {
  return (
    <div>
      <h1>sdm1 and sdm2</h1>
      <Csdm1 />
      <h1>sdm2 and sdm3</h1>
      <Csdm2 />
      <h1>only sdm2</h1>
      <Gsdm />
    </div>
  )
}

1.0.7新增:支持composeGlobalSdm接受多个global sdm参数