@viewfly/core 0.5.4 → 0.6.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/bundles/foundation/_utils.d.ts +22 -4
- package/bundles/foundation/component.d.ts +12 -13
- package/bundles/foundation/injection-tokens.d.ts +1 -0
- package/bundles/foundation/jsx-element.d.ts +8 -28
- package/bundles/foundation/memo.d.ts +1 -1
- package/bundles/foundation/types.d.ts +4 -4
- package/bundles/index.esm.js +220 -238
- package/bundles/index.js +220 -240
- package/bundles/viewfly.d.ts +1 -1
- package/package.json +2 -2
package/bundles/index.js
CHANGED
|
@@ -658,25 +658,16 @@ class Component extends ReflectiveInjector {
|
|
|
658
658
|
return this._changed;
|
|
659
659
|
}
|
|
660
660
|
constructor(parentComponent, type, props, key) {
|
|
661
|
-
super(parentComponent, [
|
|
662
|
-
provide: Injector,
|
|
663
|
-
useFactory: () => this
|
|
664
|
-
}], type.scope);
|
|
661
|
+
super(parentComponent, [], type.scope);
|
|
665
662
|
this.parentComponent = parentComponent;
|
|
666
663
|
this.type = type;
|
|
667
664
|
this.props = props;
|
|
668
665
|
this.key = key;
|
|
669
|
-
this.$$typeOf = this.type;
|
|
670
666
|
this.changedSubComponents = new Set();
|
|
671
|
-
this.unmountedCallbacks = [];
|
|
672
|
-
this.mountCallbacks = [];
|
|
673
|
-
this.propsChangedCallbacks = [];
|
|
674
|
-
this.updatedCallbacks = [];
|
|
675
|
-
this.updatedDestroyCallbacks = [];
|
|
676
|
-
this.propsChangedDestroyCallbacks = [];
|
|
677
667
|
this._dirty = true;
|
|
678
668
|
this._changed = true;
|
|
679
669
|
this.isFirstRendering = true;
|
|
670
|
+
this.refs = null;
|
|
680
671
|
}
|
|
681
672
|
markAsDirtied() {
|
|
682
673
|
this._dirty = true;
|
|
@@ -714,17 +705,20 @@ class Component extends ReflectiveInjector {
|
|
|
714
705
|
const render = this.type(proxiesProps);
|
|
715
706
|
const isRenderFn = typeof render === 'function';
|
|
716
707
|
this.instance = isRenderFn ? { $render: render } : render;
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
708
|
+
const refs = toRefs(this.props.ref);
|
|
709
|
+
if (refs.length) {
|
|
710
|
+
this.refs = refs;
|
|
711
|
+
onMounted(() => {
|
|
712
|
+
for (const ref of refs) {
|
|
713
|
+
ref.bind(this.instance);
|
|
714
|
+
}
|
|
715
|
+
return () => {
|
|
716
|
+
for (const ref of refs) {
|
|
717
|
+
ref.unBind(this.instance);
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
});
|
|
721
|
+
}
|
|
728
722
|
isSetup = false;
|
|
729
723
|
componentSetupStack.pop();
|
|
730
724
|
signalDepsStack.push([]);
|
|
@@ -749,17 +743,19 @@ class Component extends ReflectiveInjector {
|
|
|
749
743
|
return this.template;
|
|
750
744
|
}
|
|
751
745
|
const newRefs = toRefs(newProps.ref);
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
746
|
+
if (this.refs) {
|
|
747
|
+
for (const oldRef of this.refs) {
|
|
748
|
+
if (!newRefs.includes(oldRef)) {
|
|
749
|
+
oldRef.unBind(this.instance);
|
|
750
|
+
}
|
|
755
751
|
}
|
|
756
752
|
}
|
|
757
753
|
for (const newRef of newRefs) {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
754
|
+
newRef.bind(this.instance);
|
|
755
|
+
}
|
|
756
|
+
if (newRefs.length) {
|
|
757
|
+
this.refs = newRefs;
|
|
761
758
|
}
|
|
762
|
-
this.refs = newRefs;
|
|
763
759
|
if (!forceUpdate && typeof this.instance.$useMemo === 'function') {
|
|
764
760
|
if (this.instance.$useMemo(newProps, oldProps)) {
|
|
765
761
|
return this.template;
|
|
@@ -796,55 +792,73 @@ class Component extends ReflectiveInjector {
|
|
|
796
792
|
}
|
|
797
793
|
}
|
|
798
794
|
destroy() {
|
|
795
|
+
var _a, _b, _c;
|
|
799
796
|
this.unWatch();
|
|
800
|
-
this.updatedDestroyCallbacks.forEach(fn => {
|
|
797
|
+
(_a = this.updatedDestroyCallbacks) === null || _a === void 0 ? void 0 : _a.forEach(fn => {
|
|
801
798
|
fn();
|
|
802
799
|
});
|
|
803
|
-
this.
|
|
804
|
-
this.propsChangedDestroyCallbacks.forEach(fn => {
|
|
800
|
+
(_b = this.propsChangedDestroyCallbacks) === null || _b === void 0 ? void 0 : _b.forEach(fn => {
|
|
805
801
|
fn();
|
|
806
802
|
});
|
|
807
|
-
this.
|
|
808
|
-
for (const fn of this.unmountedCallbacks) {
|
|
803
|
+
(_c = this.unmountedCallbacks) === null || _c === void 0 ? void 0 : _c.forEach(fn => {
|
|
809
804
|
fn();
|
|
810
|
-
}
|
|
811
|
-
this.
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
805
|
+
});
|
|
806
|
+
this.propsChangedDestroyCallbacks =
|
|
807
|
+
this.updatedDestroyCallbacks =
|
|
808
|
+
this.mountCallbacks =
|
|
809
|
+
this.updatedCallbacks =
|
|
810
|
+
this.propsChangedCallbacks =
|
|
811
|
+
this.unmountedCallbacks = null;
|
|
815
812
|
}
|
|
816
813
|
invokePropsChangedHooks(newProps) {
|
|
817
814
|
const oldProps = this.props;
|
|
818
815
|
this.props = newProps;
|
|
819
|
-
this.
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
816
|
+
if (this.propsChangedCallbacks) {
|
|
817
|
+
if (this.propsChangedDestroyCallbacks) {
|
|
818
|
+
this.propsChangedDestroyCallbacks.forEach(fn => {
|
|
819
|
+
fn();
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
const propsChangedDestroyCallbacks = [];
|
|
823
|
+
for (const fn of this.propsChangedCallbacks) {
|
|
824
|
+
const destroyFn = fn(newProps, oldProps);
|
|
825
|
+
if (typeof destroyFn === 'function') {
|
|
826
|
+
propsChangedDestroyCallbacks.push(destroyFn);
|
|
827
|
+
}
|
|
827
828
|
}
|
|
829
|
+
this.propsChangedDestroyCallbacks = propsChangedDestroyCallbacks.length ? propsChangedDestroyCallbacks : null;
|
|
828
830
|
}
|
|
829
831
|
}
|
|
830
832
|
invokeMountHooks() {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
833
|
+
const unmountedCallbacks = [];
|
|
834
|
+
if (this.mountCallbacks) {
|
|
835
|
+
for (const fn of this.mountCallbacks) {
|
|
836
|
+
const destroyFn = fn();
|
|
837
|
+
if (typeof destroyFn === 'function') {
|
|
838
|
+
unmountedCallbacks.push(destroyFn);
|
|
839
|
+
}
|
|
835
840
|
}
|
|
836
841
|
}
|
|
842
|
+
if (unmountedCallbacks.length) {
|
|
843
|
+
this.unmountedCallbacks = unmountedCallbacks;
|
|
844
|
+
}
|
|
845
|
+
this.mountCallbacks = null;
|
|
837
846
|
}
|
|
838
847
|
invokeUpdatedHooks() {
|
|
839
|
-
this.
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
const destroyFn = fn();
|
|
845
|
-
if (typeof destroyFn === 'function') {
|
|
846
|
-
this.updatedDestroyCallbacks.push(destroyFn);
|
|
848
|
+
if (this.updatedCallbacks) {
|
|
849
|
+
if (this.updatedDestroyCallbacks) {
|
|
850
|
+
this.updatedDestroyCallbacks.forEach(fn => {
|
|
851
|
+
fn();
|
|
852
|
+
});
|
|
847
853
|
}
|
|
854
|
+
const updatedDestroyCallbacks = [];
|
|
855
|
+
for (const fn of this.updatedCallbacks) {
|
|
856
|
+
const destroyFn = fn();
|
|
857
|
+
if (typeof destroyFn === 'function') {
|
|
858
|
+
updatedDestroyCallbacks.push(destroyFn);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
this.updatedDestroyCallbacks = updatedDestroyCallbacks.length ? updatedDestroyCallbacks : null;
|
|
848
862
|
}
|
|
849
863
|
}
|
|
850
864
|
}
|
|
@@ -867,6 +881,9 @@ function toRefs(ref) {
|
|
|
867
881
|
*/
|
|
868
882
|
function onMounted(callback) {
|
|
869
883
|
const component = getSetupContext();
|
|
884
|
+
if (!component.mountCallbacks) {
|
|
885
|
+
component.mountCallbacks = [];
|
|
886
|
+
}
|
|
870
887
|
component.mountCallbacks.push(callback);
|
|
871
888
|
}
|
|
872
889
|
/**
|
|
@@ -886,6 +903,9 @@ function onMounted(callback) {
|
|
|
886
903
|
*/
|
|
887
904
|
function onUpdated(callback) {
|
|
888
905
|
const component = getSetupContext();
|
|
906
|
+
if (!component.updatedCallbacks) {
|
|
907
|
+
component.updatedCallbacks = [];
|
|
908
|
+
}
|
|
889
909
|
component.updatedCallbacks.push(callback);
|
|
890
910
|
return () => {
|
|
891
911
|
const index = component.updatedCallbacks.indexOf(callback);
|
|
@@ -915,6 +935,9 @@ function onUpdated(callback) {
|
|
|
915
935
|
*/
|
|
916
936
|
function onPropsChanged(callback) {
|
|
917
937
|
const component = getSetupContext();
|
|
938
|
+
if (!component.propsChangedCallbacks) {
|
|
939
|
+
component.propsChangedCallbacks = [];
|
|
940
|
+
}
|
|
918
941
|
component.propsChangedCallbacks.push(callback);
|
|
919
942
|
return () => {
|
|
920
943
|
const index = component.propsChangedCallbacks.indexOf(callback);
|
|
@@ -929,6 +952,9 @@ function onPropsChanged(callback) {
|
|
|
929
952
|
*/
|
|
930
953
|
function onUnmounted(callback) {
|
|
931
954
|
const component = getSetupContext();
|
|
955
|
+
if (!component.unmountedCallbacks) {
|
|
956
|
+
component.unmountedCallbacks = [];
|
|
957
|
+
}
|
|
932
958
|
component.unmountedCallbacks.push(callback);
|
|
933
959
|
}
|
|
934
960
|
class DynamicRef {
|
|
@@ -1123,6 +1149,9 @@ function createDerived(callback, isContinue) {
|
|
|
1123
1149
|
const component = getSetupContext(false);
|
|
1124
1150
|
const unListen = listen(signal, deps, callback, isContinue);
|
|
1125
1151
|
if (component) {
|
|
1152
|
+
if (!component.unmountedCallbacks) {
|
|
1153
|
+
component.unmountedCallbacks = [];
|
|
1154
|
+
}
|
|
1126
1155
|
component.unmountedCallbacks.push(() => {
|
|
1127
1156
|
unListen();
|
|
1128
1157
|
});
|
|
@@ -1155,7 +1184,7 @@ function watch(deps, callback) {
|
|
|
1155
1184
|
return;
|
|
1156
1185
|
}
|
|
1157
1186
|
isClean = true;
|
|
1158
|
-
if (component) {
|
|
1187
|
+
if (component === null || component === void 0 ? void 0 : component.unmountedCallbacks) {
|
|
1159
1188
|
const index = component.unmountedCallbacks.indexOf(destroyFn);
|
|
1160
1189
|
component.unmountedCallbacks.splice(index, 1);
|
|
1161
1190
|
}
|
|
@@ -1164,6 +1193,9 @@ function watch(deps, callback) {
|
|
|
1164
1193
|
}
|
|
1165
1194
|
};
|
|
1166
1195
|
if (component) {
|
|
1196
|
+
if (!component.unmountedCallbacks) {
|
|
1197
|
+
component.unmountedCallbacks = [];
|
|
1198
|
+
}
|
|
1167
1199
|
component.unmountedCallbacks.push(destroyFn);
|
|
1168
1200
|
}
|
|
1169
1201
|
return destroyFn;
|
|
@@ -1198,48 +1230,19 @@ function Fragment(props) {
|
|
|
1198
1230
|
return props.children;
|
|
1199
1231
|
};
|
|
1200
1232
|
}
|
|
1201
|
-
function jsx(
|
|
1202
|
-
|
|
1203
|
-
return JSXElement.createInstance(setup, props, key);
|
|
1204
|
-
}
|
|
1205
|
-
return JSXComponent.createInstance(setup, props, function (context) {
|
|
1206
|
-
return new Component(context, setup, props, key);
|
|
1207
|
-
}, key);
|
|
1233
|
+
function jsx(type, props, key) {
|
|
1234
|
+
return JSXNodeFactory.createNode(type, props, key);
|
|
1208
1235
|
}
|
|
1209
1236
|
const jsxs = jsx;
|
|
1210
|
-
const
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
}
|
|
1217
|
-
class JSXElement {
|
|
1218
|
-
static createInstance(type, props, key) {
|
|
1219
|
-
return new JSXElement(type, props, key);
|
|
1220
|
-
}
|
|
1221
|
-
constructor(type, props, key) {
|
|
1222
|
-
this.type = type;
|
|
1223
|
-
this.props = props;
|
|
1224
|
-
this.key = key;
|
|
1225
|
-
this.$$typeOf = this.type;
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
class JSXComponent {
|
|
1229
|
-
static createInstance(type, props, factory, key) {
|
|
1230
|
-
return new JSXComponent(type, props, factory, key);
|
|
1231
|
-
}
|
|
1232
|
-
constructor(type, props, factory, key) {
|
|
1233
|
-
this.type = type;
|
|
1234
|
-
this.props = props;
|
|
1235
|
-
this.factory = factory;
|
|
1236
|
-
this.key = key;
|
|
1237
|
-
this.$$typeOf = this.type;
|
|
1238
|
-
}
|
|
1239
|
-
createInstance(parentComponent) {
|
|
1240
|
-
return this.factory(parentComponent);
|
|
1237
|
+
const JSXNodeFactory = {
|
|
1238
|
+
createNode(type, props, key) {
|
|
1239
|
+
return {
|
|
1240
|
+
type,
|
|
1241
|
+
props,
|
|
1242
|
+
key
|
|
1243
|
+
};
|
|
1241
1244
|
}
|
|
1242
|
-
}
|
|
1245
|
+
};
|
|
1243
1246
|
|
|
1244
1247
|
function withMemo(canUseMemo, render) {
|
|
1245
1248
|
return {
|
|
@@ -1248,14 +1251,15 @@ function withMemo(canUseMemo, render) {
|
|
|
1248
1251
|
};
|
|
1249
1252
|
}
|
|
1250
1253
|
|
|
1254
|
+
const listenerReg = /^on(?=[A-Z])/;
|
|
1251
1255
|
function createRenderer(component, nativeRenderer) {
|
|
1252
1256
|
let isInit = true;
|
|
1253
1257
|
return function render(host) {
|
|
1254
1258
|
if (isInit) {
|
|
1255
1259
|
isInit = false;
|
|
1256
1260
|
const atom = {
|
|
1261
|
+
type: 'component',
|
|
1257
1262
|
jsxNode: component,
|
|
1258
|
-
parent: null,
|
|
1259
1263
|
sibling: null,
|
|
1260
1264
|
child: null,
|
|
1261
1265
|
nativeNode: null,
|
|
@@ -1273,35 +1277,26 @@ function createRenderer(component, nativeRenderer) {
|
|
|
1273
1277
|
};
|
|
1274
1278
|
}
|
|
1275
1279
|
function buildView(nativeRenderer, parentComponent, atom, context) {
|
|
1276
|
-
|
|
1277
|
-
|
|
1280
|
+
const { jsxNode, type } = atom;
|
|
1281
|
+
if (type === 'component') {
|
|
1282
|
+
const component = new Component(parentComponent, jsxNode.type, jsxNode.props, jsxNode.key);
|
|
1278
1283
|
atom.jsxNode = component;
|
|
1279
1284
|
componentRender(nativeRenderer, component, atom, context);
|
|
1280
1285
|
}
|
|
1281
1286
|
else {
|
|
1282
1287
|
let nativeNode;
|
|
1283
1288
|
let applyRefs = null;
|
|
1284
|
-
if (
|
|
1285
|
-
const { nativeNode: n, applyRefs: a } = createElement(nativeRenderer,
|
|
1289
|
+
if (type === 'element') {
|
|
1290
|
+
const { nativeNode: n, applyRefs: a } = createElement(nativeRenderer, jsxNode, atom.isSvg);
|
|
1286
1291
|
nativeNode = n;
|
|
1287
1292
|
applyRefs = a;
|
|
1288
1293
|
}
|
|
1289
1294
|
else {
|
|
1290
|
-
nativeNode = createTextNode(nativeRenderer,
|
|
1295
|
+
nativeNode = createTextNode(nativeRenderer, jsxNode, atom.isSvg);
|
|
1291
1296
|
}
|
|
1292
1297
|
atom.nativeNode = nativeNode;
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
nativeRenderer.appendChild(context.host, nativeNode, atom.isSvg);
|
|
1296
|
-
}
|
|
1297
|
-
else {
|
|
1298
|
-
nativeRenderer.prependChild(context.host, nativeNode, atom.isSvg);
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
else {
|
|
1302
|
-
nativeRenderer.insertAfter(nativeNode, context.host, atom.isSvg);
|
|
1303
|
-
}
|
|
1304
|
-
if (atom.jsxNode instanceof JSXElement) {
|
|
1298
|
+
insertNode(nativeRenderer, atom, context);
|
|
1299
|
+
if (type === 'element') {
|
|
1305
1300
|
const childContext = {
|
|
1306
1301
|
isParent: true,
|
|
1307
1302
|
host: nativeNode,
|
|
@@ -1336,12 +1331,7 @@ function applyChanges(nativeRenderer, component) {
|
|
|
1336
1331
|
const { atom, host, isParent, rootHost } = component.$$view;
|
|
1337
1332
|
const diffAtom = atom.child;
|
|
1338
1333
|
const template = component.update(component.props, true);
|
|
1339
|
-
|
|
1340
|
-
linkTemplate(template, component, atom);
|
|
1341
|
-
}
|
|
1342
|
-
else {
|
|
1343
|
-
atom.child = null;
|
|
1344
|
-
}
|
|
1334
|
+
atom.child = createChildChain(template, atom.isSvg);
|
|
1345
1335
|
const context = {
|
|
1346
1336
|
host,
|
|
1347
1337
|
isParent,
|
|
@@ -1408,30 +1398,27 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1408
1398
|
}
|
|
1409
1399
|
function createChanges(newAtom, expectIndex, diffAtomIndexed, nativeRenderer, commits, context, parentComponent, effect) {
|
|
1410
1400
|
const startDiffAtom = diffAtomIndexed;
|
|
1411
|
-
const
|
|
1401
|
+
const { jsxNode: newJsxNode, type } = newAtom;
|
|
1402
|
+
const key = newJsxNode.key;
|
|
1412
1403
|
while (diffAtomIndexed) {
|
|
1413
1404
|
const { atom: diffAtom, index: diffIndex } = diffAtomIndexed;
|
|
1414
|
-
|
|
1415
|
-
if (key !== undefined) {
|
|
1416
|
-
if (diffKey !== key) {
|
|
1417
|
-
diffAtomIndexed = diffAtomIndexed.next;
|
|
1418
|
-
continue;
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
else if (diffKey !== undefined) {
|
|
1422
|
-
diffAtomIndexed = diffAtomIndexed.next;
|
|
1423
|
-
continue;
|
|
1424
|
-
}
|
|
1425
|
-
if (newAtom.jsxNode.$$typeOf === diffAtom.jsxNode.$$typeOf) {
|
|
1405
|
+
if (type === diffAtom.type) {
|
|
1426
1406
|
let commit;
|
|
1427
|
-
if (
|
|
1428
|
-
commit = updateElement(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context, parentComponent);
|
|
1429
|
-
}
|
|
1430
|
-
else if (newAtom.jsxNode instanceof JSXText) {
|
|
1407
|
+
if (type === 'text') {
|
|
1431
1408
|
commit = updateText(newAtom, diffAtom, nativeRenderer, context);
|
|
1432
1409
|
}
|
|
1433
1410
|
else {
|
|
1434
|
-
|
|
1411
|
+
const { key: diffKey, type: diffType } = diffAtom.jsxNode;
|
|
1412
|
+
if (diffKey !== key || newJsxNode.type !== diffType) {
|
|
1413
|
+
diffAtomIndexed = diffAtomIndexed.next;
|
|
1414
|
+
continue;
|
|
1415
|
+
}
|
|
1416
|
+
if (type === 'component') {
|
|
1417
|
+
commit = updateComponent(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context);
|
|
1418
|
+
}
|
|
1419
|
+
else {
|
|
1420
|
+
commit = updateElement(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context, parentComponent);
|
|
1421
|
+
}
|
|
1435
1422
|
}
|
|
1436
1423
|
commits.push(commit);
|
|
1437
1424
|
const next = diffAtomIndexed.next;
|
|
@@ -1463,8 +1450,8 @@ function createNewView(start, nativeRenderer, context, parentComponent, effect)
|
|
|
1463
1450
|
function updateText(newAtom, oldAtom, nativeRenderer, context) {
|
|
1464
1451
|
return function () {
|
|
1465
1452
|
const nativeNode = oldAtom.nativeNode;
|
|
1466
|
-
if (newAtom.jsxNode
|
|
1467
|
-
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode
|
|
1453
|
+
if (newAtom.jsxNode !== oldAtom.jsxNode) {
|
|
1454
|
+
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode, newAtom.isSvg);
|
|
1468
1455
|
}
|
|
1469
1456
|
newAtom.nativeNode = nativeNode;
|
|
1470
1457
|
context.host = nativeNode;
|
|
@@ -1474,19 +1461,8 @@ function updateText(newAtom, oldAtom, nativeRenderer, context) {
|
|
|
1474
1461
|
function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer, context, parentComponent) {
|
|
1475
1462
|
return function (offset) {
|
|
1476
1463
|
newAtom.nativeNode = oldAtom.nativeNode;
|
|
1477
|
-
const host = context.host;
|
|
1478
1464
|
if (expectIndex - offset !== oldIndex) {
|
|
1479
|
-
|
|
1480
|
-
if (host === context.rootHost) {
|
|
1481
|
-
nativeRenderer.appendChild(host, newAtom.nativeNode, newAtom.isSvg);
|
|
1482
|
-
}
|
|
1483
|
-
else {
|
|
1484
|
-
nativeRenderer.prependChild(host, newAtom.nativeNode, newAtom.isSvg);
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
else {
|
|
1488
|
-
nativeRenderer.insertAfter(newAtom.nativeNode, host, newAtom.isSvg);
|
|
1489
|
-
}
|
|
1465
|
+
insertNode(nativeRenderer, newAtom, context);
|
|
1490
1466
|
}
|
|
1491
1467
|
context.host = newAtom.nativeNode;
|
|
1492
1468
|
context.isParent = false;
|
|
@@ -1500,8 +1476,9 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
|
|
|
1500
1476
|
}
|
|
1501
1477
|
else if (oldAtom.child) {
|
|
1502
1478
|
let atom = oldAtom.child;
|
|
1479
|
+
nativeRenderer.cleanChildren(oldAtom.nativeNode, oldAtom.isSvg);
|
|
1503
1480
|
while (atom) {
|
|
1504
|
-
cleanView(nativeRenderer, atom,
|
|
1481
|
+
cleanView(nativeRenderer, atom, true);
|
|
1505
1482
|
atom = atom.sibling;
|
|
1506
1483
|
}
|
|
1507
1484
|
}
|
|
@@ -1524,7 +1501,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
|
|
|
1524
1501
|
return;
|
|
1525
1502
|
}
|
|
1526
1503
|
if (newTemplate) {
|
|
1527
|
-
|
|
1504
|
+
newAtom.child = createChildChain(newTemplate, newAtom.isSvg);
|
|
1528
1505
|
}
|
|
1529
1506
|
if (newAtom.child) {
|
|
1530
1507
|
diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex);
|
|
@@ -1542,12 +1519,6 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
|
|
|
1542
1519
|
function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
|
|
1543
1520
|
let child = reusedAtom.child;
|
|
1544
1521
|
newAtom.child = child;
|
|
1545
|
-
const children = [];
|
|
1546
|
-
while (child) {
|
|
1547
|
-
children.push(child);
|
|
1548
|
-
child.parent = newAtom;
|
|
1549
|
-
child = child.sibling;
|
|
1550
|
-
}
|
|
1551
1522
|
const updateContext = (atom) => {
|
|
1552
1523
|
if (atom.jsxNode instanceof Component) {
|
|
1553
1524
|
let child = atom.child;
|
|
@@ -1558,33 +1529,24 @@ function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveVi
|
|
|
1558
1529
|
}
|
|
1559
1530
|
else {
|
|
1560
1531
|
if (moveView) {
|
|
1561
|
-
|
|
1562
|
-
if (context.host === context.rootHost) {
|
|
1563
|
-
nativeRenderer.appendChild(context.host, atom.nativeNode, atom.isSvg);
|
|
1564
|
-
}
|
|
1565
|
-
else {
|
|
1566
|
-
nativeRenderer.prependChild(context.host, atom.nativeNode, atom.isSvg);
|
|
1567
|
-
}
|
|
1568
|
-
}
|
|
1569
|
-
else {
|
|
1570
|
-
nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.isSvg);
|
|
1571
|
-
}
|
|
1532
|
+
insertNode(nativeRenderer, atom, context);
|
|
1572
1533
|
}
|
|
1573
1534
|
context.isParent = false;
|
|
1574
1535
|
context.host = atom.nativeNode;
|
|
1575
1536
|
}
|
|
1576
1537
|
};
|
|
1577
|
-
|
|
1578
|
-
updateContext(
|
|
1538
|
+
while (child) {
|
|
1539
|
+
updateContext(child);
|
|
1540
|
+
child = child.sibling;
|
|
1579
1541
|
}
|
|
1580
1542
|
}
|
|
1581
|
-
function cleanView(nativeRenderer, atom,
|
|
1543
|
+
function cleanView(nativeRenderer, atom, needClean) {
|
|
1582
1544
|
if (atom.nativeNode) {
|
|
1583
|
-
if (!
|
|
1545
|
+
if (!needClean) {
|
|
1584
1546
|
nativeRenderer.remove(atom.nativeNode, atom.isSvg);
|
|
1585
|
-
|
|
1547
|
+
needClean = true;
|
|
1586
1548
|
}
|
|
1587
|
-
if (atom.
|
|
1549
|
+
if (atom.type === 'element') {
|
|
1588
1550
|
const ref = atom.jsxNode.props[refKey];
|
|
1589
1551
|
applyRefs(ref, atom.nativeNode, false);
|
|
1590
1552
|
}
|
|
@@ -1592,9 +1554,9 @@ function cleanView(nativeRenderer, atom, isClean) {
|
|
|
1592
1554
|
let child = atom.child;
|
|
1593
1555
|
while (child) {
|
|
1594
1556
|
if (child.jsxNode instanceof Component && child.jsxNode.instance.$portalHost) {
|
|
1595
|
-
|
|
1557
|
+
needClean = false;
|
|
1596
1558
|
}
|
|
1597
|
-
cleanView(nativeRenderer, child,
|
|
1559
|
+
cleanView(nativeRenderer, child, needClean);
|
|
1598
1560
|
child = child.sibling;
|
|
1599
1561
|
}
|
|
1600
1562
|
if (atom.jsxNode instanceof Component) {
|
|
@@ -1603,9 +1565,7 @@ function cleanView(nativeRenderer, atom, isClean) {
|
|
|
1603
1565
|
}
|
|
1604
1566
|
function componentRender(nativeRenderer, component, from, context) {
|
|
1605
1567
|
const { template, portalHost } = component.render();
|
|
1606
|
-
|
|
1607
|
-
linkTemplate(template, component, from);
|
|
1608
|
-
}
|
|
1568
|
+
from.child = createChildChain(template, from.isSvg);
|
|
1609
1569
|
context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
|
|
1610
1570
|
component.$$view = Object.assign({ atom: from }, context);
|
|
1611
1571
|
let child = from.child;
|
|
@@ -1615,69 +1575,89 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
1615
1575
|
}
|
|
1616
1576
|
component.rendered();
|
|
1617
1577
|
}
|
|
1618
|
-
function
|
|
1619
|
-
|
|
1578
|
+
function createChainByJSXComponent(jsxNode, prevAtom, isSvg) {
|
|
1579
|
+
const atom = {
|
|
1580
|
+
type: 'component',
|
|
1620
1581
|
jsxNode,
|
|
1621
|
-
parent,
|
|
1622
1582
|
sibling: null,
|
|
1623
1583
|
child: null,
|
|
1624
1584
|
nativeNode: null,
|
|
1625
1585
|
isSvg
|
|
1626
1586
|
};
|
|
1587
|
+
prevAtom.sibling = atom;
|
|
1588
|
+
return atom;
|
|
1627
1589
|
}
|
|
1628
|
-
function
|
|
1590
|
+
function createChainByJSXText(jsxNode, prevAtom, isSvg) {
|
|
1591
|
+
const atom = {
|
|
1592
|
+
type: 'text',
|
|
1593
|
+
jsxNode,
|
|
1594
|
+
sibling: null,
|
|
1595
|
+
child: null,
|
|
1596
|
+
nativeNode: null,
|
|
1597
|
+
isSvg
|
|
1598
|
+
};
|
|
1599
|
+
prevAtom.sibling = atom;
|
|
1600
|
+
return atom;
|
|
1601
|
+
}
|
|
1602
|
+
function createChainByJSXElement(element, prevAtom, isSvg) {
|
|
1629
1603
|
isSvg = isSvg || element.type === 'svg';
|
|
1630
1604
|
const atom = {
|
|
1605
|
+
type: 'element',
|
|
1631
1606
|
jsxNode: element,
|
|
1632
|
-
parent,
|
|
1633
1607
|
sibling: null,
|
|
1634
1608
|
child: null,
|
|
1635
1609
|
nativeNode: null,
|
|
1636
1610
|
isSvg
|
|
1637
1611
|
};
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
const children = createChainByChildren(component, Array.isArray(jsxChildren) ? jsxChildren : [jsxChildren], atom, [], isSvg);
|
|
1641
|
-
link(atom, children);
|
|
1642
|
-
}
|
|
1612
|
+
prevAtom.sibling = atom;
|
|
1613
|
+
atom.child = createChildChain(element.props.children, isSvg);
|
|
1643
1614
|
return atom;
|
|
1644
1615
|
}
|
|
1645
|
-
function
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1616
|
+
function createChainByNode(jsxNode, prevAtom, isSvg) {
|
|
1617
|
+
const type = typeof jsxNode;
|
|
1618
|
+
if (jsxNode !== null && type !== 'undefined' && type !== 'boolean') {
|
|
1619
|
+
if (typeof jsxNode === 'string') {
|
|
1620
|
+
return createChainByJSXText(jsxNode, prevAtom, isSvg);
|
|
1621
|
+
}
|
|
1622
|
+
if (Array.isArray(jsxNode)) {
|
|
1623
|
+
return createChainByChildren(jsxNode, prevAtom, isSvg);
|
|
1624
|
+
}
|
|
1625
|
+
if (type === 'object') {
|
|
1626
|
+
const nodeType = typeof jsxNode.type;
|
|
1627
|
+
if (nodeType === 'string') {
|
|
1628
|
+
return createChainByJSXElement(jsxNode, prevAtom, isSvg);
|
|
1655
1629
|
}
|
|
1656
|
-
if (
|
|
1657
|
-
|
|
1658
|
-
continue;
|
|
1630
|
+
else if (nodeType === 'function') {
|
|
1631
|
+
return createChainByJSXComponent(jsxNode, prevAtom, isSvg);
|
|
1659
1632
|
}
|
|
1660
|
-
if (item instanceof JSXComponent) {
|
|
1661
|
-
const childAtom = createChainByJSXComponentOrJSXText(item, parent, isSvg);
|
|
1662
|
-
atoms.push(childAtom);
|
|
1663
|
-
continue;
|
|
1664
|
-
}
|
|
1665
|
-
atoms.push(createChainByJSXComponentOrJSXText(new JSXText(String(item)), parent, isSvg));
|
|
1666
1633
|
}
|
|
1634
|
+
return createChainByJSXText(String(jsxNode), prevAtom, isSvg);
|
|
1635
|
+
}
|
|
1636
|
+
return prevAtom;
|
|
1637
|
+
}
|
|
1638
|
+
function createChainByChildren(children, prevAtom, isSvg) {
|
|
1639
|
+
for (const item of children) {
|
|
1640
|
+
prevAtom = createChainByNode(item, prevAtom, isSvg);
|
|
1667
1641
|
}
|
|
1668
|
-
return
|
|
1642
|
+
return prevAtom;
|
|
1669
1643
|
}
|
|
1670
|
-
function
|
|
1671
|
-
const
|
|
1672
|
-
|
|
1673
|
-
|
|
1644
|
+
function createChildChain(template, isSvg) {
|
|
1645
|
+
const beforeAtom = { sibling: null };
|
|
1646
|
+
createChainByNode(template, beforeAtom, isSvg);
|
|
1647
|
+
return beforeAtom.sibling;
|
|
1674
1648
|
}
|
|
1675
|
-
function
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1649
|
+
function insertNode(nativeRenderer, atom, context) {
|
|
1650
|
+
if (context.isParent) {
|
|
1651
|
+
if (context.host === context.rootHost) {
|
|
1652
|
+
nativeRenderer.appendChild(context.host, atom.nativeNode, atom.isSvg);
|
|
1653
|
+
}
|
|
1654
|
+
else {
|
|
1655
|
+
nativeRenderer.prependChild(context.host, atom.nativeNode, atom.isSvg);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
else {
|
|
1659
|
+
nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.isSvg);
|
|
1679
1660
|
}
|
|
1680
|
-
parent.child = children[0] || null;
|
|
1681
1661
|
}
|
|
1682
1662
|
function createElement(nativeRenderer, vNode, isSvg) {
|
|
1683
1663
|
const nativeNode = nativeRenderer.createElement(vNode.type, isSvg);
|
|
@@ -1701,7 +1681,7 @@ function createElement(nativeRenderer, vNode, isSvg) {
|
|
|
1701
1681
|
}
|
|
1702
1682
|
continue;
|
|
1703
1683
|
}
|
|
1704
|
-
if (
|
|
1684
|
+
if (listenerReg.test(key)) {
|
|
1705
1685
|
const listener = props[key];
|
|
1706
1686
|
if (typeof listener === 'function') {
|
|
1707
1687
|
bindEvent(nativeRenderer, vNode, key, nativeNode, listener, isSvg);
|
|
@@ -1721,8 +1701,8 @@ function createElement(nativeRenderer, vNode, isSvg) {
|
|
|
1721
1701
|
}
|
|
1722
1702
|
};
|
|
1723
1703
|
}
|
|
1724
|
-
function createTextNode(nativeRenderer,
|
|
1725
|
-
return nativeRenderer.createTextNode(
|
|
1704
|
+
function createTextNode(nativeRenderer, text, isSvg) {
|
|
1705
|
+
return nativeRenderer.createTextNode(text, isSvg);
|
|
1726
1706
|
}
|
|
1727
1707
|
function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNode, isSvg) {
|
|
1728
1708
|
const changes = getObjectChanges(newVNode.props, oldVNode.props);
|
|
@@ -1743,9 +1723,9 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1743
1723
|
}
|
|
1744
1724
|
continue;
|
|
1745
1725
|
}
|
|
1746
|
-
if (
|
|
1726
|
+
if (listenerReg.test(key)) {
|
|
1747
1727
|
if (typeof value === 'function') {
|
|
1748
|
-
const type = key.replace(
|
|
1728
|
+
const type = key.replace(listenerReg, '').toLowerCase();
|
|
1749
1729
|
const oldOn = oldVNode.on;
|
|
1750
1730
|
nativeRenderer.unListen(nativeNode, type, oldOn[type].delegate, isSvg);
|
|
1751
1731
|
Reflect.deleteProperty(oldOn, type);
|
|
@@ -1780,8 +1760,8 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1780
1760
|
}
|
|
1781
1761
|
continue;
|
|
1782
1762
|
}
|
|
1783
|
-
if (
|
|
1784
|
-
const listenType = key.replace(
|
|
1763
|
+
if (listenerReg.test(key)) {
|
|
1764
|
+
const listenType = key.replace(listenerReg, '').toLowerCase();
|
|
1785
1765
|
newVNode.on[listenType].listenFn = newValue;
|
|
1786
1766
|
continue;
|
|
1787
1767
|
}
|
|
@@ -1807,7 +1787,7 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1807
1787
|
}
|
|
1808
1788
|
continue;
|
|
1809
1789
|
}
|
|
1810
|
-
if (
|
|
1790
|
+
if (listenerReg.test(key)) {
|
|
1811
1791
|
if (typeof value === 'function') {
|
|
1812
1792
|
bindEvent(nativeRenderer, newVNode, key, nativeNode, value, isSvg);
|
|
1813
1793
|
}
|
|
@@ -1825,10 +1805,12 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1825
1805
|
};
|
|
1826
1806
|
}
|
|
1827
1807
|
function applyRefs(refs, nativeNode, binding) {
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1808
|
+
if (refs) {
|
|
1809
|
+
const refList = Array.isArray(refs) ? refs : [refs];
|
|
1810
|
+
for (const item of refList) {
|
|
1811
|
+
if (item instanceof DynamicRef) {
|
|
1812
|
+
binding ? item.bind(nativeNode) : item.unBind(nativeNode);
|
|
1813
|
+
}
|
|
1832
1814
|
}
|
|
1833
1815
|
}
|
|
1834
1816
|
}
|
|
@@ -1837,7 +1819,7 @@ function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn, isSvg) {
|
|
|
1837
1819
|
if (!on) {
|
|
1838
1820
|
vNode.on = on = {};
|
|
1839
1821
|
}
|
|
1840
|
-
const type = key.replace(
|
|
1822
|
+
const type = key.replace(listenerReg, '').toLowerCase();
|
|
1841
1823
|
const delegateObj = {
|
|
1842
1824
|
delegate(...args) {
|
|
1843
1825
|
return delegateObj.listenFn.apply(this, args);
|
|
@@ -1965,9 +1947,7 @@ exports.Inject = Inject;
|
|
|
1965
1947
|
exports.Injectable = Injectable;
|
|
1966
1948
|
exports.InjectionToken = InjectionToken;
|
|
1967
1949
|
exports.Injector = Injector;
|
|
1968
|
-
exports.
|
|
1969
|
-
exports.JSXElement = JSXElement;
|
|
1970
|
-
exports.JSXText = JSXText;
|
|
1950
|
+
exports.JSXNodeFactory = JSXNodeFactory;
|
|
1971
1951
|
exports.NativeRenderer = NativeRenderer;
|
|
1972
1952
|
exports.NullInjector = NullInjector;
|
|
1973
1953
|
exports.Optional = Optional;
|