SHARE
TWEET

Untitled

a guest May 19th, 2017 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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']
RAW Paste Data
Challenge yourself this year...
Learn something new in 2017
Top