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

@cohook/solid-js

v1.1.0-alpha.0

Published

Solid-js lightweight, progressive data caching and cross-component communication

Downloads

21

Readme

@cohook/solid-js

Solid JS 轻量级、渐进式数据缓存和跨组件通信方案

✨特性

  • 基于solidJS内置的数据管理方案封装
  • 自动跟踪数据变化并更新,精准定位作用区间
  • 读写分离,自定义Action去处理数据,灵活化组装实现逻辑复用
  • 轻量,API简单化,类型提示友好
  • 数据不可变
  • 支持插件化拓展功能

📦 安装

yarn add @cohook/solid-js
npm i @cohook/solid-js

⚡快速开始

1. 定义一个Container

import createContainer from "@cohook/solid-js"

const container = createContainer(0)

2. 定义Action

const inc = () => container.commit((draft) => void (draft.current += 1)
const dec = () => container.commit((draft) => void (draft.current -= 1)

3. 数据状态化和修改

function Counter() {
  const countAccessor = counterContainer.useMapDataToAccessor()
  return (
    <div>
      count:{countAccessor()}
      <button onClick={() => inc()}>+</button>
      <button onClick={() => dec()}>-</button>
    </div>
  )
}

💡API

createContainer(initialData)

createContainer作为容器工厂函数,接收初始数据initialData,返回一个容器对象container

container

container.useMapDataToAccessor()

用于将数据状态化,被状态化后的数据会自动跟踪变化并更新。

container.commit(updater)

commit 接受一个函数updater(和SolidJS的produce的参数基本保持一致)作为参数,,用来创建修改数据的Action,可灵活组合容器对象提供的方法来组装Action。

const dec = () => container.commit((draft) => void (draft.current -= 1)

createContainerWithPlugins(initialData, pluginsOption)

createContainer作为容器工厂函数,接收初始数据initialData和插件配置pluginsOption 👉,返回一个带有插件的容器对象containerWithPlugins

containerWithPlugins

containerWithPlugins.getData()

用于获取当前的容器数据,就像是一个内置的action,可在任何地方使用。

containerWithPlugins.useMapDataToAccessor()

用于将数据状态化,被状态化后的数据会自动跟踪变化并更新。

containerWithPlugins.commit(updater)

commit 接受一个函数updater(和SolidJS的produce的参数基本保持一致)作为参数,,用来创建修改数据的Action,可灵活组合容器对象提供的方法来组装Action。

const dec = () => {
  const count = containerWithPlugins.getData()
  if(count < 0) return
  containerWithPlugins.commit((draft) => void (draft.current -= 1)
}