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

redux-dat

v0.0.1

Published

## How this works This works by every peer having their own Dat Archive that they place actions into, every peer listening to each other's Dat Archives' changes, and when an action has been added to a Dat Archive, each peer combines the action streams in

Downloads

4

Readme

<redux-dat>

How this works

This works by every peer having their own Dat Archive that they place actions into, every peer listening to each other's Dat Archives' changes, and when an action has been added to a Dat Archive, each peer combines the action streams in the Dat Archives into one and uses a standard Redux store to calculate the state.

Installation and usage

npm install --save 'redux-dat'

The API is very similar to the standard Redux API. The difference is that instead of passing in an initialState, you pass in URLs of Dat Archives because state will be derived from the actions contained in those archives. Another difference is that dispatching an action is asynchronous by the time your subscribe callback is called. A subtle but sometimes important difference. Same goes for when your peers dispatch an action.

const store = createStore(reducer, ownArchiveUrl, [firstPeerArchiveUrl, secondPeerArchiveUrl])
store.subscribe(someRenderFunction)
store.dispatch({type: 'INCREMENT'})

Tips:

  • See tests for usage.
  • Note that every peer needs to have all the Peer Archive URLs and their own Archive URL before instantiating the store. You'll need to figure out how to facilitate the key exchanges in your own app.

Test

npm install
npm start

Open http://localhost:8081/test/redux-dat_test.html (not 127.0.0.1 because DatArchive API is not available on IP Addresses) in Beaker Browser. Note that you must authorize manually each archive the test suite creates.

Thoughts on strategies for replicating actions between Redux store peers

There are a couple of strategies I've been thinking about. Depending on the application you probably want a different one so this library might give you the option to choose a strategy in the future. For now, it uses "Chronological consensus of action order".

  • First come first serve action order.
    • Can lead to peers having different state because actions are in different order if for example the network is slow.
  • Chronological consensus of action order.
    • Everyone is able to calculate consensus but you may find yourself on a fork of history committing actions in a parallel universe only to find when consensus catches up, the opponent you thought you were jumping over never existed. Or worse, you made your opponent jump.
    • The parallel universe issue can be perhaps mitigated by smart UI that after a TURN action, the UI prevents further TURN actions locally until a new TURN action has been replicated from a peer... If the UI forces every peer to take turns in a consistent order, that will prevent parallel universes from emerging.
  • Consensus maker is the peer with the first ID in a sort of IDs.
    • Everyone must agree on IDs of peers from the beginning.
    • Not great if the consensus maker leaves.
  • Consensus maker is the first to solve random math problem.
    • Blockchain like...
  • Consensus maker is the one with the slowest network.
    • I hear this is the classic way to do P2P games over networks.