Created
December 9, 2016 15:08
-
-
Save synzhang/0c7ec077d3fbfd79da96856b5e0e81d3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Component { | |
static utils = { | |
log() { | |
} | |
} | |
static DEFAULTS = { | |
} | |
static Extension = { | |
constructor: function () {}, | |
base: undefined, | |
name: undefined, | |
} | |
constructor(element, options) { | |
this.element = element; | |
this.options = options; | |
this | |
.initElement() | |
.attachHandlers() | |
.initExtensions(); | |
return this; | |
} | |
initElement() { | |
return this; | |
} | |
attachHandlers() { | |
return this; | |
} | |
initExtensions() { | |
this.extensions = []; | |
// this.extensions.push(this.initExtension(new BuiltInExtension(options), name)); | |
this.options.extensions.keys(name => this.extensions.push(this.initExtension(this.options.extensions[name], name))); | |
return this; | |
} | |
initExtension(extension, name) { | |
extension.base = this; | |
extension.name = name; | |
return extension; | |
} | |
destroy() { | |
return this; | |
} | |
render() { | |
return this; | |
} | |
reset() { | |
return this; | |
} | |
} | |
function ComponentFactory(elements, option) { | |
elements.forEach((element, index) => { | |
let component = element.component; | |
if (!component) { | |
let options = Object.assign({}, Component.DEFAULTS, element.dataset, option); | |
element.component = new Component(element, options); | |
} | |
}); | |
} | |
class BuiltInExtension extends Component.Extension { | |
constructor(options) { | |
super(options); | |
return this; | |
} | |
} | |
class Extension extends Component.Extension { | |
constructor(options) { | |
super(options); | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment