Releases: yaohaixiao/outline.js
Releases · yaohaixiao/outline.js
3.21.0
3.20.1
3.20.0
3.19.1
3.19.0
3.18.1
3.18.0
Features
- 优化 _getChaptersWithCode() 方法中的生成章节索引 code 的算法,性能大幅提升; (22f151f)
import isArray from './utils/types/isArray'
const _getChaptersWithCode = (chapters) => {
const groups = {}
const cb = (o) => {
return [o.pid]
}
chapters.forEach((o) => {
const group = JSON.stringify(cb(o))
groups[group] = groups[group] || []
groups[group].push(o)
o.index = groups[group].length
if (o.pid === -1) {
o.code = String(o.index)
}
})
Object.keys(groups).forEach((group) => {
groups[group].forEach((c) => {
// 旧算法:const subjects = chapters.filter((b) => b.pid === c.id)
// 新的算法直接访问 map 属性,速度要快很多,时间复杂度从 N * N, 降低到了 N
const subjects = groups[`[${c.id}]`]
if (!subjects || !isArray(subjects)) {
return false
}
subjects.forEach((o) => {
o.code = c.code + '.' + o.index
})
})
})
return chapters
}
export default _getChaptersWithCode