0.0.1 • Published 6 years ago

create-proxy v0.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

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