Giter Club home page Giter Club logo

trex.core's Introduction

<T>Rex Core Components

https://nodei.co/npm/trex.core.png?downloads=true&downloadRank=true&stars=true

Simple Dependency Injection

import ServiceLocator from 'trex.core/ServiceLocator';

const api = new ServiceLocator();

export enum Controllers {
    App = 'IAppController',
    Contacts = 'IContactsController',
    Search = 'ISearchController',
    AppFragments = 'IAppFragmentsController',
    CreditCalculator = 'ICreditCalculatorController',
    Weblogs = 'IWeblogController'
}

(function(api: ServiceLocator) {
    api.bind<IAppController>(Controllers.App).to(new AppController());
    api.bind<IContactsController>(Controllers.Contacts).to(new ContactsController());
    api.bind<ISearchController>(Controllers.Search).to(new SearchController());
    api.bind<IAppFragmentsController>(Controllers.AppFragments).to(new AppFragmentsController());
    api.bind<ICreditCalculatorController>(Controllers.CreditCalculator).to(new CreditCalculatorController());
    api.bind<IWeblogController>(Controllers.Weblogs).to(new WeblogController());
})(api);

export default api;

XComponent

React Component Wrapper to support a reactive stream of props.

export default abstract class XHttpComponent<P, S extends IFragmentState, T> extends XComponent<P, S> {
    private subscription: Subscription;

    constructor(props: P) {
        super(props);
    }

    componentDidMount() {
        this.subscription = this.props$
            .mergeMap(props => this.sourceData(props))
            .map(httpBag => this.renderFragment(httpBag))
            .subscribe(jsxFragment => {
                this.setState({fragment: jsxFragment});
            });
    }

XHttpComponent

interface IProps{
}

class WeblogListWidget extends ReXHttpComponent<IProps, IFragmentState, Array<Weblog>> {
    private readonly weblogController: IWeblogController = Api.get<IWeblogController>(Controllers.Weblogs);

    constructor(props: IProps) {
        super(props);

        this.state = {
            fragment: null
        };
    }

    sourceData(props: IProps) {
        return this.weblogController.list();
    }

    protected renderPending(): JSX.Element {
        return (<span>Loading...</span>);
    }

    protected renderSucceeded(weblogs: Array<Weblog>): JSX.Element {
        return (<article>
            <header>Weblogs:</header>
            <section>
                {
                    weblogs.map(weblog => (
                        <article key={weblog.blogId}>
                            <header>{weblog.title}</header>
                            <section>
                                <p>{weblog.body}</p>
                            </section>
                        </article>
                    ))
                }
            </section>
        </article>);
    }

    protected renderFailed(error: HttpError): JSX.Element {
        return <div>Failed!</div>
    }

    render(): JSX.Element {
        return (
            <article className="weblogs">
                {this.state.fragment}
            </article>
        );
    }
}

export default WeblogListWidget;

trex.core's People

Contributors

ddoronin avatar

Watchers

James Cloos avatar  avatar

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.