@viewfly/core 1.0.0-alpha.6 → 1.0.0-alpha.8

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.
@@ -1,6 +1,5 @@
1
1
  import { AbstractType, ExtractValueType, InjectFlags, InjectionToken, Injector, Provider, ReflectiveInjector, Type } from '../di/_api';
2
2
  import { Key, Props } from './jsx-element';
3
- import { ComponentView } from './_utils';
4
3
  /**
5
4
  * Viewfly 组件管理类,用于管理组件的生命周期,上下文等
6
5
  */
@@ -14,7 +13,6 @@ export declare class Component extends ReflectiveInjector {
14
13
  changedSubComponents: Set<Component>;
15
14
  get dirty(): boolean;
16
15
  get changed(): boolean;
17
- $$view: ComponentView;
18
16
  unmountedCallbacks?: LifeCycleCallback[] | null;
19
17
  mountCallbacks?: LifeCycleCallback[] | null;
20
18
  propsChangedCallbacks?: PropsChangedCallback<any>[] | null;
@@ -591,13 +591,13 @@ function getArrayChanges(left, right) {
591
591
  return changes;
592
592
  }
593
593
  function classToString(config) {
594
- if (!config) {
595
- return '';
596
- }
597
594
  if (typeof config === 'string') {
598
595
  return config;
599
596
  }
600
- else if (Array.isArray(config)) {
597
+ if (!config) {
598
+ return '';
599
+ }
600
+ if (Array.isArray(config)) {
601
601
  const classes = [];
602
602
  for (const i of config) {
603
603
  const v = classToString(i);
@@ -607,7 +607,7 @@ function classToString(config) {
607
607
  }
608
608
  return classes.join(' ');
609
609
  }
610
- else if (typeof config === 'object') {
610
+ if (typeof config === 'object') {
611
611
  if (config.toString !== Object.prototype.toString && !config.toString.toString().includes('[native code]')) {
612
612
  return config.toString();
613
613
  }
@@ -741,30 +741,32 @@ class Component extends ReflectiveInjector {
741
741
  };
742
742
  }
743
743
  update(newProps, forceUpdate = false) {
744
- const oldProps = this.props;
745
- const { add, remove, replace } = getObjectChanges(newProps, this.props);
746
- if (add.length || remove.length || replace.length) {
747
- this.invokePropsChangedHooks(newProps);
748
- }
749
- else if (!this.dirty) {
750
- return this.template;
751
- }
752
- const newRefs = toRefs(newProps.ref);
753
- if (this.refs) {
754
- for (const oldRef of this.refs) {
755
- if (!newRefs.includes(oldRef)) {
756
- oldRef.unBind(this.instance);
744
+ if (!forceUpdate) {
745
+ const { add, remove, replace } = getObjectChanges(newProps, this.props);
746
+ if (add.length || remove.length || replace.length) {
747
+ this.invokePropsChangedHooks(newProps);
748
+ }
749
+ else if (!this.dirty) {
750
+ this.props = newProps;
751
+ return this.template;
752
+ }
753
+ const newRefs = toRefs(newProps.ref);
754
+ if (this.refs) {
755
+ for (const oldRef of this.refs) {
756
+ if (!newRefs.includes(oldRef)) {
757
+ oldRef.unBind(this.instance);
758
+ }
757
759
  }
758
760
  }
761
+ for (const newRef of newRefs) {
762
+ newRef.bind(this.instance);
763
+ }
764
+ if (newRefs.length) {
765
+ this.refs = newRefs;
766
+ }
759
767
  }
760
- for (const newRef of newRefs) {
761
- newRef.bind(this.instance);
762
- }
763
- if (newRefs.length) {
764
- this.refs = newRefs;
765
- }
766
- if (!forceUpdate && typeof this.instance.$useMemo === 'function') {
767
- if (this.instance.$useMemo(newProps, oldProps)) {
768
+ if (typeof this.instance.$useMemo === 'function') {
769
+ if (this.instance.$useMemo(newProps, this.props)) {
768
770
  return this.template;
769
771
  }
770
772
  }
@@ -1281,6 +1283,7 @@ function withMemo(canUseMemo, render) {
1281
1283
  };
1282
1284
  }
1283
1285
 
1286
+ const componentViewCache = new WeakMap();
1284
1287
  const listenerReg = /^on(?=[A-Z])/;
1285
1288
  function createRenderer(component, nativeRenderer) {
1286
1289
  let isInit = true;
@@ -1359,7 +1362,7 @@ function updateView(nativeRenderer, component) {
1359
1362
  }
1360
1363
  }
1361
1364
  function applyChanges(nativeRenderer, component) {
1362
- const { atom, host, isParent, rootHost } = component.$$view;
1365
+ const { atom, host, isParent, rootHost } = componentViewCache.get(component);
1363
1366
  const diffAtom = atom.child;
1364
1367
  const template = component.update(component.props, true);
1365
1368
  atom.child = createChildChain(template, atom.isSvg);
@@ -1371,8 +1374,9 @@ function applyChanges(nativeRenderer, component) {
1371
1374
  diff(nativeRenderer, component, atom.child, diffAtom, context);
1372
1375
  const next = atom.sibling;
1373
1376
  if (next && next.jsxNode instanceof Component) {
1374
- next.jsxNode.$$view.host = context.host;
1375
- next.jsxNode.$$view.isParent = context.isParent;
1377
+ const view = componentViewCache.get(next.jsxNode);
1378
+ view.host = context.host;
1379
+ view.isParent = context.isParent;
1376
1380
  }
1377
1381
  }
1378
1382
  function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
@@ -1386,7 +1390,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1386
1390
  }
1387
1391
  let dirtyDiffAtom = oldAtom;
1388
1392
  while (dirtyDiffAtom) {
1389
- cleanView(nativeRenderer, dirtyDiffAtom, false);
1393
+ cleanView(nativeRenderer, dirtyDiffAtom, true);
1390
1394
  dirtyDiffAtom = dirtyDiffAtom.sibling;
1391
1395
  }
1392
1396
  let offset = 0;
@@ -1480,7 +1484,7 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
1480
1484
  let atom = oldAtom.child;
1481
1485
  nativeRenderer.cleanChildren(oldAtom.nativeNode, oldAtom.isSvg);
1482
1486
  while (atom) {
1483
- cleanView(nativeRenderer, atom, true);
1487
+ cleanView(nativeRenderer, atom, false);
1484
1488
  atom = atom.sibling;
1485
1489
  }
1486
1490
  }
@@ -1495,7 +1499,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
1495
1499
  const newTemplate = component.update(newProps);
1496
1500
  const portalHost = component.instance.$portalHost;
1497
1501
  context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
1498
- component.$$view = Object.assign({ atom: newAtom }, context);
1502
+ componentViewCache.set(component, Object.assign({ atom: newAtom }, context));
1499
1503
  newAtom.jsxNode = component;
1500
1504
  if (newTemplate === oldTemplate) {
1501
1505
  reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
@@ -1511,7 +1515,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
1511
1515
  else if (reusedAtom.child) {
1512
1516
  let atom = reusedAtom.child;
1513
1517
  while (atom) {
1514
- cleanView(nativeRenderer, atom, false);
1518
+ cleanView(nativeRenderer, atom, true);
1515
1519
  atom = atom.sibling;
1516
1520
  }
1517
1521
  }
@@ -1544,9 +1548,9 @@ function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveVi
1544
1548
  }
1545
1549
  function cleanView(nativeRenderer, atom, needClean) {
1546
1550
  if (atom.nativeNode) {
1547
- if (!needClean) {
1551
+ if (needClean) {
1548
1552
  nativeRenderer.remove(atom.nativeNode, atom.isSvg);
1549
- needClean = true;
1553
+ needClean = false;
1550
1554
  }
1551
1555
  if (atom.type === 'element') {
1552
1556
  const ref = atom.jsxNode.props[refKey];
@@ -1556,7 +1560,7 @@ function cleanView(nativeRenderer, atom, needClean) {
1556
1560
  let child = atom.child;
1557
1561
  while (child) {
1558
1562
  if (child.jsxNode instanceof Component && child.jsxNode.instance.$portalHost) {
1559
- needClean = false;
1563
+ needClean = true;
1560
1564
  }
1561
1565
  cleanView(nativeRenderer, child, needClean);
1562
1566
  child = child.sibling;
@@ -1569,7 +1573,7 @@ function componentRender(nativeRenderer, component, from, context) {
1569
1573
  const { template, portalHost } = component.render();
1570
1574
  from.child = createChildChain(template, from.isSvg);
1571
1575
  context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
1572
- component.$$view = Object.assign({ atom: from }, context);
1576
+ componentViewCache.set(component, Object.assign({ atom: from }, context));
1573
1577
  let child = from.child;
1574
1578
  while (child) {
1575
1579
  buildView(nativeRenderer, component, child, context);
package/bundles/index.js CHANGED
@@ -593,13 +593,13 @@ function getArrayChanges(left, right) {
593
593
  return changes;
594
594
  }
595
595
  function classToString(config) {
596
- if (!config) {
597
- return '';
598
- }
599
596
  if (typeof config === 'string') {
600
597
  return config;
601
598
  }
602
- else if (Array.isArray(config)) {
599
+ if (!config) {
600
+ return '';
601
+ }
602
+ if (Array.isArray(config)) {
603
603
  const classes = [];
604
604
  for (const i of config) {
605
605
  const v = classToString(i);
@@ -609,7 +609,7 @@ function classToString(config) {
609
609
  }
610
610
  return classes.join(' ');
611
611
  }
612
- else if (typeof config === 'object') {
612
+ if (typeof config === 'object') {
613
613
  if (config.toString !== Object.prototype.toString && !config.toString.toString().includes('[native code]')) {
614
614
  return config.toString();
615
615
  }
@@ -743,30 +743,32 @@ class Component extends ReflectiveInjector {
743
743
  };
744
744
  }
745
745
  update(newProps, forceUpdate = false) {
746
- const oldProps = this.props;
747
- const { add, remove, replace } = getObjectChanges(newProps, this.props);
748
- if (add.length || remove.length || replace.length) {
749
- this.invokePropsChangedHooks(newProps);
750
- }
751
- else if (!this.dirty) {
752
- return this.template;
753
- }
754
- const newRefs = toRefs(newProps.ref);
755
- if (this.refs) {
756
- for (const oldRef of this.refs) {
757
- if (!newRefs.includes(oldRef)) {
758
- oldRef.unBind(this.instance);
746
+ if (!forceUpdate) {
747
+ const { add, remove, replace } = getObjectChanges(newProps, this.props);
748
+ if (add.length || remove.length || replace.length) {
749
+ this.invokePropsChangedHooks(newProps);
750
+ }
751
+ else if (!this.dirty) {
752
+ this.props = newProps;
753
+ return this.template;
754
+ }
755
+ const newRefs = toRefs(newProps.ref);
756
+ if (this.refs) {
757
+ for (const oldRef of this.refs) {
758
+ if (!newRefs.includes(oldRef)) {
759
+ oldRef.unBind(this.instance);
760
+ }
759
761
  }
760
762
  }
763
+ for (const newRef of newRefs) {
764
+ newRef.bind(this.instance);
765
+ }
766
+ if (newRefs.length) {
767
+ this.refs = newRefs;
768
+ }
761
769
  }
762
- for (const newRef of newRefs) {
763
- newRef.bind(this.instance);
764
- }
765
- if (newRefs.length) {
766
- this.refs = newRefs;
767
- }
768
- if (!forceUpdate && typeof this.instance.$useMemo === 'function') {
769
- if (this.instance.$useMemo(newProps, oldProps)) {
770
+ if (typeof this.instance.$useMemo === 'function') {
771
+ if (this.instance.$useMemo(newProps, this.props)) {
770
772
  return this.template;
771
773
  }
772
774
  }
@@ -1283,6 +1285,7 @@ function withMemo(canUseMemo, render) {
1283
1285
  };
1284
1286
  }
1285
1287
 
1288
+ const componentViewCache = new WeakMap();
1286
1289
  const listenerReg = /^on(?=[A-Z])/;
1287
1290
  function createRenderer(component, nativeRenderer) {
1288
1291
  let isInit = true;
@@ -1361,7 +1364,7 @@ function updateView(nativeRenderer, component) {
1361
1364
  }
1362
1365
  }
1363
1366
  function applyChanges(nativeRenderer, component) {
1364
- const { atom, host, isParent, rootHost } = component.$$view;
1367
+ const { atom, host, isParent, rootHost } = componentViewCache.get(component);
1365
1368
  const diffAtom = atom.child;
1366
1369
  const template = component.update(component.props, true);
1367
1370
  atom.child = createChildChain(template, atom.isSvg);
@@ -1373,8 +1376,9 @@ function applyChanges(nativeRenderer, component) {
1373
1376
  diff(nativeRenderer, component, atom.child, diffAtom, context);
1374
1377
  const next = atom.sibling;
1375
1378
  if (next && next.jsxNode instanceof Component) {
1376
- next.jsxNode.$$view.host = context.host;
1377
- next.jsxNode.$$view.isParent = context.isParent;
1379
+ const view = componentViewCache.get(next.jsxNode);
1380
+ view.host = context.host;
1381
+ view.isParent = context.isParent;
1378
1382
  }
1379
1383
  }
1380
1384
  function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
@@ -1388,7 +1392,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1388
1392
  }
1389
1393
  let dirtyDiffAtom = oldAtom;
1390
1394
  while (dirtyDiffAtom) {
1391
- cleanView(nativeRenderer, dirtyDiffAtom, false);
1395
+ cleanView(nativeRenderer, dirtyDiffAtom, true);
1392
1396
  dirtyDiffAtom = dirtyDiffAtom.sibling;
1393
1397
  }
1394
1398
  let offset = 0;
@@ -1482,7 +1486,7 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
1482
1486
  let atom = oldAtom.child;
1483
1487
  nativeRenderer.cleanChildren(oldAtom.nativeNode, oldAtom.isSvg);
1484
1488
  while (atom) {
1485
- cleanView(nativeRenderer, atom, true);
1489
+ cleanView(nativeRenderer, atom, false);
1486
1490
  atom = atom.sibling;
1487
1491
  }
1488
1492
  }
@@ -1497,7 +1501,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
1497
1501
  const newTemplate = component.update(newProps);
1498
1502
  const portalHost = component.instance.$portalHost;
1499
1503
  context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
1500
- component.$$view = Object.assign({ atom: newAtom }, context);
1504
+ componentViewCache.set(component, Object.assign({ atom: newAtom }, context));
1501
1505
  newAtom.jsxNode = component;
1502
1506
  if (newTemplate === oldTemplate) {
1503
1507
  reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
@@ -1513,7 +1517,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
1513
1517
  else if (reusedAtom.child) {
1514
1518
  let atom = reusedAtom.child;
1515
1519
  while (atom) {
1516
- cleanView(nativeRenderer, atom, false);
1520
+ cleanView(nativeRenderer, atom, true);
1517
1521
  atom = atom.sibling;
1518
1522
  }
1519
1523
  }
@@ -1546,9 +1550,9 @@ function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveVi
1546
1550
  }
1547
1551
  function cleanView(nativeRenderer, atom, needClean) {
1548
1552
  if (atom.nativeNode) {
1549
- if (!needClean) {
1553
+ if (needClean) {
1550
1554
  nativeRenderer.remove(atom.nativeNode, atom.isSvg);
1551
- needClean = true;
1555
+ needClean = false;
1552
1556
  }
1553
1557
  if (atom.type === 'element') {
1554
1558
  const ref = atom.jsxNode.props[refKey];
@@ -1558,7 +1562,7 @@ function cleanView(nativeRenderer, atom, needClean) {
1558
1562
  let child = atom.child;
1559
1563
  while (child) {
1560
1564
  if (child.jsxNode instanceof Component && child.jsxNode.instance.$portalHost) {
1561
- needClean = false;
1565
+ needClean = true;
1562
1566
  }
1563
1567
  cleanView(nativeRenderer, child, needClean);
1564
1568
  child = child.sibling;
@@ -1571,7 +1575,7 @@ function componentRender(nativeRenderer, component, from, context) {
1571
1575
  const { template, portalHost } = component.render();
1572
1576
  from.child = createChildChain(template, from.isSvg);
1573
1577
  context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
1574
- component.$$view = Object.assign({ atom: from }, context);
1578
+ componentViewCache.set(component, Object.assign({ atom: from }, context));
1575
1579
  let child = from.child;
1576
1580
  while (child) {
1577
1581
  buildView(nativeRenderer, component, child, context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.8",
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",
@@ -47,7 +47,7 @@
47
47
  "bugs": {
48
48
  "url": "https://github.com/viewfly/viewfly.git/issues"
49
49
  },
50
- "gitHead": "f92d3c923b1b9f115b928bc57f4d8adf1f8100c9",
50
+ "gitHead": "95538a571b0d2e8a96dbfdc940959605ea06c252",
51
51
  "dependencies": {
52
52
  "reflect-metadata": "^0.2.2"
53
53
  }