Live Note

Remain optimistic

  • before: abcd
  • after: acdb

===第一轮遍历开始===

a(之后)vs a(之前)
key 不变,可复用
此时 a 对应的 oldFiber(之前的 a)在之前的数组(abcd)中索引为 0
所以 lastPlacedIndex = 0;

继续第一轮遍历…

c(之后)vs b(之前)
key 改变,不能复用,跳出第一轮遍历
此时 lastPlacedIndex === 0;
===第一轮遍历结束===

===第二轮遍历开始===
newChildren === cdb,没用完,不需要执行删除旧节点
oldFiber === bcd,没用完,不需要执行插入新节点

将剩余 oldFiber(bcd)保存为 map

// 当前 oldFiber:bcd
// 当前 newChildren:cdb

继续遍历剩余 newChildren

key === c 在 oldFiber 中存在
const oldIndex = c(之前).index;
此时 oldIndex === 2; // 之前节点为 abcd,所以 c.index === 2
比较 oldIndex 与 lastPlacedIndex;

如果 oldIndex >= lastPlacedIndex 代表该可复用节点不需要移动
并将 lastPlacedIndex = oldIndex;
如果 oldIndex < lastplacedIndex 该可复用节点之前插入的位置索引小于这次更新需要插入的位置索引,代表该节点需要向右移动

在例子中,oldIndex 2 > lastPlacedIndex 0
lastPlacedIndex = 2;
c 节点位置不变

继续遍历剩余 newChildren

// 当前 oldFiber:bd
// 当前 newChildren:db

key === d 在 oldFiber 中存在
const oldIndex = d(之前).index;
oldIndex 3 > lastPlacedIndex 2 // 之前节点为 abcd,所以 d.index === 3
lastPlacedIndex = 3;
d 节点位置不变

继续遍历剩余 newChildren

// 当前 oldFiber:b
// 当前 newChildren:b

key === b 在 oldFiber 中存在
const oldIndex = b(之前).index;
oldIndex 1 < lastPlacedIndex 3 // 之前节点为 abcd,所以 b.index === 1
则 b 节点需要向右移动
===第二轮遍历结束===

最终 acd 3 个节点都没有移动,b 节点被标记为移动

警方虚拟币法律知识的更新

继沿海几座大城市的网警朋友积极学习区块链技术(存证等方面)和相关法律知识之后,内陆的经济警察也开始相关法律知识的更新。

我们发现,浙江某市的区块链内部研讨会议和技术复盘会议中,也出现了警察叔叔参与讨论,而且其对技术本身的研究颇深,出乎大家意料。这与两年前在人民大学与公检法朋友们沟通时的情况(彼时他们对区块链的陌生)形成了鲜明的对比。

这充分说明,已经有案子出现了,并且呈现一定活跃态势,司法机关严阵以待,提前用相关法律知识武装自己,以便更好地适应或许会出现的涉币案件潮。

反观链圈,几乎每一个区块链项目方都有“发币”的冲动,虽然我们理解“激励机制”对项目自身的作用,然而,一旦发币 ICO,在我国现有法律框架下会被定性为“非法的公开融资行为”,涉嫌非法集资类犯罪或非法经营罪等。

Read more »

原型模式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
let LoopImages = function (imageArr, container) {
this.imageArr = imageArr
this.container = container
}
LoopImages.prototype = {
createImage: function () {
console.log("create image")
},
changeImage: function () {
console.log("change image")
},
}

let SlideLoopImg = function (imageArr, container) {
LoopImages.call(this, imageArr, container)
}
SlideLoopImg.prototype = new LoopImages() // 继承
SlideLoopImg.prototype.changeImage = () => {
// 重写
console.log("slide loop change image")
}

// for test
let slideImage = new SlideLoopImg(["1.jpg", "2.jpg"], "slide")
console.log(slideImage.container)
slideImage.changeImage()

原型继承

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* copy object
*/
function prototypeExtend() {
let F = function () {}
// let F = new Function()

for (let i = 0; i < arguments.length; i++) {
for (let j in arguments[i]) {
F.prototype[j] = arguments[i][j]
}
}

return new F()
}

// for test
let car = prototypeExtend(
{
speed: 20,
fast: function () {
this.speed++
console.log("is faster")
},
},
{
slow: function () {
this.speed--
console.log("is slower")
},
},
{
stop: function () {
this.speed = 0
console.log("is stop")
},
},
{
currentSpeed: function () {
console.log(this.speed)
},
}
)

car.fast()
car.fast()
car.fast()
car.fast()

car.currentSpeed()
car.stop()

car.currentSpeed()

邻接表

存储方式:表头存放节点,相邻节点存放于之后的链表中。
** 使用 Map 模拟 **

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Graph {
constructor() {
this.point = []
this.map = new Map()
}

addPoint(point) {
this.point.push(point)
this.map.set(point, [])
}

// 无向
addEdge(pointA, pointB) {
this.map.get(pointA).push(pointB)
this.map.get(pointB).push(pointA)
}

print() {
for (let item of this.point) {
console.log(item + " -> " + this.map.get(item).join(","))
}
}
}

Test

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var graph = new Graph()
var topArr = ["A", "B", "C", "D", "E", "F", "G", "H", "I"]
for (let item of topArr) {
graph.addPoint(item)
}

graph.addEdge("A", "B")
graph.addEdge("A", "D")
graph.addEdge("A", "E")
graph.addEdge("A", "H")
graph.addEdge("F", "G")
graph.addEdge("I", "B")
graph.addEdge("I", "C")

graph.print()

教育部关于同意复旦大学章程部分条款修改的批复 教政法函〔2019〕18 号

重点修改如下:

序言第一段

“国人自主创办”改为“中国人自主创办”。

序言第二段

删去“学校的办学理念是其校歌所传颂的……思想自由……强调以学术精神滋养师生,坚守价值,治学严谨,为学有恒。学校始终秉持团结、服务与牺牲的精神,强调学校、师生的社会责任和国家使命。”增加“敦行爱国奉献……海纳百川、追求卓越。学校倡导‘文明、健康、团结、奋发’的校风和‘刻苦、严谨、求实、创新’的学风,强调坚持理想、探究真理、正谊明道、守护文明。”

Read more »