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

get-set-action

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-set-action

A React State Management Library similar and alternative to mobx, redux.etc. it's the simplest, smallest and fastest state management library for react with dev tools support.

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
0
Created
Source

Action Management Library

This library provides a set of utilities for managing actions, async actions, and fetch operations, particularly useful for making AI calls. It is designed to simplify the handling of asynchronous operations and state management in JavaScript applications.

Features

  • Debounce and Throttle: Easily debounce or throttle your functions to control the rate of execution.
  • Async Actions: Manage asynchronous operations with built-in support for debouncing, throttling, and state management.
  • Fetch Utility: Simplified fetch operations with interceptors for request, response, and error handling.
  • State Management: Track and manage the state of your actions with ease.

Installation

To use this library, simply import the functions you need from the index.ts file.

Usage

Action

The action function allows you to create enhanced functions with interceptors and subscription capabilities.

API

  • intercept: Add an interceptor to modify the input before execution.
  • subscribe: Subscribe to the result of the action.
  • retry: Retry the last action with the same parameters.
  • getState: Get the current state of the action.

Example

import { action } from './index';

const myAction = action((props) => {
  console.log('Action executed with:', props);
  return props;
});

myAction.intercept((props) => {
  console.log('Intercepted:', props);
  return { ...props, intercepted: true };
});

myAction.subscribe((result) => {
  console.log('Result:', result);
});

myAction({ key: 'value' });

AsyncAction

The asyncAction function is used to manage asynchronous operations with support for debouncing and throttling.

API

  • run: Execute the async action.
  • abort: Abort the current async operation.
  • intercept: Add an interceptor to modify the input before execution.
  • interceptAfter: Add an interceptor to modify the result after execution.
  • interceptError: Add an interceptor to handle errors.

Example

import { asyncAction } from './index';

const myAsyncAction = asyncAction(async (payload) => {
  const response = await fetch(payload.url);
  return response.json();
}, { debounce: 500 });

myAsyncAction.run({ url: 'https://api.example.com/data' })
  .then(data => console.log('Data:', data))
  .catch(error => console.error('Error:', error));

Fetch

The Fetch function simplifies fetch operations with built-in interceptors for request, response, and error handling.

API

  • intercept: Add an interceptor to modify the request before execution.
  • interceptAfter: Add an interceptor to modify the response after execution.
  • interceptError: Add an interceptor to handle errors.

Example

import { Fetch } from './index';

const fetchAction = Fetch({ debounce: 1000 });

fetchAction.run({ url: 'https://api.example.com/data' })
  .then(response => console.log('Response:', response))
  .catch(error => console.error('Error:', error));

fetchAction.intercept((payload) => {
  console.log('Request Intercepted:', payload);
  return payload;
});

fetchAction.interceptAfter((data) => {
  console.log('Response Intercepted:', data);
  return data;
});

fetchAction.interceptError((error) => {
  console.error('Error Intercepted:', error);
  return error;
});

Conclusion

This library provides a comprehensive set of tools for managing actions and asynchronous operations in your applications. Whether you need to debounce a function, manage async actions, or perform fetch operations with custom interceptors, this library has you covered.

Keywords

get-set-react

FAQs

Package last updated on 30 Dec 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