|
14 | 14 | 然而,在未激活 glass-easel 组件框架时,或在旧版本的小程序基础库中, Chaining API 不被支持。这个 polyfill 可以在这些时候补上 Chaining API 支持。
|
15 | 15 |
|
16 | 16 |
|
17 |
| -## 这个 Polyfill 对 Chaining API 的支持度 |
18 |
| - |
19 |
| -这个 Polyfill 支持提供绝大多数 Chaining API 系列接口。 |
20 |
| - |
21 |
| -但受限于旧版小程序框架,仍有少量接口无法支持,主要包括: |
22 |
| - |
23 |
| -* `.data(...)` 中不能使用函数形式,只能使用对象形式。 |
24 |
| -* `.init(ctx)` 中不支持 `ctx.relation` 。 |
25 |
| - |
26 |
| -最好在 TypeScript 下使用这个模块。(这样可以准确知道可用的接口。) |
27 |
| - |
28 |
| - |
29 | 17 | ## 基础用法
|
30 | 18 |
|
31 | 19 | 首先在 npm 中引入:
|
@@ -56,6 +44,83 @@ import { Behavior } from 'miniprogram-chaining-api-polyfill'
|
56 | 44 | ```
|
57 | 45 |
|
58 | 46 |
|
| 47 | +## 这个 Polyfill 对 Chaining API 的支持度 |
| 48 | + |
| 49 | +这个 Polyfill 支持提供绝大多数 Chaining API 系列接口。但受限于旧版小程序框架,仍有少量接口无法支持。 |
| 50 | + |
| 51 | +以下是不支持的接口列表及相应的修改建议。 |
| 52 | + |
| 53 | +### 不支持 `.data(...)` |
| 54 | + |
| 55 | +使用 `.staticData(...)` 代替,例如: |
| 56 | + |
| 57 | +```ts |
| 58 | +Comopnent() |
| 59 | + .data(() => ({ hello: 'world' })) // 不支持 |
| 60 | + .register() |
| 61 | +``` |
| 62 | + |
| 63 | +改为: |
| 64 | + |
| 65 | +```ts |
| 66 | +Component() |
| 67 | + .staticData({ hello: 'world' }) |
| 68 | + .register() |
| 69 | +``` |
| 70 | + |
| 71 | +### `.init(...)` 中的 `observer` 需要在外部有相应定义 |
| 72 | + |
| 73 | +`.init(...)` 中不直接支持 `observer` 。如需使用,需要在链式调用上预留一个空函数。例如: |
| 74 | + |
| 75 | +```ts |
| 76 | +Comopnent() |
| 77 | + .init(({ observer }) => { |
| 78 | + observer('hello', () => { // 不支持 |
| 79 | + // do something |
| 80 | + }) |
| 81 | + }) |
| 82 | + .register() |
| 83 | +``` |
| 84 | + |
| 85 | +改为: |
| 86 | + |
| 87 | +```ts |
| 88 | +Comopnent() |
| 89 | + .observer('hello', () => {}) // 预留一个空函数作为定义 |
| 90 | + .init(({ observer }) => { |
| 91 | + observer('hello', () => { |
| 92 | + // do something |
| 93 | + }) |
| 94 | + }) |
| 95 | + .register() |
| 96 | +``` |
| 97 | + |
| 98 | +### `.init(...)` 中不支持 `relation` |
| 99 | + |
| 100 | +`.init(...)` 中不能使用 `relation` 。如需使用,需要写在链式调用上。例如: |
| 101 | + |
| 102 | +```ts |
| 103 | +Component() |
| 104 | + .init(({ relation }) => { |
| 105 | + relation('another', { type: 'parent' }) // 不支持 |
| 106 | + }) |
| 107 | + .register() |
| 108 | +``` |
| 109 | + |
| 110 | +改为: |
| 111 | + |
| 112 | +```ts |
| 113 | +Component() |
| 114 | + .relation('another', { type: 'parent' }) |
| 115 | + .register() |
| 116 | +``` |
| 117 | + |
| 118 | +### 其他不支持的细节 |
| 119 | + |
| 120 | +* 链式调用上的 `lifetime` `pageLifetime` `observer` 不支持设置 `once` 参数。 |
| 121 | +* 不支持 `.chainingFilter(...)` 。 |
| 122 | + |
| 123 | + |
59 | 124 | ## LICENSE
|
60 | 125 |
|
61 | 126 | MIT
|
0 commit comments