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

rng-dynamics

v12.0.2

Published

Angular Dynamic modules and components @runtime!

Downloads

1

Readme

Coverage Status

RNgDynamics

RNgDynamics is library for consuming Modules dynamically within your Angular Applications.

The library allows loading @NgModule's at runtime using the Angular JIT compiler with straightforward api configuring the lazy loaded modules and components.

Angular only supports by default lazy loading from the Router, with RNgDynamics components can be loaded lazily by your application code.

Lazy loaded components can be projected by the built-in directive rngLazyLoaded that act's as proxy for dynamic module components.

A lazy loaded module once loaded is cached in memory, so the application will not load it twice.

Features

  • Lazy load modules and components without Angular Router
  • Project lazy loaded components using a simple directive rngLazyLoaded
  • Modules and components are cached in memory (optionally Module Factories can be non-cached)
  • Load lazy components by type or by a named key string you define
  • Create endlessly lazy-loading capabilities in your Angular applications and libraries by wiring your own lazy loading logic

Usage

First of all create a Module to be lazy loaded without importing it into the others modules or RootModule.

Then define the RNgDynamicModuleDef for your module to be registered within RNgDynamics as follows:

const RNG_DYNAMICS : RNgDynamicModules<LazyModule> = [
  {
    components: {lazyComponent: LazyComponent}, // all the components associated with the Module
    import: () => import("./lazy/lazy.module").then(m => m.LazyModule) // use import and resolve the module type
  }
]

Then register the RNgDynamicModules<T> array to the RNgDynamicModule using the forRoot method.

@NgModule({
  declarations: [AppComponent],
  imports: [
    CommonModule,
    BrowserModule,
    RNgLoggerModule,
    RNgDynamicModule.forRoot(RNG_DYNAMICS) // register dynamics
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

You can use the RNgDynamicModule.forRoot in any module multiple times, the configurations are compacted by the library.

Now just define an element you want to proxy in your Components, as follows:

 <ng-container rngLazyLoaded="lazyComponent"></ng-container>

or by supplying the type:

@Component({
    selector: "my-component",
    template: `<ng-container [rngLazyLoaded]="myLazyComp"></ng-container>`
})
export class MyComponent {
    myLazyComp = LazyComponent
}

That's enough, your LazyComponent is ready to be lazy-loaded!

Known Limitations

Actually the library only supports lazy loading from modules available at build time using the loading callback:

import("./folder/MyModule.ts").then(m => m.MyModule)

The plan is to support loading modules not available at build time in the future.