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