Advertisement
Guest User

Untitled

a guest
May 19th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. let editableThings = new WeakMap();
  2. function finisherFor(prop) {
  3. function finisher(C) {
  4. let list = editableThings.get(C);
  5. if (!list) {
  6. list = [];
  7. editableThings.set(C, list);
  8. }
  9.  
  10. list.push(prop);
  11. }
  12. }
  13.  
  14. function Editable() {
  15. return function ({ key, ... props}) {
  16. return { key, ... props, finisher: finisherFor(key) };
  17. }
  18. }
  19.  
  20. function getEditableProps(C) {
  21. return editableThings.get(C) || [];
  22. }
  23.  
  24.  
  25. class Blog {
  26. @Editable title;
  27. @Editable author;
  28. }
  29.  
  30.  
  31. print(getEditableProps(Blog)); // ['title', 'author']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement