Skip to content

Instantly share code, notes, and snippets.

@Gomah
Created August 11, 2017 05:27
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 Gomah/8ac0325fe67894a3b8e238094dcba7bc to your computer and use it in GitHub Desktop.
Save Gomah/8ac0325fe67894a3b8e238094dcba7bc to your computer and use it in GitHub Desktop.
export class GraphModel {
/**
* @param {Object} attrs Attributes on the GraphModel.
*/
constructor(attrs) {
Object.defineProperty(this, 'attrs', { value: attrs, enumerable: false });
Object.keys(this.attrs).filter(key => !(key in this)).forEach(key => {
let descriptor;
if (attrs[key] === null) {
descriptor = {
enumerable: true,
get() {
return null;
},
};
} else {
descriptor = {
enumerable: true,
get() {
return this.attrs[key].valueOf();
},
};
}
Object.defineProperty(this, key, descriptor);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment