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

json-git-redux

v0.2.0

Published

Official json-git bindings for Redux

Downloads

4

Readme

json-git-redux Build Status

Official json-git bindings for Redux.

Installation

It is avaible through npm:

npm install json-git-redux

Usage

Setup

First, you must registered the reducer with your repositories and the middleware:

import {
    applyMiddleware,
    combineReducers,
    createStore,
} from 'redux'
import createRepository from 'json-git'
import {
    createMiddleware as createJsonGitMiddleware,
    createReducer as createJsonGitReducer,
} from 'json-git-redux';

import reducers from '<project-path>/reducers'

// Instanciate all your repositories here
// You can use any name you like as key
const repositories = {
    myRepository: createRepository(),
};

// Add the reducer to your store on the `jsonGit` key
// Then add the middleware
const store = createStore(
    combineReducers({
        ...reducers,
        jsonGit: createJsonGitReducer(repositories),
    }),
    applyMiddleware(createJsonGitMiddleware()),
);

The middleware is responsible for dispatching succeeded/failed actions about write actions.

Write operations with action creators

json-git-redux provides 4 action creators to perform write operations on your repositories:

  • checkout(repositoryName, branch [, create=false]) creates and/or changes the current branch on a repository
  • commit(repositoryName, author, message, tree) creates a new commit on the current branch of a repository
  • merge(repositoryName, author, branch [, resolver]) merges a branch into the current branch on a repository
  • revert(repositoryName, author, commitHash, [, resolver]) reverts the changes introduced by a commit on a repository

To use them, just import them from json-git-redux:

import React, {
    Component,
    PropTypes,
} from 'react';
import { connect } from 'react-redux';
import {
    checkout,
    commit,
    merge,
    revert,
} from 'json-git-redux';

class Foo extends Component {
    constructor(props, context) {
        super(props, context);

        this.onClick = this.onClick.bind(this);
    }

    onClick() {
        const { commit } = this.props;

        commit('myRepository', 'robin', 'first commit', {
            foo: 'bar',
        });
    }

    render() {
        return (
            <button onClick={this.onClick}>Commit</button>
        );
    }
}

Foo.propTypes = {
    checkout: PropTypes.func.isRequired,
    commit: PropTypes.func.isRequired,
    merge: PropTypes.func.isRequired,
    revert: PropTypes.func.isRequired,
};

export default connect(state => (
    head: state.jsonGit.heads.myRepository,
), {
    checkout,
    commit,
    merge,
    revert,
})(Foo);

Note that you must subscribe your component to the head of your repository if you want it to be refreshed at each change (head: state.jsonGit.heads.myRepository).

Read operations with selectors

json-git-redux provides 4 selectors to perform read operations on your repositories:

  • apply(repositoryName, patch [, resolver]) applies a patch to the current tree of a repository and returns the result
  • getDiff(repositoryName, left, right) generates a JSON Patch between two branches or commits in a repository
  • getJSON(repositoryName) exports a snapshot of a repository
  • getLog(repositoryName) returns the full history of a repository
  • getTree(repositoryName) returns the current tree of a repository
  • subscribe(repositoryName, subscriber) subscribe a subscriber to a repository
  • unsubscribe(repositoryName, subscriber) unsubscribe a subscriber from a repository

To use them, just import them from json-git-redux:

import React, {
    Component,
    PropTypes,
} from 'react';
import { connect } from 'react-redux';
import {
    apply,
    getDiff,
    getJSON,
    getLog,
    getTree,
} from 'json-git-redux';

class Foo extends Component {
    render() {
        const tree = getTree('myRepository');

        return (
            <pre>{tree}</pre>
        );
    }
}

Foo.propTypes = {};

export default Foo;

Action types

| Type | Description | | --- | --- | | CHECKOUT_FAILED | When a checkout failed | | CHECKOUT_SUCCEEDED | When a checkout succeed | | CHECKOUT | When a checkout is performed | | COMMIT_FAILED | When a commit failed | | COMMIT_SUCCEEDED | When a commit succeed | | COMMIT | When a commit is performed | | MERGE_FAILED | When a merge failed | | MERGE_SUCCEEDED | When a merge succeed | | MERGE | When a merge is performed | | REVERT_FAILED | When a revert failed | | REVERT_SUCCEEDED | When a revert succeed | | REVERT | When a revert is performed |

Development

Install dependencies with yarn. You're then good to go.

To run the tests, just do npm test.

Contribute

All contributions are welcome and must pass the tests. If you add a new feature, please write tests for it.

License

This application is available under the MIT License.