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

component-containers

v0.1.23

Published

Declartive approach to composing components

Downloads

47

Readme

Component Containers

An ng2+ library for declaritively injecting components into your views.

Declare a map that relates your classes to their appropriate components

For example, say you have a component that displays a list of users and you want to load a specific component for either displaying or editing user information based on the type of user.

Rather than having a single component that hides/shows fields based on user model properties you can inject the right component for the right type of user based on a map.

Installation

npm i -S component-containers

Using Component Containers

Import ComponentContainerModule and register injectable components

import { NgModule } from '@angular/core';
import { MyApp } from './app.component';

// Import Component Containers
import { ComponentContainerModule } from 'component-containers';

// Import any static components that you'll want to inject 
// and add them to this module's entryComponents[] 
// (dynamic components register themselves)

import { AdminUserComponent } from './components/admin-user.component';
import { MemberUserComponent } from './components/member-user.component';
import { NewUserComponent } from './components/new-user.component';

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [ 
    ComponentContainerModule // Expose Component Containers to your app
  ],
  bootstrap: [AppModule],
  entryComponents: [
    AdminUserComponent,
    MemberUserComponent,
    NewUserComponent
  ],
  providers: []
})
export class AppModule {}

Create a map to link your models to components

import { Component } from '@angular/core';

import { AdminUserComponent } from './admin-user.component';
import { MemberUserComponent } from './member-user.component';
import { NewUserComponent } from './new-user.component';

import { ComponentMap, ContainerItemDirective } from 'component-containers';

@Component({
  selector: 'app-user-editor',
  template: '<ng-container container-item [map]="map" [context]="current"></ng-container>',
  styleUrls: ['./app-user.component.css']
})
export class AppUserComponent {

  public current: any;
  public map: ComponentMap;

  constructor() {
    this.map =
      new ComponentMap([{
        model: AdminUser,
        component: AdminUserComponent //A promise can also be used here to resolve dynamic/lazy-loaded components
      }, {
        model: MemberUser,
        component: MemberUserComponent
      }, {
        model: NewUser,
        component: NewUserComponent
      }])
  }

  editUser(user) {
    //This will automatically resolve the proper editor component based on the user's type
    this.current = user;
  }

}
class AdminUser extends MemberUser{
  roles:Array<string>;
}
class MemberUser extends Base {
  name:string
  email:string
  profilePic:string
}
class NewUser {
  name:string
  signupType:string
}

Context

The component that is injected recieves a property [context] which is the model that triggered the mapping (this.current in the preivous example)

Developing

Develop this module like any other Angular 2 module. Then, run npm run build to build a local copy.

npm link

Currently, this module must be published to npm. npm link packages will not install properly.