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'
}) // => Joe
person.size // => 20
perons.getLocation() // => here


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


See the source for _.proxied on GitHub.