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

mutasync

v0.0.1

Published

Online state management

Downloads

4

Readme

mutasync

Syncs your state manager offline & online

Mutasync provides an easy way to save state in localStorage, authenticate and save mutations online using a mutasync-server. It allows to build apps that are meant "front first" where we put all trust in user's browser. It is well suited for ideas where there is no real usage of a database. See mutasync-server github page for more information regarding how data is used.

:bomb: For now mutasync works with mutastore (a forked version of unistore) a pending PR to Unistore is open. If merged mutastore could then cease to exist preferably for Unistore

  • Saves in LocalStorage
  • Saves online
  • Works with JWT
  • Dead small & simple code

Install

This project uses node and npm. Go check them out if you don't have them locally installed.

npm install --save mutasync

Usage

Mutasync works best with mutastore, any compatible store should do, but for now you have to go trough the installation and usage of mutastore.

Once installed,

Mandatory step

import sync from 'mutasync';

const SYNC = sync({
  host: 'your-end-point'
})

// This handle submission of mutations to save
store.subscribe(SYNC.apply)

To handle localStorage

class App extends Component {
  componentDidMount = () => store.setState(
    sync('mytoken').retrieveLocal()
  )

  render = () => <div id="app">
    <Provider store={store}>
      <Page />
    </Provider>
  </div>
}

To handle authentication

const LoginBase = ({login}) => <form onSubmit={
  (e) => {
    e.preventDefault();
    login( e.target[0].value, e.target[1].value )
  }
}>
  <label>Username</label>
  <input type="text" id="email" />
  <label>Password</label>
  <input type="password" id="password" />
  <button type="submit">Login</button>
  <button onClick={(e) => {
    e.preventDefault();
    sync('mytoken').clearLocal(defaults)
    store.mutate({logout: defaults}, true)
  }}>Logout</button>
</form>

const Login = connect(
  (state, props) => ({...state}),
  (state, props) => ({
    login: (state, username, password) => SYNC
      .auth( username, password )
      .then( (res) => res.json() )
      .then( (res) => ({ authenticate: { ...res }, sync: false }))
      .catch(function(res) {
         console.log('error :', res);
      })
  })
)(LoginBase)

API

sync

Constructs a sync object which contains all the API methods.

Parameters

  • destination is an object in the form { 'host': 'host-endpoint', }
  • v is a function that should check wether the user is authenticated.

Examples

const SYNC = sync({
  host: 'your-server-endpoint'
})

retrieveLocal

Retrieve state from localStorage (Should be used when your master has loaded)

Examples

SYNC.retrieveLocal()

clearLocal

Clears state from localStorage (For your logout button)

Parameters

  • dflt is how the default state should like

Examples

SYNC.clearLocal({})

apply

Sends state update, saves it in localeStorage

Parameters

  • state is the new current state
  • action is the action that triggered the update

Examples

store.suscribe(SYNC.apply)

auth

Authenticate function, still need to .then and .catch it

Parameters

  • username
  • password