@viewfly/core 1.0.0-alpha.7 → 1.0.0-alpha.9

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;
@@ -1283,6 +1283,7 @@ function withMemo(canUseMemo, render) {
1283
1283
  };
1284
1284
  }
1285
1285
 
1286
+ const componentViewCache = new WeakMap();
1286
1287
  const listenerReg = /^on(?=[A-Z])/;
1287
1288
  function createRenderer(component, nativeRenderer) {
1288
1289
  let isInit = true;
@@ -1361,7 +1362,7 @@ function updateView(nativeRenderer, component) {
1361
1362
  }
1362
1363
  }
1363
1364
  function applyChanges(nativeRenderer, component) {
1364
- const { atom, host, isParent, rootHost } = component.$$view;
1365
+ const { atom, host, isParent, rootHost } = componentViewCache.get(component);
1365
1366
  const diffAtom = atom.child;
1366
1367
  const template = component.update(component.props, true);
1367
1368
  atom.child = createChildChain(template, atom.isSvg);
@@ -1373,8 +1374,9 @@ function applyChanges(nativeRenderer, component) {
1373
1374
  diff(nativeRenderer, component, atom.child, diffAtom, context);
1374
1375
  const next = atom.sibling;
1375
1376
  if (next && next.jsxNode instanceof Component) {
1376
- next.jsxNode.$$view.host = context.host;
1377
- next.jsxNode.$$view.isParent = context.isParent;
1377
+ const view = componentViewCache.get(next.jsxNode);
1378
+ view.host = context.host;
1379
+ view.isParent = context.isParent;
1378
1380
  }
1379
1381
  }
1380
1382
  function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
@@ -1470,6 +1472,10 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
1470
1472
  }
1471
1473
  context.host = newAtom.nativeNode;
1472
1474
  context.isParent = false;
1475
+ if (newAtom.jsxNode === oldAtom.jsxNode) {
1476
+ newAtom.child = oldAtom.child;
1477
+ return;
1478
+ }
1473
1479
  const applyRefs = updateNativeNodeProperties(nativeRenderer, newAtom.jsxNode, oldAtom.jsxNode, newAtom.nativeNode, newAtom.isSvg);
1474
1480
  if (newAtom.child) {
1475
1481
  diff(nativeRenderer, parentComponent, newAtom.child, oldAtom.child, {
@@ -1497,7 +1503,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
1497
1503
  const newTemplate = component.update(newProps);
1498
1504
  const portalHost = component.instance.$portalHost;
1499
1505
  context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
1500
- component.$$view = Object.assign({ atom: newAtom }, context);
1506
+ componentViewCache.set(component, Object.assign({ atom: newAtom }, context));
1501
1507
  newAtom.jsxNode = component;
1502
1508
  if (newTemplate === oldTemplate) {
1503
1509
  reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
@@ -1571,7 +1577,7 @@ function componentRender(nativeRenderer, component, from, context) {
1571
1577
  const { template, portalHost } = component.render();
1572
1578
  from.child = createChildChain(template, from.isSvg);
1573
1579
  context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
1574
- component.$$view = Object.assign({ atom: from }, context);
1580
+ componentViewCache.set(component, Object.assign({ atom: from }, context));
1575
1581
  let child = from.child;
1576
1582
  while (child) {
1577
1583
  buildView(nativeRenderer, component, child, context);
@@ -1618,7 +1624,6 @@ function createChainByJSXElement(element, prevAtom, isSvg) {
1618
1624
  };
1619
1625
  prevAtom.sibling = atom;
1620
1626
  atom.child = createChildChain(element.props.children, isSvg);
1621
- element.props.children = null;
1622
1627
  return atom;
1623
1628
  }
1624
1629
  function createChainByNode(jsxNode, prevAtom, isSvg) {
package/bundles/index.js CHANGED
@@ -1285,6 +1285,7 @@ function withMemo(canUseMemo, render) {
1285
1285
  };
1286
1286
  }
1287
1287
 
1288
+ const componentViewCache = new WeakMap();
1288
1289
  const listenerReg = /^on(?=[A-Z])/;
1289
1290
  function createRenderer(component, nativeRenderer) {
1290
1291
  let isInit = true;
@@ -1363,7 +1364,7 @@ function updateView(nativeRenderer, component) {
1363
1364
  }
1364
1365
  }
1365
1366
  function applyChanges(nativeRenderer, component) {
1366
- const { atom, host, isParent, rootHost } = component.$$view;
1367
+ const { atom, host, isParent, rootHost } = componentViewCache.get(component);
1367
1368
  const diffAtom = atom.child;
1368
1369
  const template = component.update(component.props, true);
1369
1370
  atom.child = createChildChain(template, atom.isSvg);
@@ -1375,8 +1376,9 @@ function applyChanges(nativeRenderer, component) {
1375
1376
  diff(nativeRenderer, component, atom.child, diffAtom, context);
1376
1377
  const next = atom.sibling;
1377
1378
  if (next && next.jsxNode instanceof Component) {
1378
- next.jsxNode.$$view.host = context.host;
1379
- next.jsxNode.$$view.isParent = context.isParent;
1379
+ const view = componentViewCache.get(next.jsxNode);
1380
+ view.host = context.host;
1381
+ view.isParent = context.isParent;
1380
1382
  }
1381
1383
  }
1382
1384
  function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
@@ -1472,6 +1474,10 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
1472
1474
  }
1473
1475
  context.host = newAtom.nativeNode;
1474
1476
  context.isParent = false;
1477
+ if (newAtom.jsxNode === oldAtom.jsxNode) {
1478
+ newAtom.child = oldAtom.child;
1479
+ return;
1480
+ }
1475
1481
  const applyRefs = updateNativeNodeProperties(nativeRenderer, newAtom.jsxNode, oldAtom.jsxNode, newAtom.nativeNode, newAtom.isSvg);
1476
1482
  if (newAtom.child) {
1477
1483
  diff(nativeRenderer, parentComponent, newAtom.child, oldAtom.child, {
@@ -1499,7 +1505,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
1499
1505
  const newTemplate = component.update(newProps);
1500
1506
  const portalHost = component.instance.$portalHost;
1501
1507
  context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
1502
- component.$$view = Object.assign({ atom: newAtom }, context);
1508
+ componentViewCache.set(component, Object.assign({ atom: newAtom }, context));
1503
1509
  newAtom.jsxNode = component;
1504
1510
  if (newTemplate === oldTemplate) {
1505
1511
  reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
@@ -1573,7 +1579,7 @@ function componentRender(nativeRenderer, component, from, context) {
1573
1579
  const { template, portalHost } = component.render();
1574
1580
  from.child = createChildChain(template, from.isSvg);
1575
1581
  context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
1576
- component.$$view = Object.assign({ atom: from }, context);
1582
+ componentViewCache.set(component, Object.assign({ atom: from }, context));
1577
1583
  let child = from.child;
1578
1584
  while (child) {
1579
1585
  buildView(nativeRenderer, component, child, context);
@@ -1620,7 +1626,6 @@ function createChainByJSXElement(element, prevAtom, isSvg) {
1620
1626
  };
1621
1627
  prevAtom.sibling = atom;
1622
1628
  atom.child = createChildChain(element.props.children, isSvg);
1623
- element.props.children = null;
1624
1629
  return atom;
1625
1630
  }
1626
1631
  function createChainByNode(jsxNode, prevAtom, isSvg) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "1.0.0-alpha.7",
3
+ "version": "1.0.0-alpha.9",
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": "092e986d74477afb6246001ca58962172f926e73",
50
+ "gitHead": "b8e4c0fb9e3b7854bcc26aa995140cb18a55af08",
51
51
  "dependencies": {
52
52
  "reflect-metadata": "^0.2.2"
53
53
  }