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

react-components-controller

v0.3.1

Published

Controller for React components

Downloads

9

Readme

EXAMPLE CODE###

----project.js-----
import React from 'react';
import ReactComponentsController from 'react-components-controller';
import PackageComponent from '/packages/somepackage/packege';
import ListingItem from './mods/ListingItem';
import Navbar from './mods/Navbar';

const Controller = new ReactComponentsController();
Controller.registerComponent('ListingItem', ListingItem);

export default () => (
    <div>
        <Navbar />
        <PackageComponent extendController={Controller} />
    </div>
);

----package.js----
import React from 'react';
import ReactComponentsController from 'react-components-controller';
import ListingWrapper from './components/ListingWrapper';
import ListingContainer from './components/ListingContainer';
import ListingItem from './components/ListingItem';
import ListingItemAvatar from './components/ListingItemAvatar';

const Controller = new ReactComponentsController();
Controller.registerComponent('ListingWrapper', ListingWrapper);
Controller.registerComponent('ListingContainer', ListingContainer);
Controller.registerComponent('ListingItem', ListingItem);
Controller.registerComponent('ListingItemAvatar', ListingItemAvatar);

export default ({extendController}) => {
    if(extendController){
        Controller.extendController(extendController);
    }
    return (
        <div>
            {Controller.getComponent('ListingWrapper',{ListingTitle:'Default lising'})}
        </div>
    );
}


----ListingWrapper.jsx---
import React from 'react';

export default ({Controller, ListingTitle}) => {
    if(extendController){
        Controller.extendController(extendController);
    }
    return (
        <div>
            {ListingTitle}
            {Controller.getComponent('ListingContainer',{ListingContainerTitle:'Default lising container title'})}
        </div>
    );
}

Methods##

| Method | Attributes | Description | |---|---|---| | registerComponent | componentName: [String] component: [ReactComponent]options: [Object] | Register component in Controller | | registerBeforeComponent | componentName: [String] component: [ReactComponent] | You can register component to display before some basic register component | | registerAfterComponent | componentName: [String] component: [ReactComponent] | You can register component to display after some basic register component | | registerComponentExtend | componentName: [String] extend: [Object] options: [Object] | You can register components extend it will be extended after call extendController method | | extendComponent | componentName: [String] extend: [Object] options: [Object] | You can extend methods of registred components for example render method | | extendController | controller: [ReactComponentsController] | You can overwrite and extend controller by another controller. All registred component with the same name will be overwrite | | getComponent | componentName: [String] props: [Object] options: [Object] | Render registred component by his registration name |

Methods description

registerComponent(componentName, component, options)

  • componentName - [String] name of virtual instance where Your component will be displayed
  • component - [Component] React Component to display
  • options - [Object] of additional information. You can use it in the component
const Controller = new ReactComponentsController();
Controller.registerComponent('ListingWrapper', testComponentWrapper);
Controller.registerComponent('ListingContainer', testComponentContainer);
Controller.registerComponent('ListingItem', testComponentItem);

registerBeforeComponent(componentName, component)

  • componentName - [String] name of virtual instance where main component will be displayed after this component
  • component - [Component] React Component to display
const Controller = new ReactComponentsController();
Controller.registerComponent('ListingWrapper', testComponentWrapper);
Controller.registerBeforeComponent('ListingWrapper', testComponentBefore);

registerAfterComponent(componentName, component)

  • componentName - [String] name of virtual instance where main component will be displayed before this component
  • component - [Component] React Component to display
const Controller = new ReactComponentsController();
Controller.registerComponent('ListingWrapper', testComponentWrapper);
Controller.registerAfterComponent('ListingWrapper', testComponentAfter);

registerComponentExtend(componentName, extend, options)

  • componentName - [String] name of virtual instance where main component will be displayed
  • extend - [Object] Object with function that will be extended and overwrite
  • options - [Object] of additional information. You can use it in the component
const Controller = new ReactComponentsController();
const Controller2 = new ReactComponentsController();

Controller.registerComponent('test1', testComponent);

Controller2.registerComponentExtend('test1', {
    testMethod(){
        return 'extended test method';
    },
    render(){
        return (<div>extended: {this.testMethod()}</div>);
    }
});
Controller2.registerComponent('test2', testComponent2);

Controller.extendController(Controller2);

extendComponent(componentName, extend, options)

  • componentName - [String] name of virtual instance where main component will be displayed
  • extend - [Object] Object with function that will be extended and overwrite
  • options - [Object] of additional information. You can use it in the component
const Controller = new ReactComponentsController();

Controller.registerComponent('test1', testComponent);

Controller.extendComponent('test1', {
    testMethod(){
        return 'extended test method';
    },
    render(){
        return (<div>extended: {this.testMethod()}</div>);
    }
});

extendController(controller)

  • controller - [DynamicController] more important controller that will overwrite old controller
const Controller = new ReactComponentsController();
const Controller2 = new ReactComponentsController();

Controller.registerComponent('test1', testComponent);

Controller2.registerComponent('test1', testComponent2);
Controller2.registerComponent('test2', testComponent2);

Controller.extendController(Controller2);

getComponent(componentName, props, options)

  • componentName - [String] name of virtual instance where Your component will be displayed
  • props - [Object] Props that React Component will have
  • options - [Object] additional information. You can use it in the component and overwrite defined options
const Controller = new ReactComponentsController();
Controller.registerComponent('test1', testComponent);


export default ({someParam}) => (
    <div>{Controller.getComponent('test1', someParam)}</div>
)