🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@metamask/swappable-obj-proxy

Package Overview
Dependencies
Maintainers
9
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/swappable-obj-proxy

Tools for creating `Proxy`s around objects that are swappable via setTarget

2.3.0
latest
Source
npm
Version published
Weekly downloads
32K
26.67%
Maintainers
9
Weekly downloads
 
Created
Source

createSwappableProxy

Creates a Proxy around any object. Retarget the proxy with setTarget.

Installation

yarn add @metamask/swappable-obj-proxy

or

npm install @metamask/swappable-obj-proxy

Usage

createSwappableProxy

const { createSwappableProxy } = require('@metamask/swappable-obj-proxy');

const original = { sayHello: () => 'hi' };
const next = { sayHello: () => 'haay' };
const proxy = createEventEmitterProxy(original);

proxy.sayHello(); //=> "hi"
proxy.setTarget(next);
proxy.sayHello(); //=> "haay"

createEventEmitterProxy

Creates a Proxy around an EventEmitter. If the proxy has setTarget called with a different EventEmitter, all events will be removed from the old target and transferred to the new EventEmitter.

const { createEventEmitterProxy } = require('@metamask/swappable-obj-proxy');

const original = new EventEmitter();
const next = new EventEmitter();
const proxy = createEventEmitterProxy(original);

proxy.on('event', () => console.log('saw event!'));

// triggers the event handler
original.emit('event');

// moves listeners over to next
proxy.setTarget(next);

// does NOT trigger the event handler
original.emit('event');
// DOES trigger the event handler
next.emit('event');

FAQs

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