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

@easylibs/tempdata-backend

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@easylibs/tempdata-backend

The `TempDataBackend` class is a JavaScript class that provides methods for persisting data to a server and saving form data to a server. It uses the `FetchRequest` and `TempData` classes to perform these tasks.

latest
Source
npmnpm
Version
1.2.6
Version published
Maintainers
0
Created
Source

TempDataBackend

The TempDataBackend class is a JavaScript class that provides methods for persisting data to a server and saving form data to a server. It uses the FetchRequest and TempData classes to perform these tasks.

GitHub stars GitHub issues npm version License jsDelivr downloads

Usage

To use the TempDataBackend class, you first need to create an instance of the class. You can do this by passing in a TempData instance and a URI to the constructor.

const database = new TempData("my-database");
const backend = new TempDataBackend(database, "https://example.com/api/data");

Once you have created an instance of the TempDataBackend class, you can use the persist() method to persist data to the server. The persist() method takes two optional parameters: a redirect URL and a callback function. The redirect URL is the URL that the user will be redirected to after the data is persisted. The callback function is called after the data is persisted.

backend.persist({
  onPostFetch: (response: any, status:number) => {
    // Do something
  },
  onPreFetch: (data: any) => {
    // Do something
  },
  onSuccess: (response: any) => {
    // Do something
  },
  onError: (error: Error, status: number) => {
    // Do something
  }
});

The save() method can be used to save form data to the server. The save() method takes an object as its only parameter. The object must contain the following properties:

  • submiter: The submit button element.
  • callbacks: an object containing the onPreFetch, onPostFetch, onSuccess and onError callbacks
  • loader (optional): The loader HTML content to display while saving the data.
const submitter = document.querySelector("button[type=submit]");
const loader = "<div>Loading...</div>";
backend.save(submitter, loader {
  onPostFetch: (response: any, status:number) => {
    // Do something
  },
  onPreFetch: (data: any) => {
    // Do something
  },
  onSuccess: (response: any) => {
    // Do something
  },
  onError: (error: Error, status: number) => {
    // Do something
  }
});

Implementation Details

The TempDataBackend class uses the FetchRequest class to send data to the server. The FetchRequest class is a wrapper around the Fetch API that provides a number of helpful features, such as automatic JSON parsing and error handling.

The TempDataBackend class also uses the TempData class to store data in the browser's IndexedDB database. The TempData class provides a number of methods for working with IndexedDB

Keywords

backend

FAQs

Package last updated on 14 Sep 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