1 Star 0 Fork 34

/outline.js

forked from Yaohaixiao/outline.js 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
base.js 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
import isString from './utils/types/isString'
import hasOwn from './utils/lang/hasOwn'
import isObject from './utils/types/isObject'
import extend from './utils/lang/extend'
import publish from './utils/observer/emit'
import subscribe from './utils/observer/on'
import unsubscribe from './utils/observer/off'
class Base {
constructor(options) {
this.attrs = {}
if (options) {
this.initialize(options)
}
}
initialize(options) {
this.attr(options).render().addListeners()
return this
}
attr(prop, value) {
const attrs = this.attrs
if (isString(prop)) {
// 只能扩展 attrs 中已有的属性
if (value && hasOwn(attrs, prop)) {
// 更新单个配置信息
attrs[prop] = value
return this
}
// 只传递 prop 参数,则返回对应的属性值
return attrs[prop]
} else if (isObject(prop)) {
// 批量更新配置信息
extend(attrs, prop)
return this
} else if (arguments.length === 0) {
// 不传递参数,直接返回整个
return attrs
}
return this
}
render() {
return this
}
destroy() {
this.removeListeners()
return this
}
reload(options) {
this.destroy().initialize(this.attr(options))
return this
}
$emit(event, data) {
publish(event, data)
return this
}
$on(event, callback) {
subscribe(event, callback, this)
return this
}
$off(event, callback) {
unsubscribe(event, callback)
return this
}
addListeners() {
return this
}
removeListeners() {
return this
}
}
export default Base
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/qdplatform/outline.js.git
[email protected]:qdplatform/outline.js.git
qdplatform
outline.js
outline.js
master

搜索帮助