Coder Social home page Coder Social logo

react-arc's Introduction

react-arc version react-arc downloads

ARC

React Abstract Redux Containers

Set of components to manage collections/models from a REST service

Live demo : https://toolbox.sunny.fr/react-arc/

sample code

config

//EXAMPLE CONFIG
export const config = {
    // reducer name
    name: 'something',
    // will be used to decorate every action (singular prefered)
    uppercaseName: 'SOMETHING',
    // useful to map objects in collection
    modelProps: ['id'],
    // can be an empty list (might be usefull if you need paging...)
    collectionProps: ['size','page'],
    // path to your rest server
    paths: {
        item: '/some/url/{id}',
        collection: '/some/url?page={page}&size={size}'
    }
}

component

import React  from 'react'
import config from './somewhere/config.json'
import {AbstractModelContainer, withARC} from 'react-arc'

const PortfolioItem = ({item}) =>{
    return (<li>
        <h3>{item.title}</h3>
        <p>{item.description}</p>
    </li>)
}
class PortfolioComponent extends AbstractModelContainer {
    render(){
        if (!this.isLoaded()) return (<div>loading....</div>)
        const items = this.getCollection().map(item=><PortfolioItem key={item.id} item={item} />)
        return(<ul>
            {items}
        </ul>)
    }
}

export default withARC(config)(PortfolioComponent)

App.js

function App() {
    return (
        <Provider store={store}>
            <ARCProvider store={store}>
                {/* ... */} 
            </ARCProvider>
        </Provider>
    )    
}

store

import {mixerStore} from 'react-arc'
import configPortfolio from './somewhere/config.json'

const reducers = {
    portfolio: mixerStore({config:configPortfolio})
}

react-arc's People

Contributors

sunny-fr avatar

Stargazers

Alonso GIRALDO avatar  avatar

Watchers

James Cloos avatar Matiar avatar

react-arc's Issues

Fetch Collection with optionals params

react-arc/src/components/AbstractCollectionComponent.js

/* public
* Fetch a collection */
fetch = (newProps) => {
    const props = newProps || this.props
    this.props.dispatch(this.actions.fetchAll(extractParams(this.ARCConfig.collectionProps, props)))
 }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.