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 🙏

© 2026 – Pkg Stats / Ryan Hefner

syncmachine-sdk

v0.1.3

Published

Sync Machine is a service that handles data synchronization for your React application.

Readme

What is Sync Machine?

Sync Machine is a service that handles data synchronization for your React application.

It's based on a similar programming model to Redux, where changes to your application's state is described through events that change the state.

Concepts

Sync Machine has three concepts:

Application

Creating an application gives you an API key that you can use to connect your React app to Sync Machine.

Entity

An entity is any object in your application that you want to synchronize.

Are you creating a To-do list app? Then you'll probably have List entities with a bunch of items.

Update

Any time an entity changes, your application posts an update to Sync Machine.

An update can be any JSON value.

Getting started

There's three steps to add Sync Machine to your React application.

Step 1: Add syncmachine-sdk to your package.json

Step 2: Create an Application to get an API key

Go to https://syncmachine.herokuapp.com and create an account, then create an Application to generate an API key.

Save this API key for the next step.

Step 3: Wrap your app in a SyncMachineSocketProvider

Somewhere at the top level of your React application, add this:

import {SyncMachineSocketProvider} from 'syncmachine-sdk';

// ...

    return <SyncMachineSocketProvider apiKey={'API KEY GOES HERE'}>
        Your app goes here
    </SyncMachineSocketProvider>;

This will make the SDK connect to Sync Machine and create a connection to your Application.

It provides this connection, in the React context, to the entity hooks we'll make in the next step.

Step 4: Add a Sync Machine entity hook

In the component that renders your entity, use the useSyncMachineEntity hook to connect to a Sync Machine entity.

I'm going to assume here that we're going to make a To-do list application, with a List entity. Go ahead and substitute whatever entity type works for your app.

First, create an entity definition that looks like this:

const listEntity = {
    kind: 'List',
    initialState: () => (
      { name: "Unnamed list", items: [] }
    ),
    applyUpdate: (entity, update) => {
      console.log("Applying update: ", update);
      // TODO: apply the update and return a new list 
      return entity;
    }
};

There's three parts to an entity definition:

  • kind: This names the kind of entity.
  • initialState: This gives the structure of the entity before any updates have been applied to it.
  • applyUpdate: This function should apply the update to the entity and return the new state of the entity.
    • If you're familiar with Redux, this is like a 'reducer'.

Next, use the hook to get the state of the entity. For now we'll just render the state as JSON:


const List = ({id}) => {
    const [list, entity] = useSyncMachineEntity({
        ...listEntity, id,
    });
    
    return <div>{JSON.stringify(list)}</div>;
}

Step 4: Write the applyUpdate function

Finally, actually write the applyUpdate function.

TODO

Step 5: Post updates

Whenever the user makes a change to the entity, post an update to the entity.

For example, if they add an item to the List you might do this:

    entity.postUpdate({
      type: 'insert-item',
      data: {
        id: uuid(),
        title: 'New item title',
        completed: false
      }
    });

This update will get added to the entity's update stream and broadcast to all clients. They'll apply it with their applyState function and render the new state.