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

@isaiahiroko/ng-decorators

v0.0.6

Published

A collection of common decorators for use in angular applications.

Downloads

4

Readme

NG Decorators

A collection of common decorators for use in angular applications.

  • @Default()
  • @Delay()
  • @Log()
  • @Tick()
  • @Track()
  • @Unsubscribe()

Install

Run npm install isaiahiroko/ng-decorators --save

@Default()

A Property Decorator, designed to be a companion of the popular angular @Input() decorator.

import { Default } from 'isaiahiroko/ng-decorators'

@Component({...})
class SampleComponent {

    // if color is not define, it gets a value of #AABBCC
    @Input() @Default('#AABBCC') color: string
    
    // if property is not defined, it gets the Object defined here
    // if property is defined, it is merge with the object defined here, 
    // with the former having a higher precedence
    @Input() @Default({
        name: '...',
        desc: '...',
        width: '50px',
        height: '100px',
    }) property: Object
    
    ...
}

@Delay()

@Delay is a Method Decorator that that delays the execution of a method by an amount ot time when called.

import { Delay } from 'isaiahiroko/ng-decorators'

class SampleClass {

    ...

    // This method won't be executed until after 1000miliseconds anytime it is called
    @Delay(1000)
    public DoSomething(){ 
        console.log('I had a little delay...but here I am')
    }

    ...
}

@Log()

@Log is a Class Decorator that logs (in console) every actvity of the class .

import { Log } from 'isaiahiroko/ng-decorators'

// this decorator woudld log infomartion about Sit, Walk, Stand methods
// anything they are called

@Log()
class SampleClass {

    public Sit(){ 
        
    }

    public Walk(){ 
        
    }

    public Stand(){ 
        
    }
}

@Tick()

@Tick is a Method Decorator that calls the corresponding method after every interval until a limit is reached. The first call to the method commences the process.

import { Delay } from 'isaiahiroko/ng-decorators'

class SampleClass {

    ...

    // After the first call,
    // `DoSomething` would be called every 1000ms for the next 5000ms.
    @Tick(1000, 5000)
    public DoSomething(){ 
        console.log('wait for me...i would be back soon...')
    }

    ...
}

@Track()

[TODO]

@Unsubscribe()

@Unsubscribe is a Class Decorator that unsubscribes existing subscriptions attached to a @Components before it is destroyed.

import { Delay } from 'isaiahiroko/ng-decorators'
import { Subscription } from 'rxjs'

@Unsubscribe()
class SampleClass {

    // won't work if the subscriotion
    // is not assigned to a class property
    subs: Subscription

    public constructor(){ 
        // this observer would be unsubscribed 
        // just before this component is destroyed
        // because of the attached decorator: @Unsubscribe()
        combineLatest(...).pipe(
          mergeMap((values) => {
            ...
          }),
          map((mergedValues) => {
            '''
          })
        ).subscribe((mappedValues) => {
            ...
        })
    }

    // No need to do this
    // ngOnDestroy () {
    //     this.subs.unsubscribe()
    // }

}

License