Skip to content

How to wrap reactive object (with array) in custom proxy? #6443

Discussion options

You must be logged in to vote

Hi, sorry for the late reply.

I came up with this and called it stainableProxy. It uses Array.isArray and watchArray. (Date is behaving odd as a Proxy.)

type stainableProxyOptions = {
  onDirty: () => void;
};

export const stainableProxy = <T>(
  value: Ref<T>,
  options: Partial<stainableProxyOptions> = {}
): Ref<T> => {
  const defaultOptions: stainableProxyOptions = {
    onDirty: () => void 0,
  };

  const { onDirty } = { ...defaultOptions, ...options };

  const handler = (path: Array<string> = []) => {
    /**
     * Using WeakMap allows to yield the same proxy
     * for multiple get calls on the same property
     * without cluttering the memory
     */
    const map = new WeakMap(

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SpazzMarticus
Comment options

Answer selected by SpazzMarticus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants