create-proxy

0.0.1 • Public • Published

create-proxy

a tool to add proxies to object, useful for trapping methods in object

Install

yarn add create-proxy
npm i create-proxy -S

Usage

import createProxy from 'create-proxy'
 
const target = {
  a () {},
  b () {},
  c: 1
}
 
const pTarget = createProxy(target, {
  a: {
    apply (target, thisArg, args) {
      target.apply(thisArg, args)
      console.log('proxy:a')
    }
  },
  b: {
    apply (target, thisArg, args) {
      target.apply(thisArg, args)
      console.log('proxy:b')
    }
  }
})
 
p.a() // proxy:a
p.b() // proxy:b
p.c // 1

Example

  • vuex-router-histroy trap router's methods(push、replace、go、back、forward) and create history log

Readme

Keywords

none

Package Sidebar

Install

npm i create-proxy

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

69.4 kB

Total Files

11

Last publish

Collaborators

  • l-chris