Skip to content

Commit a8f76d7

Browse files
authored
Merge pull request #98 from wechat-miniprogram/feat-glass-easel
Add support for glass-easel
2 parents dc2d5b3 + b66127d commit a8f76d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+16415
-27922
lines changed

.eslintrc.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,40 @@ module.exports = {
22
root: true,
33
parser: '@typescript-eslint/parser',
44
parserOptions: {
5-
ecmaVersion: 6,
5+
ecmaVersion: 9,
6+
ecmaFeatures: {
7+
jsx: false,
8+
},
69
sourceType: 'module',
710
},
811
env: {
912
es6: true,
10-
browser: true,
13+
node: true,
1114
jest: true,
1215
commonjs: true,
13-
node: true,
1416
},
15-
plugins: ['@typescript-eslint'],
16-
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
1717
globals: {
18-
wx: true,
18+
window: true,
19+
document: true,
1920
App: true,
2021
Page: true,
2122
Component: true,
2223
Behavior: true,
24+
wx: true,
2325
},
26+
plugins: ['@typescript-eslint', 'prettier'],
27+
extends: [
28+
'eslint:recommended',
29+
'plugin:@typescript-eslint/eslint-recommended',
30+
'plugin:@typescript-eslint/recommended',
31+
'prettier/@typescript-eslint',
32+
],
2433
rules: {
25-
'no-console': 0,
34+
'prettier/prettier': 'error',
2635
'@typescript-eslint/ban-ts-ignore': 'off',
2736
'@typescript-eslint/no-empty-function': 'off',
2837
'@typescript-eslint/explicit-function-return-type': 'off',
2938
'@typescript-eslint/no-explicit-any': 'off',
3039
'@typescript-eslint/no-non-null-assertion': 'off',
31-
indent: ['error', 2, { SwitchCase: 1 }],
32-
'comma-spacing': 'error',
33-
semi: ['error', 'never'],
34-
quotes: ['error', 'single'],
35-
'object-curly-spacing': ['error', 'always'],
36-
'@typescript-eslint/ban-ts-comment': 'off',
37-
"@typescript-eslint/interface-name-prefix": 'off'
3840
},
3941
}

.github/workflows/node.js.yml

+12-13
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,26 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: [ "master" ]
8+
branches: ['master']
99
pull_request:
10-
branches: [ "master" ]
10+
branches: ['master']
1111

1212
jobs:
1313
build:
14-
1514
runs-on: ubuntu-latest
1615

1716
strategy:
1817
matrix:
19-
node-version: [12.x, 14.x, 16.x]
18+
node-version: [16.x, 20.x]
2019
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2120

2221
steps:
23-
- uses: actions/checkout@v3
24-
- name: Use Node.js ${{ matrix.node-version }}
25-
uses: actions/setup-node@v3
26-
with:
27-
node-version: ${{ matrix.node-version }}
28-
cache: 'npm'
29-
- run: npm i
30-
- run: npm run build --if-present
31-
- run: npm test
22+
- uses: actions/checkout@v3
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
cache: 'npm'
28+
- run: npm i
29+
- run: npm run build --if-present
30+
- run: npm test

.prettierrc.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
printWidth: 100,
3+
tabWidth: 2,
4+
useTabs: false,
5+
semi: false,
6+
singleQuote: true,
7+
quoteProps: 'as-needed',
8+
trailingComma: 'all',
9+
bracketSpacing: true,
10+
arrowParens: 'always',
11+
requirePragma: false,
12+
insertPragma: false,
13+
proseWrap: 'preserve',
14+
endOfLine: 'lf',
15+
embeddedLanguageFormatting: 'auto',
16+
}

.swcrc

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
2-
"jsc": {
3-
"parser": {
4-
"syntax": "typescript",
5-
"tsx": false,
6-
"decorators": false,
7-
"dynamicImport": false
8-
},
9-
"transform": null,
10-
"target": "es5",
11-
"loose": true,
12-
"externalHelpers": false,
13-
"keepClassNames": false,
14-
"minify": {
15-
"compress": {
16-
"unused": true
17-
},
18-
"mangle": true
19-
}
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript",
5+
"tsx": false,
6+
"decorators": false,
7+
"dynamicImport": false
208
},
21-
"minify": true,
22-
"module": {
23-
"type": "commonjs",
24-
"strict": false,
25-
"strictMode": true,
26-
"lazy": false,
27-
"noInterop": false
9+
"transform": null,
10+
"target": "es5",
11+
"loose": true,
12+
"externalHelpers": false,
13+
"keepClassNames": false,
14+
"minify": {
15+
"compress": {
16+
"unused": true
17+
},
18+
"mangle": true
2819
}
29-
}
20+
},
21+
"minify": true,
22+
"module": {
23+
"type": "commonjs",
24+
"strict": false,
25+
"strictMode": true,
26+
"lazy": false,
27+
"noInterop": false
28+
}
29+
}

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 wechat-miniprogram
3+
Copyright (c) 2018-2024 wechat-miniprogram
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+30-44
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
> 此 behavior 依赖开发者工具的 npm 构建。具体详情可查阅[官方 npm 文档](https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html)
66
7-
注意: 4.0.0 大版本变更了最基本的接口名,升级到 4.0.0 以上时请注意 [#60](https://github.com/wechat-miniprogram/computed/issues/60) 的问题。旧版文档可以参考对应版本的 git tag 中的 README ,如 [v3.1.1](https://github.com/wechat-miniprogram/computed/tree/v3.1.1) tag
7+
注意: 4.0.0 大版本变更了最基本的接口名,从低版本升级到 4.0.0 以上时请注意 [#60](https://github.com/wechat-miniprogram/computed/issues/60) 的问题。
88

99
## 使用方法
1010

1111
### 方式一 代码片段
1212

13-
需要小程序基础库版本 >= 2.6.1 的环境。
13+
需要小程序基础库版本 >= 2.11.0 的环境。
1414

1515
可以直接体验一下这个代码片段,它包含了基本用法示例:[https://developers.weixin.qq.com/s/4KYn6TmJ7osP](https://developers.weixin.qq.com/s/4KYn6TmJ7osP)
1616

@@ -120,7 +120,33 @@ Component({
120120
<button bindtap="onTap">click</button>
121121
```
122122

123-
### TypeScript 支持
123+
### glass-easel Chaining API 支持
124+
125+
使用 glass-easel Chaining API 时,可以用更友好的 `computed` `watch` 函数。
126+
127+
```js
128+
import { computed, watch } from 'miniprogram-computed'
129+
130+
Component()
131+
.data(() => ({
132+
a: 1,
133+
b: 2,
134+
}))
135+
.init((ctx) => {
136+
const data = computed(ctx, {
137+
c: (data) => data.a + data.b,
138+
d: (data) => data.a * 2,
139+
}, {
140+
e: (data) => data.c + data.d,
141+
})
142+
watch(ctx, 'a, b', (a: number, b: number) => {
143+
// ...
144+
})
145+
})
146+
.register()
147+
```
148+
149+
### 非 chaining API 的 TypeScript 支持
124150

125151
由于通过 behavior 的方式引入不能获得类型支持, 因此为了获得类型的支持, 可以使用一个辅助组件构造器:
126152

@@ -162,42 +188,6 @@ ComponentWithComputed({
162188

163189
针对此问题,推荐使用 `ComponentWithComputed` 构造器代替 `Component` 构造器。
164190

165-
**关于类型声明**
166-
167-
`4.0.5` 版本之前,并未提供相关的 `.d.ts` 类型声明。
168-
169-
强烈建议将 `miniprogram-computed` npm 包依赖升级至 `^4.0.5` 已获取完整的类型能力。
170-
171-
## ^4.0.0 与 ^1.0.0、 ^2.0.0、 ^3.0.0 版本的差异
172-
173-
### ^4.0.0 版本
174-
175-
- 变更了最基本的接口。
176-
177-
- 新增简单的 TypeScript 支持。
178-
179-
### ^3.0.0 版本
180-
181-
- 支持 mobx-miniprogram 扩展库引入的数据段。
182-
183-
- 对自定义 behavior 数据段使用 computed 时,支持在初始化视图中进行数据渲染。
184-
185-
- 基于 proxy 更新了 computed 数据追踪的实现方式,computed 依赖的数据路径追踪初始化操作,延后到组件的 created 阶段 。
186-
187-
### ^2.0.0 版本
188-
189-
基于小程序基础库 2.6.1 开始支持的 observers 定义段实现,具有较好的性能。
190-
191-
以下是版本之间主要区别的比较。
192-
193-
| 项目 | ^1.0.0 | ^2.0.0 | ^3.0.0 和 ^4.0.0 |
194-
| ----------------------------------------------- | --------------- | ------------- | ---------------- |
195-
| 支持的基础库最低版本 | 2.2.3 | 2.6.1 | 2.6.1 |
196-
| 支持 `watch` 定义段 ||||
197-
| 性能 | 相对较差 | 相对较好 | 相对较好 |
198-
| 支持 `mobx-miniprogram` 扩展库 | 不支持 | 不支持 | 支持 |
199-
| 支持自定义 `behavior` 数据字段 / 初始化视图渲染 | 不支持 / 不支持 | 支持 / 不支持 | 支持 / 支持 |
200-
201191
## 常见问题说明
202192

203193
### 我应该使用 computed 还是 watch ?
@@ -212,7 +202,7 @@ ComponentWithComputed({
212202

213203
### 关于 \*\* 通配符
214204

215-
`watch` 字段上可以使用 `**` 通配符,是它能够监听这个字段下的子字段的变化(类似于小程序基础库本身的 observers )。
205+
`watch` 字段上可以使用 `**` 通配符,它能够监听这个字段下的子字段的变化(类似于小程序基础库本身的 observers )。
216206

217207
```js
218208
const computedBehavior = require('miniprogram-computed').behavior
@@ -246,7 +236,3 @@ Component({
246236

247237
- 对于没有使用 `**` 通配符的字段,在 `watch` 检查值是否发生变化时,只会进行粗略的浅比较(使用 `===` );
248238
- 对于使用了 `**` 通配符的字段,则会进行深比较,来尝试精确检测对象是否真的发生了变化,这要求对象字段不能包含循环(类似于 `JSON.stringify` )。
249-
250-
### 关于低版本兼容
251-
252-
对于 IOS `9.3` 以下的版本,由于无法原生支持 `Proxy`,这里会使用 `proxy-polyfill` 去代替。

UPDATE.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@
2525
- 使用 TypeScript 重构。
2626
- 优化部分生命周期逻辑。
2727

28-
# 4.1.1
28+
## 4.1.1
2929

3030
- 优化打包方式
3131
- 优化 dev 开发流程
3232

33-
# 4.2.x
33+
## 4.2.x
3434

3535
- 增加 polyfill
3636

37-
# 4.3.x
37+
## 4.3.x
3838

3939
- 修复引用类型的部分问题
40+
41+
## 5.0.0
42+
43+
- 基于 glass-easel 重构
44+
- 支持 chaining API

demo/app.js

-3
This file was deleted.

demo/app.json

-10
This file was deleted.

demo/app.wxss

Whitespace-only changes.

demo/computed/behavior.js

-1
This file was deleted.

demo/computed/data-path.js

-1
This file was deleted.

demo/computed/data-tracer.js

-1
This file was deleted.

demo/computed/index.js

-1
This file was deleted.

0 commit comments

Comments
 (0)