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

@harmowatch/redux-decorators

v0.1.1

Published

[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovateapp.com/) [![Build Status](https://travis-ci.org/HarmoWatch/redux-decorators.svg?branch=master)](https://travis-ci.org/HarmoWatch/redux-decorators) [![Mai

Downloads

35

Readme

@harmowatch/redux-decorators

Renovate enabled Build Status Maintainability Test Coverage

What is this package for?

This package provides a set of decorators you've to wire manually against redux. The decorators are used well in the Angular 2+ package @harmowatch/ngx-redux-core.

The following decorators are available

ReduxActionDecorator

  • [ ] can be used on class declarations
  • [x] can be used on class method declarations

When the decorated method was called it will invoke ReduxActionDispatcher.dispatch. Please checkout the documentation about ReduxActionDispatcher for more information about action dispatching.

class SomeActionClass {

    // (1.1) decorate a class method 
    @ReduxActionDecorator.forMethod({type: 'some-other-type'})
    public methodWithCustomType<T>(input: T): T {
        return input;
    }

    // (1.2) decorate a class method
    @ReduxActionDecorator.forMethod()
    public methodWithAutomaticType<T>(input: T): T {
        return input;
    }

}

// (2.1) get the decorated data (will return {type: 'some-other-type', contextClass: SomeActionClass})
ReduxActionContextDecorator.get(SomeActionClass.prototype.methodWithCustomType)

// (2.2) get the decorated data (will return {type: 'methodWithAutomaticType', contextClass: SomeActionClass})
ReduxActionContextDecorator.get(SomeActionClass.prototype.methodWithAutomaticType)

take a look at the unit test

ReduxActionContextDecorator

  • [X] can be used on class declarations
  • [ ] can be used on class method declarations

This decorator only makes sense together with the ReduxActionDecorator, because the configured prefix is used a prefix for each configured action type. Please see ReduxActionDispatcher.getType for more information.

// (1) decorate the class
@ReduxActionContextDecorator.forClass({prefix: 'prefix://foo/bar'})
class SomeActionClass {

    @ReduxActionDecorator.forMethod({type: 'some-other-type'})
    public methodWithCustomType<T>(input: T): T {
        return input;
    }

    @ReduxActionDecorator.forMethod()
    public methodWithAutomaticType<T>(input: T): T {
        return input;
    }

}

// (2) get the decorated data (will return {prefix: 'prefix://foo/bar'})
ReduxActionContextDecorator.get(SomeActionClass)

take a look at the unit test

ReduxReducerDecorator

  • [ ] can be used on class declarations
  • [X] can be used on class method declarations

This decorator will wire a reducer class method against a method that was decorated by the ReduxActionDecorator.

class SomeReducerClass {

    // (1.1) decorate a class method 
    @ReduxReducerDecorator.forMethod(SomeActionClass.prototype.methodWithCustomType)
    public doSomething() {

    }

    // (1.2) decorate a class method 
    @ReduxReducerDecorator.forMethod([
        SomeActionClass.prototype.methodWithCustomType,
        SomeActionClass.prototype.methodWithAutomaticType,
    ])
    public doSomethingWhenOneOfTheActionsAreInvoked() {

    }

}

// (2.1) get the decorated data (will return SomeActionClass.prototype.methodWithCustomType)
ReduxReducerDecorator.get(SomeReducerClass.prototype.doSomething)

// (2.2) get the decorated data (will return [SomeActionClass.prototype.methodWithCustomType, SomeActionClass.prototype.methodWithAutomaticType])
ReduxReducerDecorator.get(SomeReducerClass.prototype.doSomethingWhenOneOfTheActionsAreInvoked)

take a look at the unit test

ReduxStateDecorator

  • [X] can be used on class declarations
  • [ ] can be used on class method declarations
// (1) decorate the class
@ReduxStateDecorator.forClass({name: 'state-1-2-3'})
class SomeStateClass {

}

// (2) get the decorated data (will return {name: 'state-1-2-3'})
ReduxStateDecorator.get(SomeStateClass)

take a look at the unit test

Action dispatching

ReduxActionDispatcher

As already mentioned above there's a additional static class ReduxActionDispatcher. This class has two public static methods:

ReduxActionDispatcher.getType

This method will resolve a valid redux action type for the given method. The given method must be decorated by ReduxActionDecorator.forMethod. If the class of the method is also decorated by ReduxActionContextDecorator.forClass, then the defined prefix is prepended to the returned string.

take a look at the unit test

ReduxActionDispatcher.dispatch

The dispatch method will emit a new action on the rxjs.Subject you can access by the public, readonly property ReduxActionDispatcher.dispatchedActions. If the return value of the action method is an Observable or a Promise, then the action is dispatched only if the Observable completes or the Promise resolves.

ReduxActionDispatcher.dispatchedActions.subscribe(action => {
    // do something when a action was dispatched i.e. fire the redux action on your store
})

take a look at the unit test