lens over ts #1

本篇文章首 lens over tea https://web.archive.org/web/20210521023726/https://artyom.me/lens-over-tea-1第一篇文章的启发,可以看作它的私人意译版本,关注点在与尝试用 ts 来取代原文中的 hs 语言,使得 ts 开发者能在更熟悉的语言环境中领悟原文中的精髓。

第一次尝试

文章开始,让我们从 lens 的基础语义出发,即 get 与 set。现在,我们先假设存在这样的一个需求,我们需要定义一组方法,用来向某个数组的第 i 个位置赋值和取值,需求很简单,很快,我们实现了第一版:

tsx
...
type Func<P, R = P> = (v: P) => R;
type Lens1<T> = {
get: (source: T[]) => T;
set: (nVal: T) => (source: T[]) => T[];
};

const lens1 = <T = any>(i: number) => {
const get = (a: T[]) => a[i];
const set = (nVal: T) => (source: T[]) => {
const newArr = [...source];
newArr[i] = nVal;
return newArr;
};

return {
get,
set,
} as Lens1<T>;
};

const view1 = <T>(l: Lens1<T>, source: T[]) => l.get(source);
const over1 = <T>(l: Lens1<T>, f: Func<T>, source: T[]) =>
l.set(f(l.get(source)))(source);
业务表格快查

实体属性

使用cascade function来编写

例如:

jsx
...
const item = parse(
objectCol({
name: text.label('项目名称').required(true).initialValue('测试项目名称'),
number: text.label('编号').required(true),
construct_unit: text
.label('招标人')
.required(true)
.initialValue('测试招标人'),
deposit: number.label('保证金(万元)').required(true).initialValue(25),
price: number.label('保费').required(true).initialValue(40.0),
region: objectCol({
id: select.label('所属地区').props({
request: async () => {
return [];
},
}),
}),
calendar_days: number.label('投标有效期').required(true),
weigh: number.label('权重').required(true),
status: enumType
.label('状态')
.valueEnum([
{
label: '招标中',
value: 1,
},
{
label: '招标完成',
value: 2,
},
{
label: '异常终止',
value: 3,
},
{
label: '维护中 ',
value: 4,
},
{
label: '待审核',
value: 5,
},
])
.required(true),
evaluation_method: text.label('评估方法').required(true).tableShow(false),
max_money: text.label('最高限价').required(true).tableShow(false),
require: text.label('招标需求').required(true).tableShow(false),
end_time: dateTime
.label('结束时间')
.required(true)
.tableShow(false)
.initialValue(Date.now()),
validity_start_time: dateTime
.label('开标时间')
.tableShow(false)
.required(true)
.initialValue(Date.now())
.props({ autoFocus: true }),
}),
);
资源权限模型示例

会议主要内容

整个系统所涉及的主要资源有

模版资源

会员单位资源

项目资源

保函订单资源

整个系统所涉及的员工角色

总公司与分公司

内勤人员

业务员与会员单位(这部分并不需要账户登录系统)

Monoid与快速幂

适用场景

主要适用于快速计算一个 monoid 对象的多次 concat 运算后的结果。核心点在于减少 concat 的调用次数。时间复杂度大致上为logN。

monoid 定义伴随着:

tsx
...
declare function makeUnit(): T;
declare function concat(lhs: T, rhs: T): T;

// monoid需要满足,其中a,b,c是T类型的任意值
concat(concat(a, b), c) === concat(a, concat(b, c)); // 交换律
concat(makeUnit(), a) === concat(a, makeUnit()) && concat(makeUnit(), a) === a; // 拥有单位元
blog的deploy模版

CI/CD中可能使用的git命令

1.

获得pr分支相较于主分支所做的变更

搜集commit:

merge非rebase:git log origin/main..HEAD

rebase非merge:git log main..HEAD

curd表格组件的快速编写(1)

通常意义上,我们在编写对应某个资源的管理页面的时候,我们往往会面对一大类功能大致相似的需求,例如:

传统意义上的curd

带筛选条件的查询

更新某个具体的值

对某个具体的值进行更新

与回收站的交互操作

....等等一系列的操作