javascript设计模式篇之工厂设计模式(1)

文章详细描述了Vue组件的初始化方法,包括`_init`和`initLifecycle`,以及elementUI框架中Table组件的数据管理和store的创建。还提到前端开发者如何系统学习和提升技能的重要性。
摘要由CSDN通过智能技术生成

// a uid

vm._uid = uid++

let startTag, endTag

/* istanbul ignore if */

if (process.env.NODE_ENV !== ‘production’ && config.performance && mark) {

startTag = vue-perf-start:${vm._uid}

endTag = vue-perf-end:${vm._uid}

mark(startTag)

}

// a flag to avoid this being observed

vm._isVue = true

// merge options

if (options && options._isComponent) {

// optimize internal component instantiation

// since dynamic options merging is pretty slow, and none of the

// internal component options needs special treatment.

initInternalComponent(vm, options)

} else {

vm.$options = mergeOptions(

resolveConstructorOptions(vm.constructor),

options || {},

vm

)

}

/* istanbul ignore else */

if (process.env.NODE_ENV !== ‘production’) {

initProxy(vm)

} else {

vm._renderProxy = vm

}

// expose real self

vm._self = vm

/* istanbul ignore if */

if (process.env.NODE_ENV !== ‘production’ && config.performance && mark) {

vm._name = formatComponentName(vm, false)

mark(endTag)

measure(vue ${vm._name} init, startTag, endTag)

}

if (vm.$options.el) {

vm. m o u n t ( v m . mount(vm. mount(vm.options.el)

}

}

}

initMixin方法通过prototype挂载了_init初始化方法。

export function initLifecycle (vm: Component) {

const options = vm.$options

// locate first non-abstract parent

let parent = options.parent

if (parent && !options.abstract) {

while (parent.KaTeX parse error: Expected 'EOF', got '&' at position 18: …tions.abstract &̲& parent.parent) {

parent = parent.$parent

}

parent.$children.push(vm)

}

vm.$parent = parent

vm. r o o t = p a r e n t ? p a r e n t . root = parent ? parent. root=parent?parent.root : vm

vm.$children = []

vm.$refs = {}

vm._watcher = null

vm._inactive = null

vm._directInactive = false

vm._isMounted = false

vm._isDestroyed = false

vm._isBeingDestroyed = false

}

initLifecycle为vue挂载了很多共有的属性对象。

2.elementUI框架实例


以解析table组件为例,packages/table/src/table.vue

data() {

const { hasChildren = ‘hasChildren’, children = ‘children’ } = this.treeProps;

this.store = createStore(this, {

rowKey: this.rowKey,

defaultExpandAll: this.defaultExpandAll,

selectOnIndeterminate: this.selectOnIndeterminate,

// TreeTable 的相关配置

indent: this.indent,

lazy: this.lazy,

lazyColumnIdentifier: hasChildren,

childrenColumnName: children

});

const layout = new TableLayout({

store: this.store,

table: this,

fit: this.fit,

showHeader: this.showHeader

});

return {

layout,

isHidden: false,

renderExpanded: null,

resizeProxyVisible: false,

resizeState: {

width: null,

height: null

},

// 是否拥有多级表头

isGroup: false,

scrollPosition: ‘left’

};

}

this.store = createStore(this, {})是通过函数方式创建实例element/packages/table/src/store/helper.js

export function createStore(table, initialState = {}) {

if (!table) {

throw new Error(‘Table is required.’);

}

const store = new Store();

store.table = table;

// fix https://github.com/ElemeFE/element/issues/14075

// related pr https://github.com/ElemeFE/element/pull/14146

store.toggleAllSelection = debounce(10, store._toggleAllSelection);

Object.keys(initialState).forEach(key => {

store.states[key] = initialState[key];

});

return store;

}

const layout = new TableLayout({});通过es6类的用法来创建实例,及其拥有的方法updateScrollY

小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Web前端开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频

如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注:前端)
img

总结

前端资料汇总

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

  • 框架原理真的深入某一部分具体的代码和实现方式时,要多注意到细节,不要只能写出一个框架。

  • 算法方面很薄弱的,最好多刷一刷,不然影响你的工资和成功率😯

  • 在投递简历之前,最好通过各种渠道找到公司内部的人,先提前了解业务,也可以帮助后期优秀 offer 的决策。

  • 要勇于说不,对于某些 offer 待遇不满意、业务不喜欢,应该相信自己,不要因为当下没有更好的 offer 而投降,一份工作短则一年长则 N 年,为了幸福生活要慎重选择!!!
    喜欢这篇文章文章的小伙伴们点赞+转发支持,你们的支持是我最大的动力!
    onvert/6e0ba223f65e063db5b1b4b6aa26129a.png)

  • 框架原理真的深入某一部分具体的代码和实现方式时,要多注意到细节,不要只能写出一个框架。

  • 算法方面很薄弱的,最好多刷一刷,不然影响你的工资和成功率😯

  • 在投递简历之前,最好通过各种渠道找到公司内部的人,先提前了解业务,也可以帮助后期优秀 offer 的决策。

  • 要勇于说不,对于某些 offer 待遇不满意、业务不喜欢,应该相信自己,不要因为当下没有更好的 offer 而投降,一份工作短则一年长则 N 年,为了幸福生活要慎重选择!!!
    喜欢这篇文章文章的小伙伴们点赞+转发支持,你们的支持是我最大的动力!

  • 14
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值