Skip to content

Instantly share code, notes, and snippets.

@gsathya
Created March 7, 2018 00:54
Show Gist options
  • Save gsathya/84628f5aec2d5efa069306695016b402 to your computer and use it in GitHub Desktop.
Save gsathya/84628f5aec2d5efa069306695016b402 to your computer and use it in GitHub Desktop.
Rethink PrivateName
function observed({kind, key, placement, descriptor, initializer}, privateFieldMaker) {
assert(kind == "field");
assert(placement == "own");
// Create a new anonymous private name as a key for a class element
let { get, set } = privateFieldMaker();
let underlyingDescriptor = { enumerable: false, configurable: false, writable: true };
let underlying = { kind, key: storage, placement, descriptor: underlyingDescriptor, initializer };
return {
kind: "method",
key,
placement,
descriptor: {
get() { get(this); },
set(value) {
set(this, value);
// Assume the @bound decorator was used on render
window.requestAnimationFrame(this.render);
},
enumerable: descriptor.enumerable,
configurable: descriptor.configurable,
},
extras: [underlying]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment