0.0.4 • Published 4 years ago

react-git-provider v0.0.4

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
4 years ago

react-git-provider

A Git provider for React

Note: this is a Work in progress !

Note

This is currently a proof of concept. I do not recommend using it in a production build.

Contributions are still welcome to ship it into the wild ! 🚀

Install

yarn add react-git-provider

Usage

Basic usage

You can import this project, and then use it as a classic provider, which is described https://react-git-provider.publica.re/interfaces/types.gitcontext.html.

We work with Promises, so don't forget your awaits !

Use as a component

If you want your component to update automatically with changes (e.g. on commit, etc), we provide a <Component />, which you can extend and use anywhere inside a <Provider />, which will be automagically triggered when changes occur.

To listen for changes, you have to set the state.gitWatch of your component with values corresponding with the value you want to watch first, and with the options matching first. For instance, if you want to watch for the current branch and the values of test.tsx, you have to write:

this.state = {
  ...this.state,
  gitWatch: {
    branch: {
      current: {},
    },
    file: {
      read: { path: "test.tsx", mode: "text" },
    },
  },
};

Then, in your render (or really anywhere), you'll be able to call

this.state.gitValues.branch.current;

to see the desired value.

Important: if you want to overwrite the componentDidMount, componentDidUpdate or componentWillUnmount, you have to super them first!

Go futher

You can take a look at the source of react-git-taskbar for an example or the documentation !

License

Copyright 2020, David Baumgartner.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Contributing

I welcome happily contributions to pull request through GitHub.