Skip to content

Instantly share code, notes, and snippets.

@silkentrance
Created April 3, 2016 14:43
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 silkentrance/21a7016933b0e7d7338f969ba928a457 to your computer and use it in GitHub Desktop.
Save silkentrance/21a7016933b0e7d7338f969ba928a457 to your computer and use it in GitHub Desktop.
import { decorate } from './private/utils';
// WIP: prototypical, might not be working at all, needs additional work!
function findSuperDesc(superklass, key)
{
let result;
let supklass = superklass;
while (supklass.prototype)
{
if (Object.hasOwnProperty(supklass, key))
{
result = supklass;
break;
}
supklass = Object.getPrototypeOf(supklass);
}
return result;
}
function handleDescriptor(target, key, descriptor) {
const superKlass = Object.getPrototypeOf(target);
const superDesc = findSUperDesc(superKlass, key);
return {
...superDesc,
value: descriptor.value,
initializer: descriptor.initializer,
get: descriptor.get || superDesc.get,
set: descriptor.set || superDesc.set
};
}
export default function extendDescriptor(...args) {
return decorate(handleDescriptor, args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment