Socket
Socket
Sign inDemoInstall

@braintree/destructor

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @braintree/destructor

A module used to register functions for teardown


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Install size
10.9 kB
Created
Weekly downloads
 

Readme

Source

destructor

Installation

npm install @braintree/destructor

Example

A class to keep track of tasks that must be performed to clean up any side effects caused by your SDK.

import Destructor from "@braintree/destructor";

class MyClass {
  constructor() {
    this.destructor = new Destructor();

    // add iframe to page
    const iframe = document.createElement("iframe");
    iframe.src = "https://example.com";
    document.body.appendChild(iframe);

    // register the removal of the iframe with the destructor
    this.destructor.register(() => {
      if (iframe.parentNode) {
        iframe.parentNode.removeChild(iframe);
      }
    });

    // any other tasks that need to be registered to the destructor
    // go here. Think event listeners or script tags, etc.
  }

  teardown() {
    // if you need to clean up any changes MyClass made, call
    // teardown and the destructor will run any functions that
    // were registered to it
    this.destructor.teardown();
  }
}

Requirements

This module requires Promises, so if used in an environment without Promise support, Promises will need to be polyfilled.

Running tests

npm test

FAQs

Last updated on 30 Mar 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc