Skip to content

Commit

Permalink
added revocable proxies example
Browse files Browse the repository at this point in the history
  • Loading branch information
sumeetsarkar committed Nov 20, 2017
1 parent 66ecb05 commit 9c1ac88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
10. [Let Const Var](let-const-var/index.js)
11. [Object literals](object-literals/index.js)
12. [Promises](promises/index.js)
13. [Proxies](proxies/index.js)
13. [Proxies/ Revocable Proxies](proxies/index.js)
14. [Spread](spread/index.js)
15. [Template / Tagged Template literals](template-literals/index.js)
10 changes: 10 additions & 0 deletions proxies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,21 @@
console.log(myProxyObj.name);
console.log(myProxyObj.language);
}

function demoRevocableProxy() {
const { proxy, revoke } = Proxy.revocable({}, {}); // passing empty object as target and handler
proxy.name = 'Sumeet Sarkar';
console.log(proxy.name);
revoke();
console.log(proxy); // works, as Proxy still shows the entire object
console.log(proxy.name); // error! TypeError: Cannot perform 'get' on a proxy that has been revoked
}

function demo() {
console.log('\n\PROXIES');
demoSimpleProxy();
demoProxyCreator();
demoRevocableProxy();
};

(context || this).demoLibs['proxies'] = demo;
Expand Down

0 comments on commit 9c1ac88

Please sign in to comment.