New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

flux-action-class

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flux-action-class - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

6

dist/index.d.ts
export declare type IActionStandardArgs<P, M> = P extends undefined ? M extends undefined ? [] : [P, M] : M extends undefined ? [P] : [P, M];
export declare const prefix = "flux-action-class:";
export declare let prefixDefault: string;
export declare const setPrefix: (newPrefix: string) => void;
export declare abstract class ActionStandard<Payload = undefined, Meta = undefined> {
protected static readonly _prefix: string;
private static readonly prefixFinal;
protected static readonly prefix?: string;
static readonly type: string;

@@ -6,0 +8,0 @@ readonly type: string;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.prefix = 'flux-action-class:';
exports.prefixDefault = 'flux-action-class:';
exports.setPrefix = (newPrefix) => {
exports.prefixDefault = newPrefix;
};
class ActionStandard {

@@ -15,7 +18,12 @@ constructor(...args) {

}
static get prefixFinal() {
if (this.prefix) {
return this.prefix;
}
return exports.prefixDefault;
}
static get type() {
return `${this._prefix}${this.name}`;
return `${this.prefixFinal}${this.name}`;
}
}
ActionStandard._prefix = exports.prefix;
exports.ActionStandard = ActionStandard;
{
"name": "flux-action-class",
"version": "1.1.1",
"version": "1.2.0",
"description": "Boilerplate free class-based action creator. Following flux-standard-action spec. Built with TypeScript.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -19,2 +19,5 @@ # flux-action-class [![Build Status](https://travis-ci.org/keenondrums/flux-action-class.svg?branch=master)](https://travis-ci.org/keenondrums/flux-action-class)

- [Customize action prefix](#customize-action-prefix)
- [Sub-classing](#sub-classing)
- [Using `setPrefix`](#using-setprefix)
- [Usage in reducers](#usage-in-reducers)

@@ -54,3 +57,3 @@ <!-- END doctoc generated TOC please keep comment here to allow auto update -->

- Own (non-static) `error` readonly boolean field set to `true` if payload is an instance of `Error`
- Protected static `_prefix` field which is the the first part of `type` set to 'flux-action-class:' by default
- Protected static `prefix` field which is the the first part of `type` set to 'flux-action-class:' by default

@@ -149,2 +152,4 @@ ## Examples

#### Sub-classing
```ts

@@ -154,3 +159,3 @@ import { ActionStandard } from 'flux-action-class'

abstract class AppBaseAction<Payload = undefined, Meta = undefined> extends ActionStandard<Payload, Meta> {
protected static readonly _prefix = 'app:'
protected static readonly prefix = 'app:'
}

@@ -161,1 +166,21 @@

```
#### Using `setPrefix`
```ts
import { ActionStandard, setPrefix } from 'flux-action-class'
// Add it only once and it changes default prefix for all actions
setPrefix('app:')
class ActionTest7 extends ActionStandard {}
// Creates action with no payload, no meta, type 'app:ActionTest7' and error = false
```
## Usage in reducers
Be aware, if you're using `switch-case` based reducers, TS compiler is no longer capable of automatic union discrimination, in other words the compiler can no longer match action's type by its field `type`.
Consider going with selecting a reducer from a map by key ([relevant article (go to Tip 3: Switch away from switch)](https://medium.com/@andreygoncharov/yet-another-guide-to-reduce-boilerplate-in-your-redux-ngrx-app-3794a2dd7bf), [Redux's official documentation](https://redux.js.org/recipes/reducing-boilerplate#generating-reducers)) or using [ngrx-actions](https://github.com/amcdnl/ngrx-actions) instead.
You can take a look at the discussion [here](https://github.com/keenondrums/flux-action-class/issues/1)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc