@viewfly/core 3.0.0-alpha.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/index.esm.js +8 -7
- package/dist/index.js +8 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @viewfly/core
|
|
2
2
|
|
|
3
|
-
Viewfly
|
|
3
|
+
Viewfly 的**内核包**:函数组件、`JSX`、响应式与 `signal`、`watch`、生命周期、`inject` 与 IoC 相关 API、以及 **`withMark`** 等与 UI 逻辑直接相关的入口均由此包提供。
|
|
4
4
|
|
|
5
5
|
在浏览器里挂载应用请使用 **`@viewfly/platform-browser`** 的 **`createApp`**(其内部使用本包提供的应用模型)。
|
|
6
6
|
|
|
@@ -9,8 +9,7 @@ Viewfly 的**内核包**:函数组件、JSX、响应式与信号、`watch`、
|
|
|
9
9
|
## 安装
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
|
|
13
|
-
# 或 npm / yarn
|
|
12
|
+
npm install @viewfly/core
|
|
14
13
|
```
|
|
15
14
|
|
|
16
15
|
本包依赖 **`reflect-metadata`**。正常从 **`@viewfly/core`** 的主入口导入时,会随模块加载一并初始化;若你的打包拆包方式导致依赖注入相关运行时异常,可在应用入口**最先**增加显式导入:
|
|
@@ -19,7 +18,7 @@ pnpm add @viewfly/core
|
|
|
19
18
|
import 'reflect-metadata'
|
|
20
19
|
```
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
更稳妥的做法以**当前安装版本**随附的类型定义与官方文档(<https://viewfly.org>)为准。
|
|
23
22
|
|
|
24
23
|
---
|
|
25
24
|
|
|
@@ -49,7 +48,7 @@ import 'reflect-metadata'
|
|
|
49
48
|
| 组件 | 函数组件:在 JSX 中当标签使用;配合生命周期钩子使用。 |
|
|
50
49
|
| 生命周期 | **`onMounted`**、**`onUpdated`**、**`onUnmounted`** 等(须在组件 setup 阶段调用)。 |
|
|
51
50
|
| 响应式 | **`reactive`**、**`shallowReactive`**、**`watch`** 等(`reactive` 模块)。 |
|
|
52
|
-
|
|
|
51
|
+
| `signal` / 派生 | **`createSignal`**、**`computed`** 等(见 `reactive` 导出;具体符号以类型为准)。 |
|
|
53
52
|
| 依赖注入 | 在组件内用 **`inject`** 解析 token;用 **`Injectable()`** 声明可注入类;用 **`withAnnotation`** 或 **`createContext`** / **`createContextProvider`** 挂载 **`Provider`**;根应用上通过 **`createApp(...).provide(...)`**(由 **`@viewfly/platform-browser`** 提供)注册全局提供者。 |
|
|
54
53
|
| 自定义 DOM 属性标记 | **`withMark(marks, setup)`**:为组件渲染出的元素附加与 `marks` 同名的属性(常用于 scoped CSS 的 `scopeId` 等场景)。 |
|
|
55
54
|
|
|
@@ -59,8 +58,9 @@ import 'reflect-metadata'
|
|
|
59
58
|
|
|
60
59
|
## 文档与示例
|
|
61
60
|
|
|
62
|
-
-
|
|
63
|
-
-
|
|
61
|
+
- **官方文档**:<https://viewfly.org>(重点见安装、组件、响应式、依赖注入)。
|
|
62
|
+
- **类型与注释**:发布包中的 **`.d.ts`** 与源码注释可用于补充 API 细节。
|
|
63
|
+
- **本仓库试跑**:克隆仓库后使用 **pnpm** 安装依赖,在仓库根目录执行 `pnpm dev` 打开 playground。
|
|
64
64
|
|
|
65
65
|
---
|
|
66
66
|
|
package/dist/index.esm.js
CHANGED
|
@@ -1977,7 +1977,7 @@ function patchComponent(nativeRenderer, component, oldChildAtom, newAtom, contex
|
|
|
1977
1977
|
const newTemplate = component.rerender();
|
|
1978
1978
|
const portalContainer = getContainer();
|
|
1979
1979
|
const rawContext = context;
|
|
1980
|
-
const { computedContainer } = component.viewMetadata;
|
|
1980
|
+
const { computedContainer, contextContainer } = component.viewMetadata;
|
|
1981
1981
|
popContainer();
|
|
1982
1982
|
if (portalContainer) if (portalContainer === context.contextContainer) {
|
|
1983
1983
|
if (portalContainer !== computedContainer) needMove = true;
|
|
@@ -1986,15 +1986,14 @@ function patchComponent(nativeRenderer, component, oldChildAtom, newAtom, contex
|
|
|
1986
1986
|
context = {
|
|
1987
1987
|
isParent: true,
|
|
1988
1988
|
anchorNode: portalContainer,
|
|
1989
|
-
contextContainer:
|
|
1989
|
+
contextContainer: context.contextContainer,
|
|
1990
1990
|
computedContainer: portalContainer
|
|
1991
1991
|
};
|
|
1992
1992
|
}
|
|
1993
|
-
else if (
|
|
1993
|
+
else if (contextContainer !== context.contextContainer) needMove = true;
|
|
1994
1994
|
component.viewMetadata = {
|
|
1995
1995
|
atom: newAtom,
|
|
1996
|
-
...context
|
|
1997
|
-
contextContainer: rawContext.contextContainer
|
|
1996
|
+
...context
|
|
1998
1997
|
};
|
|
1999
1998
|
newAtom.child = createChildChain(newTemplate, nativeRenderer, newAtom.namespace);
|
|
2000
1999
|
diff(nativeRenderer, component, newAtom.child, oldChildAtom, context, needMove);
|
|
@@ -2122,15 +2121,17 @@ function updateComponent(nativeRenderer, context, offset, needMove, newAtom, old
|
|
|
2122
2121
|
view.anchorNode = updatedContext.anchorNode;
|
|
2123
2122
|
view.isParent = updatedContext.isParent;
|
|
2124
2123
|
}
|
|
2124
|
+
component.rendered();
|
|
2125
2125
|
} else {
|
|
2126
2126
|
component.viewMetadata = {
|
|
2127
2127
|
atom: newAtom,
|
|
2128
2128
|
...context
|
|
2129
2129
|
};
|
|
2130
2130
|
newAtom.child = oldAtom.child;
|
|
2131
|
-
|
|
2131
|
+
const skipSubComponentDiff = !component.changedSubComponents.size;
|
|
2132
|
+
reuseComponentView(nativeRenderer, newAtom.child, context, needMove, skipSubComponentDiff);
|
|
2133
|
+
if (!skipSubComponentDiff) component.rendered();
|
|
2132
2134
|
}
|
|
2133
|
-
component.rendered();
|
|
2134
2135
|
}
|
|
2135
2136
|
function reuseComponentView(nativeRenderer, child, context, moveView, skipSubComponentDiff) {
|
|
2136
2137
|
const updateContext = (atom) => {
|
package/dist/index.js
CHANGED
|
@@ -1978,7 +1978,7 @@ function patchComponent(nativeRenderer, component, oldChildAtom, newAtom, contex
|
|
|
1978
1978
|
const newTemplate = component.rerender();
|
|
1979
1979
|
const portalContainer = getContainer();
|
|
1980
1980
|
const rawContext = context;
|
|
1981
|
-
const { computedContainer } = component.viewMetadata;
|
|
1981
|
+
const { computedContainer, contextContainer } = component.viewMetadata;
|
|
1982
1982
|
popContainer();
|
|
1983
1983
|
if (portalContainer) if (portalContainer === context.contextContainer) {
|
|
1984
1984
|
if (portalContainer !== computedContainer) needMove = true;
|
|
@@ -1987,15 +1987,14 @@ function patchComponent(nativeRenderer, component, oldChildAtom, newAtom, contex
|
|
|
1987
1987
|
context = {
|
|
1988
1988
|
isParent: true,
|
|
1989
1989
|
anchorNode: portalContainer,
|
|
1990
|
-
contextContainer:
|
|
1990
|
+
contextContainer: context.contextContainer,
|
|
1991
1991
|
computedContainer: portalContainer
|
|
1992
1992
|
};
|
|
1993
1993
|
}
|
|
1994
|
-
else if (
|
|
1994
|
+
else if (contextContainer !== context.contextContainer) needMove = true;
|
|
1995
1995
|
component.viewMetadata = {
|
|
1996
1996
|
atom: newAtom,
|
|
1997
|
-
...context
|
|
1998
|
-
contextContainer: rawContext.contextContainer
|
|
1997
|
+
...context
|
|
1999
1998
|
};
|
|
2000
1999
|
newAtom.child = createChildChain(newTemplate, nativeRenderer, newAtom.namespace);
|
|
2001
2000
|
diff(nativeRenderer, component, newAtom.child, oldChildAtom, context, needMove);
|
|
@@ -2123,15 +2122,17 @@ function updateComponent(nativeRenderer, context, offset, needMove, newAtom, old
|
|
|
2123
2122
|
view.anchorNode = updatedContext.anchorNode;
|
|
2124
2123
|
view.isParent = updatedContext.isParent;
|
|
2125
2124
|
}
|
|
2125
|
+
component.rendered();
|
|
2126
2126
|
} else {
|
|
2127
2127
|
component.viewMetadata = {
|
|
2128
2128
|
atom: newAtom,
|
|
2129
2129
|
...context
|
|
2130
2130
|
};
|
|
2131
2131
|
newAtom.child = oldAtom.child;
|
|
2132
|
-
|
|
2132
|
+
const skipSubComponentDiff = !component.changedSubComponents.size;
|
|
2133
|
+
reuseComponentView(nativeRenderer, newAtom.child, context, needMove, skipSubComponentDiff);
|
|
2134
|
+
if (!skipSubComponentDiff) component.rendered();
|
|
2133
2135
|
}
|
|
2134
|
-
component.rendered();
|
|
2135
2136
|
}
|
|
2136
2137
|
function reuseComponentView(nativeRenderer, child, context, moveView, skipSubComponentDiff) {
|
|
2137
2138
|
const updateContext = (atom) => {
|
package/package.json
CHANGED