Basic usage

Javascript’s Proxy object is powerful but a bit awkward to use. The _.proxied function creates the Proxy for you and handles calling back to your handler when functions on the Proxy are called or properties are accessed.

import { proxied } from 'radash'

type Property = 'name' | 'size' | 'getLocation'

const person = proxied((prop: Property) => {
  switch (prop) {
    case 'name':
      return 'Joe'
    case 'size':
      return 20
    case 'getLocation'
      return () => 'here'
  }
})

person.name // => Joe
person.size // => 20
perons.getLocation() // => here

Testing

This _.proxied function is 100% covered by tests. See them and contribute at GitHub.

Source

See the source for _.proxied on GitHub.