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

diddi-react

v0.3.1

Published

diddi react bindings

Downloads

2

Readme

diddi-react

diddi react bindings

🎉 Features

  • Easy to install
  • Do everything with a Provider and few React hooks

⚙ Install

# npm
npm i diddi-react

# yarn
yarn add diddi-react

🔍 Usage

Creating the bindings

// ./state-bindings.ts
import createbinding from 'diddi-react';
import state from './state';

export default createbinding(state);
// ./App.tsx
import React from 'react';
import Counter from './components/Counter.tsx';
import { Provider } from './state-bindings';

export default function App() {
  return (
    <Provider>
      <Counter />
    </Provider>
  )
}
// ./components/Counter.tsx
import React from 'react';
import { useActions, useState } from '../state-bindings';

export default function Counter() {
  const actions = useActions();
  const state = useState();

  return (
    <div>
      Counter's value: {state.counter.value}
      <button onClick={actions.counter.increment}>
        Tap to increment
      </button>
    </div>
  );
}

useActions, useState, useSelector

You can use three hooks when you create React bindings with the createbinding function.

useActions

This hook returns subscribed actions for each domain. Calling one action will cause your UI to update.

import React from 'react';
import { useActions, useState } from '../state-bindings';

export default function Counter() {
  const actions = useActions();
  const state = useState();

  return (
    <div>
      Counter's value: {state.counter.value}
      <button onClick={actions.counter.increment}>
        Tap to increment
      </button>
      <input
        onChange={event => actions.counter.set(Number(event.target.value))}
        type="number"
        value={state.counter.value}
      />
    </div>
  );
}

useState

This hook returns current state. (Give a look to the example above).

useSelector

This hook is similar to redux's one.

import React from 'react';
import { useActions, useSelector } from '../state-bindings';

export default function Counter() {
  const actions = useActions();
  const value = useSelector(state => state.counter.value);

  return (
    <div>
      Counter's value: {value}
      <button onClick={actions.counter.increment}>
        Tap to increment
      </button>
      <input
        onChange={event => actions.counter.set(Number(event.target.value))}
        type="number"
        value={value}
      />
    </div>
  );
}

debugging

To debug states using diddi, you will need this chrome extension (or firefox extension) and it's own middleware.

If you are using multiple middlewares, ensure you put this extension as the latest.

npm i diddi-debug-middleware
import mydomain from './mydomain';
import diddidebugger from 'diddi-debug-middleware';

export default create({ mydomain }, diddidebugger());

Predefined scripts:

  • changelog: creates a changelog (using standard-changelog)
  • docs: creates docs from your jsdocs
  • lint: lints your code
  • prepublishOnly: builds your sources for deployment (to npm)
  • size-limit: checks your bundle size limit
  • test: run tests
  • upgrade-interactive: updgrades your dependencies interactively (like with yarn)

️❤️ Contributing

Every contribution is really welcome!

If you feel that something can be improved or should be fixed, feel free to open an issue with the feature or the bug found.

If you want to fork and open a pull request (adding features or fixes), feel free to do it. Remember only to use the master branch as a base.

If you plan adding a new feature, please prefix the branch with the feat/branchname.

If you plan fixing something, please prefix the branch with the fix/branchname.

If you plan refactoring something, please prefix the branch with the refactor/branchname.

If you adding something which does not involve the runtime behavious, please prefix the branch with the chore/branchname.

Read the contributing guidelines

📃 Licence

Read the licence