mirror of
https://github.com/flarum/framework.git
synced 2025-05-23 07:09:57 +08:00
Massive JavaScript cleanup
- Use JSX for templates - Docblock/comment everything - Mostly passes ESLint (still some work to do) - Lots of renaming, refactoring, etc. CSS hasn't been updated yet.
This commit is contained in:
@ -1,11 +1,20 @@
|
||||
/**
|
||||
* The `mixin` utility assigns the properties of a set of 'mixin' objects to
|
||||
* the prototype of a parent object.
|
||||
*
|
||||
* @example
|
||||
* class MyClass extends mixin(ExtistingClass, evented, etc) {}
|
||||
*
|
||||
* @param {Class} Parent The class to extend the new class from.
|
||||
* @param {...Object} mixins The objects to mix in.
|
||||
* @return {Class} A new class that extends Parent and contains the mixins.
|
||||
*/
|
||||
export default function mixin(Parent, ...mixins) {
|
||||
class Mixed extends Parent {}
|
||||
for (var i in mixins) {
|
||||
var keys = Object.keys(mixins[i]);
|
||||
for (var j in keys) {
|
||||
var prop = keys[j];
|
||||
Mixed.prototype[prop] = mixins[i][prop];
|
||||
}
|
||||
}
|
||||
|
||||
mixins.forEach(object => {
|
||||
Object.assign(Mixed.prototype, object);
|
||||
});
|
||||
|
||||
return Mixed;
|
||||
}
|
||||
|
Reference in New Issue
Block a user