New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

class-action

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

class-action

A simple library for writing composable functions and methods

latest
Source
npmnpm
Version
1.0.4
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Class Action

This is a simple library for creating composable functions. It helps to create methods or functions that may need to be modified later without introducing performance issues from multiple code compilation.

A class action is simply an object with a local action method and an optional list of reaction objects which are also ClassAction instances. Not only can reactions be added or removed later and nested to any depth, but the classes can be extended and composed freely to achieve whatever effect we want. We have used class-action as the primary abstraction for implementing a transparent and extensible reactivity system in element-action.

Installation

npm i class-action

Usage

import { ClassAction } from "class-action";
class MyClassAction extends ClassAction {
    constructor(value, ...reactions) {
        super(...reactions);
        this.value = value;
    }
    doAction(context) {
        context.value = (context.value || 0) + this.value;
    }
}

const myClassAction = new MyClassAction(5, new MyClassAction(2), new MyClassAction(7));
const myContext = { };
myClassAction.act(myContext);
console.log(myContext);   // prints 14
myClassAction.act(myContext);
console.log(myContext);   // prints 28
myClassAction.reactions.splice(0, 1);
myClassAction.act(myContext);
console.log(myContext.value);   // prints 40

Documentation

This library exports a single class with a very simple API which can be picked up in a few minutes here.

Contributing

Help improve Class-action by contributing to this project. You can contribute in many ways. See the contributing guidelines. You can also show your support by sponsoring us.

Thank you for contributing.

Sponsors

...

Keywords

class-action

FAQs

Package last updated on 06 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts