@viewfly/core 0.0.28 → 0.0.29
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/bundles/foundation/_api.d.ts +2 -2
- package/bundles/foundation/_utils.d.ts +2 -6
- package/bundles/foundation/component.d.ts +9 -26
- package/bundles/foundation/jsx-element.d.ts +23 -2
- package/bundles/foundation/memo.d.ts +1 -1
- package/bundles/foundation/renderer.d.ts +2 -1
- package/bundles/foundation/root.component.d.ts +4 -5
- package/bundles/foundation/types.d.ts +1 -1
- package/bundles/index.esm.js +181 -174
- package/bundles/index.js +181 -174
- package/package.json +2 -2
package/bundles/index.js
CHANGED
|
@@ -628,60 +628,30 @@ function getSetupContext(need = true) {
|
|
|
628
628
|
function getSignalDepsContext() {
|
|
629
629
|
return signalDepsStack[signalDepsStack.length - 1];
|
|
630
630
|
}
|
|
631
|
-
class JSXComponent {
|
|
632
|
-
constructor(props, factory) {
|
|
633
|
-
this.props = props;
|
|
634
|
-
this.factory = factory;
|
|
635
|
-
}
|
|
636
|
-
createInstance(injector) {
|
|
637
|
-
return this.factory(injector, this.props);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
631
|
/**
|
|
641
632
|
* Viewfly 组件管理类,用于管理组件的生命周期,上下文等
|
|
642
633
|
*/
|
|
643
634
|
class Component extends ReflectiveInjector {
|
|
644
|
-
|
|
645
|
-
return this._dirty;
|
|
646
|
-
}
|
|
647
|
-
get changed() {
|
|
648
|
-
return this._changed;
|
|
649
|
-
}
|
|
650
|
-
constructor(context, type, props, key) {
|
|
635
|
+
constructor(context, jsxNode, props, key) {
|
|
651
636
|
super(context, [{
|
|
652
637
|
provide: Injector,
|
|
653
638
|
useFactory: () => this
|
|
654
639
|
}]);
|
|
655
|
-
this.
|
|
640
|
+
this.jsxNode = jsxNode;
|
|
656
641
|
this.props = props;
|
|
657
642
|
this.key = key;
|
|
658
|
-
this.$$typeOf = this.type;
|
|
659
643
|
this.destroyCallbacks = [];
|
|
660
644
|
this.mountCallbacks = [];
|
|
661
645
|
this.propsChangedCallbacks = [];
|
|
662
646
|
this.updatedCallbacks = [];
|
|
663
|
-
this.changedSubComponents = new Set();
|
|
664
|
-
this._dirty = true;
|
|
665
|
-
this._changed = true;
|
|
666
647
|
this.updatedDestroyCallbacks = [];
|
|
667
648
|
this.propsChangedDestroyCallbacks = [];
|
|
668
649
|
this.isFirstRending = true;
|
|
669
|
-
this.parentComponent = this.parentInjector;
|
|
670
|
-
}
|
|
671
|
-
is(target) {
|
|
672
|
-
return target.$$typeOf === this.$$typeOf;
|
|
673
|
-
}
|
|
674
|
-
provide(providers) {
|
|
675
|
-
providers = Array.isArray(providers) ? providers : [providers];
|
|
676
|
-
this.normalizedProviders.unshift(...providers.map(i => normalizeProvider(i)));
|
|
677
|
-
}
|
|
678
|
-
setup() {
|
|
679
650
|
const self = this;
|
|
680
|
-
const
|
|
651
|
+
const proxiesProps = new Proxy(props, {
|
|
681
652
|
get(_, key) {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
}
|
|
653
|
+
// 必须用 self,因为 props 会随着页面更新变更,使用 self 才能更新引用
|
|
654
|
+
return self.props[key];
|
|
685
655
|
},
|
|
686
656
|
set() {
|
|
687
657
|
// 防止因外部捕获异常引引起的缓存未清理的问题
|
|
@@ -693,84 +663,72 @@ class Component extends ReflectiveInjector {
|
|
|
693
663
|
});
|
|
694
664
|
componentSetupStack.push(this);
|
|
695
665
|
let isSetup = true;
|
|
696
|
-
const render = this.type(
|
|
666
|
+
const render = this.jsxNode.type(proxiesProps);
|
|
697
667
|
const isRenderFn = typeof render === 'function';
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
for (const ref of refs) {
|
|
702
|
-
ref.bind(
|
|
668
|
+
this.instance = isRenderFn ? { $render: render } : render;
|
|
669
|
+
this.refs = toRefs(props.ref);
|
|
670
|
+
this.mountCallbacks.push(() => {
|
|
671
|
+
for (const ref of this.refs) {
|
|
672
|
+
ref.bind(this.instance);
|
|
703
673
|
}
|
|
704
674
|
});
|
|
705
|
-
|
|
706
|
-
for (const ref of refs) {
|
|
707
|
-
ref.unBind(
|
|
675
|
+
this.destroyCallbacks.push(() => {
|
|
676
|
+
for (const ref of this.refs) {
|
|
677
|
+
ref.unBind(this.instance);
|
|
708
678
|
}
|
|
709
679
|
});
|
|
710
680
|
isSetup = false;
|
|
711
681
|
componentSetupStack.pop();
|
|
682
|
+
}
|
|
683
|
+
render() {
|
|
712
684
|
signalDepsStack.push([]);
|
|
713
|
-
let template =
|
|
685
|
+
let template = this.instance.$render();
|
|
714
686
|
const deps = signalDepsStack.pop();
|
|
715
687
|
this.unWatch = useEffect(deps, () => {
|
|
716
|
-
this.markAsDirtied();
|
|
688
|
+
this.jsxNode.markAsDirtied();
|
|
717
689
|
});
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
render: (newProps, oldProps) => {
|
|
721
|
-
if (newProps !== oldProps) {
|
|
722
|
-
const { add, remove, replace } = getObjectChanges(newProps, oldProps);
|
|
723
|
-
if (add.length || remove.length || replace.length) {
|
|
724
|
-
this.invokePropsChangedHooks(newProps);
|
|
725
|
-
}
|
|
726
|
-
const newRefs = toRefs(newProps.ref);
|
|
727
|
-
for (const oldRef of refs) {
|
|
728
|
-
if (!newRefs.includes(oldRef)) {
|
|
729
|
-
oldRef.unBind(componentInstance);
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
for (const newRef of newRefs) {
|
|
733
|
-
if (!refs.includes(newRef)) {
|
|
734
|
-
newRef.bind(componentInstance);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
refs = newRefs;
|
|
738
|
-
}
|
|
739
|
-
if (typeof componentInstance.$shouldUpdate === 'function') {
|
|
740
|
-
if (!componentInstance.$shouldUpdate(newProps, oldProps)) {
|
|
741
|
-
return template;
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
this.unWatch();
|
|
745
|
-
signalDepsStack.push([]);
|
|
746
|
-
template = componentInstance.$render();
|
|
747
|
-
const deps = signalDepsStack.pop();
|
|
748
|
-
this.unWatch = useEffect(deps, () => {
|
|
749
|
-
this.markAsDirtied();
|
|
750
|
-
});
|
|
751
|
-
return template;
|
|
752
|
-
}
|
|
753
|
-
};
|
|
690
|
+
this.template = template;
|
|
691
|
+
return template;
|
|
754
692
|
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
this.
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
693
|
+
update(newProps, forceUpdate = false) {
|
|
694
|
+
const oldProps = this.props;
|
|
695
|
+
const { add, remove, replace } = getObjectChanges(newProps, this.props);
|
|
696
|
+
if (add.length || remove.length || replace.length) {
|
|
697
|
+
this.invokePropsChangedHooks(newProps);
|
|
698
|
+
}
|
|
699
|
+
const newRefs = toRefs(newProps.ref);
|
|
700
|
+
for (const oldRef of this.refs) {
|
|
701
|
+
if (!newRefs.includes(oldRef)) {
|
|
702
|
+
oldRef.unBind(this.instance);
|
|
703
|
+
}
|
|
762
704
|
}
|
|
763
|
-
|
|
764
|
-
|
|
705
|
+
for (const newRef of newRefs) {
|
|
706
|
+
if (!this.refs.includes(newRef)) {
|
|
707
|
+
newRef.bind(this.instance);
|
|
708
|
+
}
|
|
765
709
|
}
|
|
766
|
-
this.
|
|
767
|
-
this.
|
|
710
|
+
this.refs = newRefs;
|
|
711
|
+
if (!forceUpdate && typeof this.instance.$useMemo === 'function') {
|
|
712
|
+
if (this.instance.$useMemo(newProps, oldProps)) {
|
|
713
|
+
return this.template;
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
this.unWatch();
|
|
717
|
+
signalDepsStack.push([]);
|
|
718
|
+
this.template = this.instance.$render();
|
|
719
|
+
const deps = signalDepsStack.pop();
|
|
720
|
+
this.unWatch = useEffect(deps, () => {
|
|
721
|
+
this.jsxNode.markAsDirtied();
|
|
722
|
+
});
|
|
723
|
+
return this.template;
|
|
724
|
+
}
|
|
725
|
+
provide(providers) {
|
|
726
|
+
providers = Array.isArray(providers) ? providers : [providers];
|
|
727
|
+
this.normalizedProviders.unshift(...providers.map(i => normalizeProvider(i)));
|
|
768
728
|
}
|
|
769
729
|
rendered() {
|
|
770
|
-
this.changedSubComponents.clear();
|
|
771
730
|
const is = this.isFirstRending;
|
|
772
731
|
this.isFirstRending = false;
|
|
773
|
-
this._dirty = this._changed = false;
|
|
774
732
|
if (is) {
|
|
775
733
|
this.invokeUpdatedHooks();
|
|
776
734
|
this.invokeMountHooks();
|
|
@@ -1118,6 +1076,9 @@ function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags = exports.Injec
|
|
|
1118
1076
|
return component.get(token, notFoundValue, flags);
|
|
1119
1077
|
}
|
|
1120
1078
|
|
|
1079
|
+
class NativeRenderer {
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1121
1082
|
function Fragment(props) {
|
|
1122
1083
|
return () => {
|
|
1123
1084
|
return props.children;
|
|
@@ -1127,9 +1088,9 @@ function jsx(setup, props, key) {
|
|
|
1127
1088
|
if (typeof setup === 'string') {
|
|
1128
1089
|
return JSXElement.create(setup, props, key);
|
|
1129
1090
|
}
|
|
1130
|
-
return new JSXComponent(props, function (context,
|
|
1131
|
-
return new Component(context,
|
|
1132
|
-
});
|
|
1091
|
+
return new JSXComponent(setup, props, function (context, jsxNode) {
|
|
1092
|
+
return new Component(context, jsxNode, props, key);
|
|
1093
|
+
}, key);
|
|
1133
1094
|
}
|
|
1134
1095
|
const jsxs = jsx;
|
|
1135
1096
|
class JSXText {
|
|
@@ -1155,66 +1116,91 @@ class JSXElement {
|
|
|
1155
1116
|
return target.$$typeOf === this.$$typeOf;
|
|
1156
1117
|
}
|
|
1157
1118
|
}
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
$shouldUpdate: shouldUpdate,
|
|
1162
|
-
$render: render
|
|
1163
|
-
};
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
/**
|
|
1167
|
-
* Viewfly 根组件,用于实现组件状态更新事件通知
|
|
1168
|
-
*/
|
|
1169
|
-
class RootComponent extends Component {
|
|
1170
|
-
constructor(parentInjector, factory) {
|
|
1171
|
-
super(parentInjector, factory, {});
|
|
1172
|
-
this.onChange = null;
|
|
1119
|
+
class JSXComponent {
|
|
1120
|
+
get dirty() {
|
|
1121
|
+
return this._dirty;
|
|
1173
1122
|
}
|
|
1174
|
-
|
|
1175
|
-
|
|
1123
|
+
get changed() {
|
|
1124
|
+
return this._changed;
|
|
1125
|
+
}
|
|
1126
|
+
constructor(type, props, factory, key) {
|
|
1127
|
+
this.type = type;
|
|
1128
|
+
this.props = props;
|
|
1129
|
+
this.factory = factory;
|
|
1130
|
+
this.key = key;
|
|
1131
|
+
this.$$typeOf = this.type;
|
|
1132
|
+
this.parentComponent = null;
|
|
1133
|
+
this.changedSubComponents = new Set();
|
|
1134
|
+
this._dirty = true;
|
|
1176
1135
|
this._changed = true;
|
|
1136
|
+
}
|
|
1137
|
+
markAsDirtied() {
|
|
1138
|
+
this._dirty = true;
|
|
1139
|
+
this.markAsChanged();
|
|
1140
|
+
}
|
|
1141
|
+
markAsChanged(changedComponent) {
|
|
1177
1142
|
if (changedComponent) {
|
|
1178
1143
|
this.changedSubComponents.add(changedComponent);
|
|
1179
1144
|
}
|
|
1180
|
-
(
|
|
1145
|
+
if (this._changed) {
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
this._changed = true;
|
|
1149
|
+
this.parentComponent.markAsChanged(this);
|
|
1150
|
+
}
|
|
1151
|
+
reset() {
|
|
1152
|
+
this.changedSubComponents.clear();
|
|
1153
|
+
this.instance.rendered();
|
|
1154
|
+
this._dirty = this._changed = false;
|
|
1155
|
+
}
|
|
1156
|
+
is(target) {
|
|
1157
|
+
return target.$$typeOf === this.$$typeOf;
|
|
1158
|
+
}
|
|
1159
|
+
createInstance(injector) {
|
|
1160
|
+
this.parentComponent = injector.jsxNode;
|
|
1161
|
+
this.instance = this.factory(injector, this);
|
|
1162
|
+
return this.instance;
|
|
1181
1163
|
}
|
|
1182
1164
|
}
|
|
1183
1165
|
|
|
1184
|
-
|
|
1166
|
+
function withMemo(canUseMemo, render) {
|
|
1167
|
+
return {
|
|
1168
|
+
$useMemo: canUseMemo,
|
|
1169
|
+
$render: render
|
|
1170
|
+
};
|
|
1185
1171
|
}
|
|
1186
1172
|
|
|
1187
|
-
function createRenderer(
|
|
1173
|
+
function createRenderer(jsxComponent, nativeRenderer, parentComponent) {
|
|
1188
1174
|
let isInit = true;
|
|
1189
1175
|
return function render(host) {
|
|
1190
1176
|
if (isInit) {
|
|
1191
1177
|
isInit = false;
|
|
1192
1178
|
const atom = {
|
|
1193
|
-
jsxNode:
|
|
1179
|
+
jsxNode: jsxComponent,
|
|
1194
1180
|
parent: null,
|
|
1195
1181
|
sibling: null,
|
|
1196
1182
|
child: null,
|
|
1197
1183
|
nativeNode: null
|
|
1198
1184
|
};
|
|
1199
|
-
buildView(nativeRenderer, atom, {
|
|
1185
|
+
buildView(nativeRenderer, parentComponent, atom, {
|
|
1200
1186
|
isParent: true,
|
|
1201
1187
|
host
|
|
1202
1188
|
});
|
|
1203
1189
|
}
|
|
1204
1190
|
else {
|
|
1205
|
-
updateView(nativeRenderer,
|
|
1191
|
+
updateView(nativeRenderer, jsxComponent);
|
|
1206
1192
|
}
|
|
1207
1193
|
};
|
|
1208
1194
|
}
|
|
1209
|
-
function buildView(nativeRenderer, atom, context) {
|
|
1210
|
-
if (atom.jsxNode instanceof
|
|
1211
|
-
componentRender(atom.jsxNode, atom, context);
|
|
1195
|
+
function buildView(nativeRenderer, parentComponent, atom, context) {
|
|
1196
|
+
if (atom.jsxNode instanceof JSXComponent) {
|
|
1197
|
+
const component = componentRender(atom.jsxNode, parentComponent, atom, context);
|
|
1212
1198
|
let child = atom.child;
|
|
1213
1199
|
while (child) {
|
|
1214
|
-
buildView(nativeRenderer, child, context);
|
|
1200
|
+
buildView(nativeRenderer, component, child, context);
|
|
1215
1201
|
child = child.sibling;
|
|
1216
1202
|
}
|
|
1217
|
-
atom.jsxNode.
|
|
1203
|
+
atom.jsxNode.reset();
|
|
1218
1204
|
}
|
|
1219
1205
|
else {
|
|
1220
1206
|
let nativeNode;
|
|
@@ -1241,7 +1227,7 @@ function buildView(nativeRenderer, atom, context) {
|
|
|
1241
1227
|
};
|
|
1242
1228
|
let child = atom.child;
|
|
1243
1229
|
while (child) {
|
|
1244
|
-
buildView(nativeRenderer, child, childContext);
|
|
1230
|
+
buildView(nativeRenderer, parentComponent, child, childContext);
|
|
1245
1231
|
child = child.sibling;
|
|
1246
1232
|
}
|
|
1247
1233
|
}
|
|
@@ -1252,24 +1238,24 @@ function buildView(nativeRenderer, atom, context) {
|
|
|
1252
1238
|
}
|
|
1253
1239
|
}
|
|
1254
1240
|
}
|
|
1255
|
-
function updateView(nativeRenderer,
|
|
1256
|
-
if (
|
|
1257
|
-
applyChanges(nativeRenderer,
|
|
1258
|
-
|
|
1241
|
+
function updateView(nativeRenderer, jsxComponent) {
|
|
1242
|
+
if (jsxComponent.dirty) {
|
|
1243
|
+
applyChanges(nativeRenderer, jsxComponent);
|
|
1244
|
+
jsxComponent.reset();
|
|
1259
1245
|
}
|
|
1260
|
-
else if (
|
|
1261
|
-
|
|
1246
|
+
else if (jsxComponent.changed) {
|
|
1247
|
+
jsxComponent.changedSubComponents.forEach(child => {
|
|
1262
1248
|
updateView(nativeRenderer, child);
|
|
1263
1249
|
});
|
|
1264
|
-
|
|
1250
|
+
jsxComponent.reset();
|
|
1265
1251
|
}
|
|
1266
1252
|
}
|
|
1267
|
-
function applyChanges(nativeRenderer,
|
|
1268
|
-
const { atom,
|
|
1253
|
+
function applyChanges(nativeRenderer, jsxComponent) {
|
|
1254
|
+
const { atom, host, isParent } = jsxComponent.$$view;
|
|
1269
1255
|
const diffAtom = atom.child;
|
|
1270
|
-
const template =
|
|
1256
|
+
const template = jsxComponent.instance.update(jsxComponent.instance.props, true);
|
|
1271
1257
|
if (template) {
|
|
1272
|
-
linkTemplate(template,
|
|
1258
|
+
linkTemplate(template, jsxComponent, atom);
|
|
1273
1259
|
}
|
|
1274
1260
|
else {
|
|
1275
1261
|
atom.child = null;
|
|
@@ -1278,14 +1264,14 @@ function applyChanges(nativeRenderer, component) {
|
|
|
1278
1264
|
host,
|
|
1279
1265
|
isParent
|
|
1280
1266
|
};
|
|
1281
|
-
diff(nativeRenderer, atom.child, diffAtom, context, 0, 0);
|
|
1267
|
+
diff(nativeRenderer, jsxComponent.instance, atom.child, diffAtom, context, 0, 0);
|
|
1282
1268
|
const next = atom.sibling;
|
|
1283
|
-
if (next && next.jsxNode instanceof
|
|
1269
|
+
if (next && next.jsxNode instanceof JSXComponent) {
|
|
1284
1270
|
next.jsxNode.$$view.host = context.host;
|
|
1285
1271
|
next.jsxNode.$$view.isParent = context.isParent;
|
|
1286
1272
|
}
|
|
1287
1273
|
}
|
|
1288
|
-
function diff(nativeRenderer, newAtom, oldAtom, context, expectIndex, index) {
|
|
1274
|
+
function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expectIndex, index) {
|
|
1289
1275
|
const oldChildren = [];
|
|
1290
1276
|
while (oldAtom) {
|
|
1291
1277
|
oldChildren.push({
|
|
@@ -1299,13 +1285,14 @@ function diff(nativeRenderer, newAtom, oldAtom, context, expectIndex, index) {
|
|
|
1299
1285
|
const changeCommits = {
|
|
1300
1286
|
updateComponent: (newAtom, reusedAtom, expectIndex, diffIndex) => {
|
|
1301
1287
|
commits.push((offset) => {
|
|
1302
|
-
const
|
|
1288
|
+
const oldJSXComponent = reusedAtom.jsxNode;
|
|
1289
|
+
const instance = oldJSXComponent.instance;
|
|
1303
1290
|
const newProps = newAtom.jsxNode.props;
|
|
1304
|
-
const
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
newAtom.jsxNode
|
|
1308
|
-
if (newTemplate ===
|
|
1291
|
+
const oldTemplate = instance.template;
|
|
1292
|
+
const newTemplate = instance.update(newProps);
|
|
1293
|
+
oldJSXComponent.$$view = Object.assign({ atom: newAtom }, context);
|
|
1294
|
+
newAtom.jsxNode = oldJSXComponent;
|
|
1295
|
+
if (newTemplate === oldTemplate) {
|
|
1309
1296
|
reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex !== diffIndex - offset);
|
|
1310
1297
|
return;
|
|
1311
1298
|
}
|
|
@@ -1313,7 +1300,7 @@ function diff(nativeRenderer, newAtom, oldAtom, context, expectIndex, index) {
|
|
|
1313
1300
|
linkTemplate(newTemplate, newAtom.jsxNode, newAtom);
|
|
1314
1301
|
}
|
|
1315
1302
|
if (newAtom.child) {
|
|
1316
|
-
diff(nativeRenderer, newAtom.child, reusedAtom.child, context, expectIndex, diffIndex);
|
|
1303
|
+
diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex, diffIndex);
|
|
1317
1304
|
}
|
|
1318
1305
|
else if (reusedAtom.child) {
|
|
1319
1306
|
let atom = reusedAtom.child;
|
|
@@ -1322,7 +1309,7 @@ function diff(nativeRenderer, newAtom, oldAtom, context, expectIndex, index) {
|
|
|
1322
1309
|
atom = atom.sibling;
|
|
1323
1310
|
}
|
|
1324
1311
|
}
|
|
1325
|
-
|
|
1312
|
+
oldJSXComponent.reset();
|
|
1326
1313
|
});
|
|
1327
1314
|
},
|
|
1328
1315
|
updateElement: (newAtom, oldAtom, expectIndex, oldIndex) => {
|
|
@@ -1341,7 +1328,7 @@ function diff(nativeRenderer, newAtom, oldAtom, context, expectIndex, index) {
|
|
|
1341
1328
|
context.isParent = false;
|
|
1342
1329
|
const applyRefs = updateNativeNodeProperties(nativeRenderer, newAtom.jsxNode, oldAtom.jsxNode, newAtom.nativeNode);
|
|
1343
1330
|
if (newAtom.child) {
|
|
1344
|
-
diff(nativeRenderer, newAtom.child, oldAtom.child, {
|
|
1331
|
+
diff(nativeRenderer, parentComponent, newAtom.child, oldAtom.child, {
|
|
1345
1332
|
host: newAtom.nativeNode,
|
|
1346
1333
|
isParent: true
|
|
1347
1334
|
}, 0, 0);
|
|
@@ -1369,7 +1356,7 @@ function diff(nativeRenderer, newAtom, oldAtom, context, expectIndex, index) {
|
|
|
1369
1356
|
},
|
|
1370
1357
|
create: (start) => {
|
|
1371
1358
|
commits.push(() => {
|
|
1372
|
-
buildView(nativeRenderer, start, context);
|
|
1359
|
+
buildView(nativeRenderer, parentComponent, start, context);
|
|
1373
1360
|
});
|
|
1374
1361
|
}
|
|
1375
1362
|
};
|
|
@@ -1408,7 +1395,7 @@ function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveVi
|
|
|
1408
1395
|
child = child.sibling;
|
|
1409
1396
|
}
|
|
1410
1397
|
const updateContext = (atom) => {
|
|
1411
|
-
if (atom.jsxNode instanceof
|
|
1398
|
+
if (atom.jsxNode instanceof JSXComponent) {
|
|
1412
1399
|
let child = atom.child;
|
|
1413
1400
|
while (child) {
|
|
1414
1401
|
updateContext(child);
|
|
@@ -1474,30 +1461,29 @@ function cleanView(nativeRenderer, atom, isClean) {
|
|
|
1474
1461
|
cleanView(nativeRenderer, child, isClean);
|
|
1475
1462
|
child = child.sibling;
|
|
1476
1463
|
}
|
|
1477
|
-
if (atom.jsxNode instanceof
|
|
1478
|
-
atom.jsxNode.destroy();
|
|
1464
|
+
if (atom.jsxNode instanceof JSXComponent) {
|
|
1465
|
+
atom.jsxNode.instance.destroy();
|
|
1479
1466
|
}
|
|
1480
1467
|
}
|
|
1481
|
-
function componentRender(
|
|
1482
|
-
const
|
|
1468
|
+
function componentRender(jsxComponent, parentComponent, from, context) {
|
|
1469
|
+
const component = jsxComponent.createInstance(parentComponent);
|
|
1470
|
+
const template = component.render();
|
|
1483
1471
|
if (template) {
|
|
1484
|
-
linkTemplate(template,
|
|
1472
|
+
linkTemplate(template, jsxComponent, from);
|
|
1485
1473
|
}
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
return from;
|
|
1474
|
+
jsxComponent.$$view = Object.assign({ atom: from }, context);
|
|
1475
|
+
return component;
|
|
1489
1476
|
}
|
|
1490
|
-
function createChainByComponentFactory(
|
|
1491
|
-
const component = factory.createInstance(context);
|
|
1477
|
+
function createChainByComponentFactory(jsxComponent, parent) {
|
|
1492
1478
|
return {
|
|
1493
|
-
jsxNode:
|
|
1479
|
+
jsxNode: jsxComponent,
|
|
1494
1480
|
parent,
|
|
1495
1481
|
sibling: null,
|
|
1496
1482
|
child: null,
|
|
1497
1483
|
nativeNode: null
|
|
1498
1484
|
};
|
|
1499
1485
|
}
|
|
1500
|
-
function createChainByJSXElement(
|
|
1486
|
+
function createChainByJSXElement(jsxComponent, element, parent) {
|
|
1501
1487
|
const atom = {
|
|
1502
1488
|
jsxNode: element,
|
|
1503
1489
|
parent,
|
|
@@ -1507,7 +1493,7 @@ function createChainByJSXElement(context, element, parent) {
|
|
|
1507
1493
|
};
|
|
1508
1494
|
if (Reflect.has(element.props, 'children')) {
|
|
1509
1495
|
const jsxChildren = element.props.children;
|
|
1510
|
-
const children = createChainByChildren(
|
|
1496
|
+
const children = createChainByChildren(jsxComponent, Array.isArray(jsxChildren) ? jsxChildren : [jsxChildren], atom, []);
|
|
1511
1497
|
link(atom, children);
|
|
1512
1498
|
}
|
|
1513
1499
|
return atom;
|
|
@@ -1521,14 +1507,14 @@ function createChainByJSXText(node, parent) {
|
|
|
1521
1507
|
nativeNode: null
|
|
1522
1508
|
};
|
|
1523
1509
|
}
|
|
1524
|
-
function createChainByChildren(
|
|
1510
|
+
function createChainByChildren(jsxComponent, children, parent, atoms) {
|
|
1525
1511
|
for (const item of children) {
|
|
1526
1512
|
if (item instanceof JSXElement) {
|
|
1527
|
-
atoms.push(createChainByJSXElement(
|
|
1513
|
+
atoms.push(createChainByJSXElement(jsxComponent, item, parent));
|
|
1528
1514
|
continue;
|
|
1529
1515
|
}
|
|
1530
1516
|
if (item instanceof JSXComponent) {
|
|
1531
|
-
const childAtom = createChainByComponentFactory(
|
|
1517
|
+
const childAtom = createChainByComponentFactory(item, parent);
|
|
1532
1518
|
atoms.push(childAtom);
|
|
1533
1519
|
continue;
|
|
1534
1520
|
}
|
|
@@ -1537,7 +1523,7 @@ function createChainByChildren(context, children, parent, atoms) {
|
|
|
1537
1523
|
continue;
|
|
1538
1524
|
}
|
|
1539
1525
|
if (Array.isArray(item)) {
|
|
1540
|
-
createChainByChildren(
|
|
1526
|
+
createChainByChildren(jsxComponent, item, parent, atoms);
|
|
1541
1527
|
continue;
|
|
1542
1528
|
}
|
|
1543
1529
|
if (item !== null && typeof item !== 'undefined') {
|
|
@@ -1546,9 +1532,10 @@ function createChainByChildren(context, children, parent, atoms) {
|
|
|
1546
1532
|
}
|
|
1547
1533
|
return atoms;
|
|
1548
1534
|
}
|
|
1549
|
-
function linkTemplate(template,
|
|
1535
|
+
function linkTemplate(template, jsxComponent, parent) {
|
|
1550
1536
|
const children = Array.isArray(template) ? template : [template];
|
|
1551
|
-
|
|
1537
|
+
const newChildren = createChainByChildren(jsxComponent, children, parent, []);
|
|
1538
|
+
link(parent, newChildren);
|
|
1552
1539
|
}
|
|
1553
1540
|
function link(parent, children) {
|
|
1554
1541
|
for (let i = 1; i < children.length; i++) {
|
|
@@ -1728,17 +1715,37 @@ function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn) {
|
|
|
1728
1715
|
nativeRenderer.listen(nativeNode, type, delegate);
|
|
1729
1716
|
}
|
|
1730
1717
|
|
|
1718
|
+
/**
|
|
1719
|
+
* Viewfly 根组件,用于实现组件状态更新事件通知
|
|
1720
|
+
*/
|
|
1721
|
+
class RootComponent extends JSXComponent {
|
|
1722
|
+
constructor(factory, {}) {
|
|
1723
|
+
super(factory, {}, (parentComponent, jsxNode) => {
|
|
1724
|
+
return new Component(parentComponent, jsxNode, {});
|
|
1725
|
+
});
|
|
1726
|
+
this.onChange = null;
|
|
1727
|
+
}
|
|
1728
|
+
markAsChanged(changedComponent) {
|
|
1729
|
+
var _a;
|
|
1730
|
+
this._changed = true;
|
|
1731
|
+
if (changedComponent) {
|
|
1732
|
+
this.changedSubComponents.add(changedComponent);
|
|
1733
|
+
}
|
|
1734
|
+
(_a = this.onChange) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1731
1738
|
const viewflyErrorFn = makeError('Viewfly');
|
|
1732
1739
|
function viewfly({ context, nativeRenderer, autoUpdate, root }) {
|
|
1733
1740
|
const appProviders = [];
|
|
1734
1741
|
let destroyed = false;
|
|
1735
|
-
const rootComponent = new RootComponent(
|
|
1742
|
+
const rootComponent = new RootComponent(() => {
|
|
1736
1743
|
provide(appProviders);
|
|
1737
1744
|
return () => {
|
|
1738
1745
|
return destroyed ? null : root;
|
|
1739
1746
|
};
|
|
1740
|
-
});
|
|
1741
|
-
const render = createRenderer(rootComponent, nativeRenderer);
|
|
1747
|
+
}, {});
|
|
1748
|
+
const render = createRenderer(rootComponent, nativeRenderer, context || new NullInjector());
|
|
1742
1749
|
let isStarted = false;
|
|
1743
1750
|
let task = null;
|
|
1744
1751
|
function microTask(callback) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
|
|
5
5
|
"main": "./bundles/index.js",
|
|
6
6
|
"module": "./bundles/index.esm.js",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"bugs": {
|
|
47
47
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "ff67aecb0dd61ac7d81decbbd1670cdfe850f1cb"
|
|
50
50
|
}
|