All Projects → GoogleChrome → Proxy Polyfill

GoogleChrome / Proxy Polyfill

Licence: apache-2.0
Proxy object polyfill

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Proxy Polyfill

Nginx Tutorial
这是一个 Nginx 极简教程,目的在于帮助新手快速入门 Nginx。
Stars: ✭ 845 (-11.15%)
Mutual labels:  proxy
Proxychains Ng
proxychains ng (new generation) - a preloader which hooks calls to sockets in dynamically linked programs and redirects it through one or more socks/http proxies. continuation of the unmaintained proxychains project. the sf.net page is currently not updated, use releases from github release page instead.
Stars: ✭ 7,553 (+694.22%)
Mutual labels:  proxy
New Pac
翻墙-科学上网、免费翻墙、免费科学上网、免费自由上网、fanqiang、翻墙梯子、免费软件/方法,一键翻墙浏览器,免费shadowsocks/ss/ssr/v2ray/goflyway账号/节点分享,vps一键搭建翻墙服务器脚本/教程,电脑、手机、iOS、安卓、windows、Mac、Linux、路由器翻墙
Stars: ✭ 31,869 (+3251.1%)
Mutual labels:  proxy
Docker Apache Proxy
Apache web server like proxy to Docker
Stars: ✭ 9 (-99.05%)
Mutual labels:  proxy
Hacking With Golang
Golang安全资源合集
Stars: ✭ 876 (-7.89%)
Mutual labels:  proxy
Grpc Tools
A suite of gRPC debugging tools. Like Fiddler/Charles but for gRPC.
Stars: ✭ 881 (-7.36%)
Mutual labels:  proxy
Cloak
A censorship circumvention tool to evade detection against state adversaries
Stars: ✭ 942 (-0.95%)
Mutual labels:  proxy
Ponyfill
🦄 Like polyfill but with pony pureness
Stars: ✭ 945 (-0.63%)
Mutual labels:  polyfill
Switcher
Run SSH and HTTP(S) on the same port
Stars: ✭ 877 (-7.78%)
Mutual labels:  proxy
Simple Traefik Proxy And Services
Get your own services running - within just a few minutes and with automatic SSL.
Stars: ✭ 21 (-97.79%)
Mutual labels:  proxy
Bbc Rss
BBC iPlayer programmes / Nitro API to RSS adaptor app
Stars: ✭ 10 (-98.95%)
Mutual labels:  proxy
Shadowsocks Php
A php port of shadowsocks based on workerman. A socks5 proxy written in PHP.
Stars: ✭ 869 (-8.62%)
Mutual labels:  proxy
Proxly
Easiest way to proxy a list of objects/functions in Javascript
Stars: ✭ 15 (-98.42%)
Mutual labels:  proxy
Broadcast Channel
📡 BroadcastChannel to send data between different browser-tabs or nodejs-processes 📡
Stars: ✭ 843 (-11.36%)
Mutual labels:  polyfill
Xx Net
A proxy tool to bypass GFW.
Stars: ✭ 30,963 (+3155.84%)
Mutual labels:  proxy
Polyfill Service
Javascript polyfills as a service. Java implementation.
Stars: ✭ 8 (-99.16%)
Mutual labels:  polyfill
Concent
State management that tailored for react, it is simple, predictable, progressive and efficient.
Stars: ✭ 882 (-7.26%)
Mutual labels:  proxy
S3proxy
Access other storage backends via the S3 API
Stars: ✭ 952 (+0.11%)
Mutual labels:  proxy
Citadelcore
Cross platform filtering HTTP/S proxy based on .NET Standard 2.0.
Stars: ✭ 28 (-97.06%)
Mutual labels:  proxy
Broxy
An HTTP/HTTPS intercept proxy written in Go.
Stars: ✭ 912 (-4.1%)
Mutual labels:  proxy

Build

This is a polyfill for the Proxy object, part of ES6. See the MDN docs or Introducing ES2015 Proxies for more information on Proxy itself. Unlike other polyfills, this does not require Object.observe, which is no longer supported anywhere.

The polyfill supports just a limited number of proxy 'traps'. It also works by calling seal on the object passed to Proxy. This means that the properties you want to proxy must be known at creation time.

Additionally, your objects' prototypes will be snapshotted at the time a proxy is created. The properties of your objects can still change - you're just unable to define new ones. For example, proxying unrestricted dictionaries is not a good use-case for this polyfill.

Currently, the following traps are supported-

  • get
  • set
  • apply
  • construct

The Proxy.revocable method is also supported, but only for calls to the above traps.

This has no external dependencies. Skip down to usage to get started.

Example

The most compelling use case for Proxy is to provide change notifications.

function observe(o, callback) {
  return new Proxy(o, {
    set(target, property, value) {
      callback(property, value);
      target[property] = value;
    },
  });
}

const x = {'name': 'BB-8'};
const p = observe(x, (property, value) => console.info(property, value));
p.name = 'BB-9';
// name BB-9

You can extend this to generate change notifications for anywhere in an object tree-

function observe(o, callback) {
  function buildProxy(prefix, o) {
    return new Proxy(o, {
      set(target, property, value) {
        // same as above, but add prefix
        callback(prefix + property, value);
        target[property] = value;
      },
      get(target, property) {
        // return a new proxy if possible, add to prefix
        const out = target[property];
        if (out instanceof Object) {
          return buildProxy(prefix + property + '.', out);
        }
        return out;  // primitive, ignore
      },
    });
  }

  return buildProxy('', o);
}

const x = {'model': {name: 'LEAF'}};
const p = observe(x, (property, value) => console.info(property, value));
p.model.name = 'Tesla';
// model.name Tesla

Adding new properties

The following line will fail (with a TypeError in strict mode) with the polyfill, as it's unable to intercept new properties-

p.model.year = 2016;  // error in polyfill

However, you can replace the entire object at once - once you access it again, your code will see the proxied version.

p.model = {name: 'Falcon', year: 2016};
// model Object {name: "Falcon", year: 2016}

For a similar reason, this polyfill can't proxy Array objects very well - but you can replace them all at once.

Usage

Install via your favourite package manager as proxy-polyfill.

To polyfill Proxy everywhere

You should include proxy-polyfill into your build system (just require it directly, it doesn't export anything), or import the proxy.min.js file directly. This is the recommended approach and works on the web, in Node, or React Native.

To consume the polyfill as a function

Requires ./src/proxy.js, which exports a proxy polyfill builder function in commonJS.

// commonJS require
const proxyPolyfill = require('proxy-polyfill/src/proxy')();

// Your environment may also support transparent rewriting of commonJS to ES6:
import ProxyPolyfillBuilder from 'proxy-polyfill/src/proxy';
const proxyPolyfill = ProxyPolyfillBuilder();

// Then use...
const myProxy = new proxyPolyfill(...);

Support

The polyfill supports browsers that implement the full ES5 spec, such as IE9+ and Safari 6+. It may work in other non-browser environments too.

Note that Firefox, Chrome, Safari 10+ and Edge support Proxy natively. You don't need this if you're only targeting these modern browsers.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].