Skip to content

Instantly share code, notes, and snippets.

@bterlson
Last active May 20, 2017 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bterlson/52ee9948ce3f9defc41586a9221a7eca to your computer and use it in GitHub Desktop.
Save bterlson/52ee9948ce3f9defc41586a9221a7eca to your computer and use it in GitHub Desktop.
let editableThings = new WeakMap();
function finisherFor(prop) {
return function finisher(C) {
let list = editableThings.get(C);
if (!list) {
list = [];
editableThings.set(C, list);
}
list.push(prop);
}
}
function Editable() {
return function ({ key, ... props}) {
return { key, ... props, finisher: finisherFor(key) };
}
}
function getEditableProps(C) {
return editableThings.get(C) || [];
}
class Blog {
@Editable title;
@Editable author;
}
print(getEditableProps(Blog)); // ['title', 'author']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment