Live Note

Remain optimistic

想起来了就写一点…

  • 不在均线向下时做多.
  • 不在均线向上时做空.
  • 不要觉得你比指标厉害,你只是一个 sb.
  • 及时止损.
  • 做交易就像钓鱼,你需要做的是等一个机会钓一条大鱼,而不是频繁的钓小鱼.

需求概述

在旧项目中,有一个策略页面包含四种策略,分别为:Auto、Spot、Long 和 Short。页面中涉及多种配置(Config),包括公共配置(Common Config)、期货配置(Futures Config)以及仅适用于现货的配置(Spot Only Config)。

旧项目实现方式

旧项目采用 MVC 架构,页面数据全部存储在 Controller 中。四种策略共用同一个 config。在页面中使用 panel 时,整个 Controller 会被直接传入 props。由于 panel 是一个独立的组件,需要进行数据分离,这种实现方式导致策略页面运行非常卡顿。具体问题包括:每个 panel 都复制了一份完整的数据;当数据发生修改时,所有 panel 都会重新渲染(rerender),用户体验极差。

旧项目里面有一个策略页面, 里面假设有四种策略, 分别为: Auto, Spot, Long, Short. 下面有一些 Config, 他们有的是公共 Config, 有的是 Futures Config,还有的是 Spot Only Config.

新项目实现方式

Strategy Page Architecture

  • 配置分离:为四种策略分别设置独立的 config。对于公共配置(Common Config),在更新时会同步更新其他三个 config。(为何不单独设置一个 common config?一方面,四种策略的配置已完全分离,公共配置数量较少时,这种方式是可接受的;另一方面,产品需求变动频繁,单独的公共配置不利于后续扩展。)
  • Panel 交互优化:panel 组件通过 onChange 回调管理当前页面的数据变动,而 visible 状态则由 Global Store 统一管理,因为这部分与页面无关。
Read more »

整理图片

摄影图片太多了, 需要整理.
之前用的腾讯云oss, 但是需要流量费, 好兄弟推荐了cloudflare, 免费而且速度快.

而且可以 CDN 加速, 非常适合我.

所以把图片都迁移到了 CF, 并新启了一个相册用于放图片

ablum

r2-image-bucket

有物混成,先天地生,渊呵寥呵,独立而不改,可以为天地母。吾未知其名,字之曰道,强为之名曰大。大曰逝,逝曰远,远曰反。道大,天大,地大,王亦大。国中有四大,而王居一焉。人法地,地法天,天法道,道法自然。

每个人都有自己的道

总有人问:师傅, 到底什么是道?修行的终点是什么?

我问过道友,有的说,为了包吃包住;有的说,为了脱离世俗;还有的,也没想好为什么就来了,来了之后,又走了.

在我看来,每个人有每个人的道,也许你已经知道自己想要什么了;也许你还在途中;也许,你终其一生也无法知道自己想要什么.

所以终点是什么呢?自在心中,你觉得到了,那就是了.
我们能做的,也只是保持前行,积善为德,以德入道.

达则兼济天下,穷则独善其身

主播为了流量,拍献爱心的视频,如果真的献了爱心,我倒是觉得挺好的.
只是观众不买账:”你不就是为了赚钱吗?虚伪的家伙”.

乍一听,有点道理.仔细琢磨,处处不对.

  • 献爱心了吗?献了
  • 主播获利了吗?是的
  • 厂家获利了吗(如果有的话)?是的
  • 观众获利了吗?从某种角度来说,是的

观众角度呢?

  • 献爱心了吗?没有
  • 抨击了吗?少部分有
  • 购买了厂家的物品吗?大部分没有
  • 损失了吗?没有

这么一看,观众反倒是那个光站在道德的制高点上,不做任何事情的群体.

但是,观众是错的吗?我觉得也不是

  • 穷则独善其身,如果一个人穷,他也会做一些善事,只是他做的善事,不会给他带来太多的收益,所以他会选择独善其身.,
  • 达则兼济天下,如果一个人有钱,他也会做一些善事,只是他做的善事,会给他带来很多的收益,所以他会选择兼济天下.

没有做善事,反倒去抨击做了善事的人,这是无法理解的.

当然,乌合之众罢了,他们无法判断自己做的事情是否正确,只是随着大家做而已.

也有反驳:”我就见过有人无私奉献,自己穷得叮当响还要去做善事的”

当然,当然,个人有个人的道嘛.他们在我眼里就是大师,我无法做到,我尊敬他们.

也有一部分奉着好人有好报的原则去做善事的,我不觉得这是错误的,但是我不会去做.

杀人放火金腰带,修桥补路无尸骸

善有善报恶有恶报,不是不报时候未到

大家耳熟能详了,但是,佛说了这种报应会在同一个人身上吗?

在佛教中,因果也被称为缘起.一切现象都不是孤立的,而是由之前的因果关系所引起的.

诸行无常,诸法无我,一切有为法,皆从因缘生.
以因故果,以业故报.
此有故彼有,此生故彼生.

那,真的善有善报,恶有恶报吗?

是的,有的,不过在我看来,不一定会降临到这一世(佛教的轮回说),我甚至觉得,不会降临到同一个人身上.

你遭的报应,可能是你自己造成的,也可能是别人造成的.
同理,你做的恶,可能不会伤害到你自己,反而伤害到别人.

这么看来,因果约束没了,因为报应是随机的.

那大家直接去作恶不就好了?当个坏人,这世爽了就够了,死后哪管他洪水滔天.

所以,需要道德法律来约束了.

既然因果轮回,那我就不制造因果,不介入他人的因果.如果必要的话,不作恶.
这样,恶报就不会降临到自己或者别人身上.

这也是我的处世之道:

  • 别人的事,关我屁事
  • 我的事,关你屁事

你是大级别的人物,在我看来也就是个普通人.
三清都只是我的师兄,你算老几?

所以,道是什么?

我也不知道,我只能感觉得到它.
它就有点像古兰经里的阿拉,区别是阿拉是有灵性的,而道是无灵性的.

它让我时刻记住,什么能做什么不能做,修德,修道,修行.

旧 React 简易实现

react-old.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import { updateDomProperties } from "./dom-utils.js"

// 根实例
let rootInstance = null
const TEXT_ELEMENT = "TEXT_ELEMENT"

// 创建 VDOM 元素
function createElement(type, config, ...args) {
const props = Object.assign({}, config)
const hasChildren = args.length > 0
const rawChildren = hasChildren ? [].concat(...args) : []

props.children = rawChildren
.filter((c) => c !== null && c !== false)
.map((c) => (c instanceof Object ? c : createTextElement(c)))

return { type, props }
}

function createTextElement(text) {
return createElement(TEXT_ELEMENT, { nodeValue: text })
}

function render(element, container) {
const prevInstance = rootInstance
const nextInstance = reconcile(container, prevInstance, element)
rootInstance = nextInstance
}

// 递归更新子元素
function reconcile(parentDom, instance, element) {
if (instance === null) {
// 创建新实例
const newInstance = instantiate(element)
parentDom.appendChild(newInstance.dom)
return newInstance
} else if (element === null) {
// 删除实例
parentDom.removeChild(instance.dom)
return null
} else if (instance.element.type !== element.type) {
// 如果类型不同,则替换实例
const newInstance = instantiate(element)
// 替换实例
parentDom.replaceChild(newInstance.dom, instance.dom)
return newInstance
} else if (typeof element.type === "string") {
// 更新 DOM 实例
updateDomProperties(instance.dom, instance.element.props, element.props)

// 更新 instance
instance.childInstances = reconcilerChildren(instance, element)
instance.element = element

return instance
} else {
// 更新组件实例
instance.publicInstance.props = element.props
const childElement = instance.publicInstance.render()
const oldChildInstance = instance.childInstance
const childInstance = reconcile(parentDom, oldChildInstance, childElement)

instance.dom = childInstance.dom
instance.childInstance = childInstance
instance.element = element

return instance
}
}

function reconcilerChildren(instance, element) {
const dom = instance.dom
const childInstances = instance.childInstances
const nextChildElements = element.props.children || []
const newChildInstances = []

const count = Math.max(childInstances.length, nextChildElements.length)

// 本 demo, 顺序不同也算作更新

for (let i = 0; i < count; i++) {
const childInstance = childInstances[i]
const childElement = nextChildElements[i]

const newChildInstance = reconcile(dom, childInstance, childElement)

newChildInstances.push(newChildInstance)
}

return newChildInstances.filter((instance) => instance !== null)
}

// 把元素实例化成真实的DOM节点
function instantiate(element) {
const { type, props } = element
const isDomElement = typeof type === "string"

if (isDomElement) {
// 创建 DOM 元素
const isTextElement = type === TEXT_ELEMENT
const dom = isTextElement
? document.createTextNode("")
: document.createElement(type)

// 更新 dom
updateDomProperties(dom, [], props)

// 实例化子元素
const childElements = props.children || []
const childInstances = childElements.map(instantiate)
const childDoms = childInstances.map((childInstance) => childInstance.dom)
childDoms.forEach((childDom) => dom.appendChild(childDom))

const instance = { dom, element, childInstances }

return instance
} else {
// 初始化组件
const instance = {}
const publicInstance = createPublicInstance(element, instance)
const childElement = publicInstance.render() // 拿到 vdom
const childInstance = instantiate(childElement) // 实例化
const dom = childInstance.dom

Object.assign(instance, { dom, element, publicInstance, childInstance })

return instance
}
}

function createPublicInstance(element, internalInstance) {
const { type, props } = element

// type 此时是一个 Class
const publicInstance = new type(props)

publicInstance.__internalInstance = internalInstance

return publicInstance
}

function updateInstance(internalInstance) {
const parentDom = internalInstance.dom.parentNode
const element = internalInstance.element

reconcile(parentDom, internalInstance, element)
}

class Component {
constructor(props) {
this.props = props
this.state = this.state || {}
}

setState(partialState) {
this.state = Object.assign({}, this.state, partialState)
updateInstance(this.__internalInstance)
}

// render 出来的也是 VDOM
render() {}
}

export default { render, createElement, Component }
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
<style>
.container {
width: 200px; /* 固定宽度,触发溢出 */
overflow: hidden; /* 隐藏溢出内容 */
white-space: nowrap; /* 禁止换行 */
}

.text {
display: inline-block;
width: 100%; /* 占满容器 */
direction: rtl; /* 文本方向从右到左 */
text-overflow: ellipsis; /* 显示省略号 */
overflow: hidden;
text-align: left; /* 强制左对齐,保持视觉上的正常阅读方向 */
}
</style>
<div class="container">
<span class="text">短文本不会被省略</span>
</div>

<div class="container">
<span class="text">这是一段很长的文本,左侧会被省略</span>
</div>

在 TypeScript 的类型系统中,逆变(Contravariance)协变(Covariance)双变(Bivariance)不变(Invariance) 是描述类型兼容性和子类型关系的重要概念。这些术语来源于类型理论,主要用于处理函数类型、泛型和接口的赋值规则。理解这些概念不仅能帮助我们编写更安全的代码,还能让我们更好地设计类型系统。本文将逐一讲解这四种变型,辅以代码示例,让你轻松掌握它们的含义与应用。

Read more »

AJAX:实现原理与技术背景

在现代 Web 开发中,AJAX(Asynchronous JavaScript and XML,异步 JavaScript 和 XML)是一种不可或缺的技术。它通过异步通信实现了网页的无刷新更新,极大地提升了用户体验。那么,AJAX 是如何实现的?它的出现又有着怎样的背景?

从静态到动态的 Web 进化

Web 1.0 的局限性

在互联网早期,网页主要依赖同步请求模型。当用户点击链接或提交表单时,浏览器会向服务器发送请求,然后等待服务器返回全新的 HTML 页面。这一过程会导致整个页面刷新,用户不得不面对短暂的空白和等待。对于简单的静态网站,这种模式尚可接受,但随着 Web 应用复杂性的增加,例如实时聊天、动态表单验证等需求,这种方式的弊端愈发明显——用户体验差、交互效率低。

动态 Web 的需求

进入 21 世纪,互联网用户对 Web 应用的要求日益提高。人们希望网页能像桌面应用程序一样,提供流畅的交互和实时更新。例如,在输入搜索关键词时实时显示建议,或在聊天应用中即时刷新消息。这些需求推动了 Web 技术向动态化、异步化的方向发展。

技术基础的成熟

AJAX 并非凭空出现,它建立在一系列已有技术之上:

  • JavaScript:作为客户端脚本语言,负责处理用户交互和动态更新页面内容。
  • XMLHttpRequest(XHR):浏览器内置对象,允许在后台与服务器通信。
  • DOM(文档对象模型):提供操作页面结构的接口,使数据能够无缝嵌入。
  • XML:最初用于数据交换(后来 JSON 逐渐取而代之)。

这些技术的成熟为 AJAX 的诞生奠定了基础。尤其是 XMLHttpRequest,最早由微软在 Internet Explorer 5 中引入,随后被其他浏览器标准化,成为 AJAX 的核心组件。

Read more »

在 TypeScript 的类型系统中,Top Type(顶层类型)Bottom Type(底层类型) 是两个非常重要的概念。它们分别代表了类型范围的“最顶层”和“最底层”,理解它们对于掌握 TypeScript 的类型系统至关重要。

Read more »

Subtype Polymorphism

通过类继承和方法重写,子类可以提供与父类方法相同的接口,但实现不同的行为。

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
class Animal {
makeSound(): void {
console.log("Some generic animal sound")
}
}

class Dog extends Animal {
makeSound(): void {
console.log("Woof!")
}
}

class Cat extends Animal {
makeSound(): void {
console.log("Meow!")
}
}

function makeAnimalSound(animal: Animal): void {
animal.makeSound()
}

const dog = new Dog()
const cat = new Cat()

makeAnimalSound(dog) // Woof!
makeAnimalSound(cat) // Meow!

key points:

  • 类型兼容性:TypeScript 的类型系统允许子类实例赋值给父类类型的变量(向上转型)。
  • 运行时行为:实际执行的方法取决于对象的运行时类型,而不是声明时的类型。
Read more »