0.6.2 • Published 6 years ago

react-conduct v0.6.2

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

react-conduct

React data provider

NPM version Build Status Dependency Status Coverage percentage experimental

Install

npm install react @types/react --save    
npm install react-conduct --save

or

yarn add react @types/react react-conduct

Usage

import React = require("react");
import ReactDOM = require("react-dom");
import {provide} from "react-conduct";

// Component for providing data
class TestComponent extends React.Component<{ 
        data1: string; // providing prop
    }, {}> {
    public render() {
        return ["Data1: ", this.props.data1];
    }
}    
const ProvidedComponent = provide(TestComponent) // component for providing
    ((props: {arg1: string})=> { // providers for every props
        return {
            resolve: async ({setProps}) => {
                setProps({data1: await Promise.resolve(props.arg1 + ", World!")});
            },
            error: (err)=> ["Error": err],
            loading: ()=> "Loading",
        };
    },
);
const el = <ProvidedComponent arg1="Hello" />;

ReactDOM.render(el, document.getElementById("root"));    

Examples

git clone https://github.com/arvitaly/react-conduct

cd react-conduct

npm install

node examples/counter

[Counter example](https://github.com/arvitaly/react-conduct/blob/master/examples/counter.ts)     

API

interface IDataProps<T> {
    status: "success" | "error" | "loading";
    data?: T;
    error?: any;
}
// Provider constructor
interface IProviderStatic<A, D> {
    new(args: A, onSuccess: (data: D) => void, onError: (err: any) => void): IProvider;
}    
// Provider
interface IProvider {
    dispose(): void;
}

Test

npm install
npm test
0.6.2

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago