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

solid-socket

v0.0.2

Published

Signal based websocket runtime for Solid Start

Downloads

113

Readme

Solid Socket

Signals meets WebSockets.

This repo implements the classic TodoMVC app using Solid Socket. Most of the state and logic lives on the server, and the client communicates with it over websockets.

Getting Started

git clone https://github.com/devagrawal09/solid-socket
cd solid-socket
npm install
npm run dev

APIs

"use socket"

Use this directive on top of a file to define socket functions. A socket function is a function exported from a file marked as "use socket". This file will be split into a separate bundle that runs on the server. You can create global state in a "use socket" file through signals or any other stateful primitive.

Socket functions work like hooks, and should be called inside Solid.js components. Calling a socket function can instantiate a stateful closure on the server, which is automatically cleaned up with the calling component.

// src/lib/socket.tsx
"use socket"

export function useLogger() {
  let i = 0

  function logger() {
    console.log(`Hello World!`, i++)
  }
  
  return logger
}

// src/routes/index.tsx
export default function IndexPage() {
  const serverLogger = useLogger()

  return <button onClick={() => serverLogger()}>Log</button>
}

Clicking the button will log the message on the server and increment the count for the next log.

`"createSocketMemo"

A socket memo is a signal that can be accessed on the other side of the network. It's a serializable/transportable reactive value. Socket memos can be used to share a reactive value from the client to the server, and the server to the client.

// src/lib/socket.tsx
"use socket"

export function useCounter() {
  const [count, setCount] = createSignal()
  return {
    count: createSocketMemo(count),
    setCount
  }
}

// src/routes/index.tsx
export default function Counter() {
  const serverCounter = useCounter()

  return <button
    onClick={() => serverCounter.setCount(serverCounter.count() + 1)}
  >
    Count: {serverCounter.count()}
  </button>
}

The todos example in this repo shows how to use createSocketMemo to also share a signal from the client to the server.

Status

This project is highly experimental and you might run into issues building with this. Please report any issues you might find and leave feedback for things you'd like to see!.

Known Limitations

  • If socket functions are not called within components or reactive roots, they will never be cleaned up from the server. Only call socket functions from roots.
  • Socket functions can return functions, memos, or objects whose shallow properties are functions or memos. Deeply nested properties that are functions or memos won't be serialized and might throw an error instead.
  • The input to a socket function can either be a serializable object or a memo. It cannot be a function or an object with properties that are functions or memos.
  • Third party packages that use Solid's signals might not work yet on the server.

Roadmap

  • More demos
  • createSocketProjection
  • Integration with solid-events
  • Address above limitations
  • Package as an npm module