Created
September 16, 2015 19:03
-
-
Save luggage66/8920135a556fc33b06ac to your computer and use it in GitHub Desktop.
Bookshelf.js 0.8.2 static method inheritance monkey-punching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function fixBookShelfES6Inheritance(target) { | |
// console.log('Fixing:', target.name); | |
let parentConstructor = Object.getPrototypeOf(target.prototype).constructor; | |
let parentStaticProperties = Object.keys(parentConstructor); | |
// console.log('Adding static properties:', parentStaticProperties); | |
// TODO: Deal with static methods that want to call super() (right now they are REPLACED!) | |
parentStaticProperties.forEach(propName => target[propName] = parentStaticProperties[propName]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import BookshelfModelDecorator from './fixBookShelfES6Inheritance'; | |
@BookshelfModelDecorator | |
export default class User extends bookshelf.Model | |
{ | |
get tableName() { return 'User'; } | |
constructor(attr, options) { | |
super(attr, options); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment