{"id":28425222,"url":"https://github.com/metamask/swappable-obj-proxy","last_synced_at":"2025-06-25T21:31:14.414Z","repository":{"id":65412293,"uuid":"133742358","full_name":"MetaMask/swappable-obj-proxy","owner":"MetaMask","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-01T06:55:15.000Z","size":1330,"stargazers_count":5,"open_issues_count":8,"forks_count":3,"subscribers_count":34,"default_branch":"main","last_synced_at":"2025-06-05T10:50:27.667Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MetaMask.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":"metamask","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2018-05-17T01:30:44.000Z","updated_at":"2025-04-25T12:40:29.000Z","dependencies_parsed_at":"2024-06-18T23:54:15.280Z","dependency_job_id":null,"html_url":"https://github.com/MetaMask/swappable-obj-proxy","commit_stats":{"total_commits":26,"total_committers":3,"mean_commits":8.666666666666666,"dds":"0.42307692307692313","last_synced_commit":"c9fcaebacb1dd618e2958aeeed1215e7e83b5013"},"previous_names":["kumavis/eventemitter-proxy"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/MetaMask/swappable-obj-proxy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fswappable-obj-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fswappable-obj-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fswappable-obj-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fswappable-obj-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MetaMask","download_url":"https://codeload.github.com/MetaMask/swappable-obj-proxy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fswappable-obj-proxy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261955920,"owners_count":23235976,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-05T10:36:38.572Z","updated_at":"2025-06-25T21:31:14.406Z","avatar_url":"https://github.com/MetaMask.png","language":"TypeScript","readme":"# createSwappableProxy\n\nCreates a `Proxy` around any object. Retarget the proxy with `setTarget`.\n\n## Installation\n\n`yarn add @metamask/swappable-obj-proxy`\n\nor\n\n`npm install @metamask/swappable-obj-proxy`\n\n## Usage\n\n### createSwappableProxy\n\n```js\nconst { createSwappableProxy } = require('@metamask/swappable-obj-proxy');\n\nconst original = { sayHello: () =\u003e 'hi' };\nconst next = { sayHello: () =\u003e 'haay' };\nconst proxy = createEventEmitterProxy(original);\n\nproxy.sayHello(); //=\u003e \"hi\"\nproxy.setTarget(next);\nproxy.sayHello(); //=\u003e \"haay\"\n```\n\n### createEventEmitterProxy\n\nCreates a `Proxy` around an `EventEmitter`. If the proxy has `setTarget` called with a different `EventEmitter`, all events will be removed from the old target and transferred to the new EventEmitter.\n\n```js\nconst { createEventEmitterProxy } = require('@metamask/swappable-obj-proxy');\n\nconst original = new EventEmitter();\nconst next = new EventEmitter();\nconst proxy = createEventEmitterProxy(original);\n\nproxy.on('event', () =\u003e console.log('saw event!'));\n\n// triggers the event handler\noriginal.emit('event');\n\n// moves listeners over to next\nproxy.setTarget(next);\n\n// does NOT trigger the event handler\noriginal.emit('event');\n// DOES trigger the event handler\nnext.emit('event');\n```\n","funding_links":["https://opencollective.com/metamask"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetamask%2Fswappable-obj-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetamask%2Fswappable-obj-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetamask%2Fswappable-obj-proxy/lists"}