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

@karelics/angular-unleash-proxy-client

v17.0.0

Published

Angular wrapper for [unleash-proxy-client](https://github.com/Unleash/unleash-proxy-client-js).

Downloads

889

Readme

@karelics/angular-unleash-proxy-client

Angular wrapper for unleash-proxy-client.

Usage

1. Configure unleash proxy

Unleash proxy server should be run and configured.

2. Install

Install @karelics/angular-unleash-proxy-client from NPM.

npm install @karelics/angular-unleash-proxy-client

Install unleash-proxy-client if it is not installed yet.

npm install unleash-proxy-client

3. Initialize

karelics/angular-unleash-proxy-client should be initialized once in AppModule (or bootstrap standalone component).

import { provideUnleashProxy } from '@karelics/angular-unleash-proxy-client';

providers: [
  provideUnleashProxy({
    url: unleash_proxy_url,
    clientKey: client_key,
    appName: app_name,
  }),
]

4. Use

Directive

You can define else template similar to *ngIf directive.

<div *featureEnabled="'feature_name'; else disabledTmpl">enabled</div>

<ng-template #disabledTmpl>disabled</ng-template>

<div *featureDisabled="'feature_name'">disabled</div>

Guard

Optionally you can define route to redirect if feature toggle condition was not met.

const routes: Routes = [
  {
    path: 'a',
    canActivate:[
      featureEnabled('feature_name'),
    ],
    component: AComponent,
  },
  {
    path: 'b',
    canActivate:[
      featureDisabled('feature_name', 'c'),
    ],
    component: BComponent,
  },
  {
    path: 'c',
    component: CComponent,
  }
];

Service

UnleashService has the following logic around original unleash proxy client service:

  • wraps original service events into observables
  • provides isEnabled/isDisabled methods to check current toggle state
  • provides isEnabled$/isDisabled$ methods returning observable to be informed about toggle state changes

Other unleash service features can be accessed with unleash property.

import { UnleashService } from '@karelics/angular-unleash-proxy-client';

@Injectable()
export class MyService {
  constructor(
    private unleashService: UnleashService,
  ) {
    // don't forget to unsubscribe
    this.unleashService.isEnabled$('feature_name').pipe(
      tap(...),
    ).subscribe();
  }
  
  methodA(): void {
    if (this.unleashService.isDisabled('feature_name')) {
      ...
    }
  }

  methodB(): void {
    this.unleashService.unleash.updateContext(...);
  }
}

Updates

Feature toggles state is requested from unleash proxy each time on page load, but by default unleash proxy client every 30 seconds requests updates from unleash proxy to perform runtime changes. If requesting state on page load if enough in your case, you can disable updates using unleash configuration:

import { provideUnleashProxy } from '@karelics/angular-unleash-proxy-client';

providers: [
  provideUnleashProxy({
    ... // other options
    disableRefresh: true,
    disableMetrics: true,
  }),
]