@viewfly/core 0.0.25 → 0.0.26

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.
@@ -22,5 +22,7 @@ export interface Atom {
22
22
  export interface ComponentView {
23
23
  atom: Atom;
24
24
  template: JSXInternal.JSXNode;
25
+ host: NativeNode;
26
+ isParent: boolean;
25
27
  render(newProps: Props, oldProps: Props): JSXInternal.JSXNode;
26
28
  }
@@ -21,6 +21,7 @@ export declare class Component extends ReflectiveInjector implements JSXTypeof {
21
21
  mountCallbacks: LifeCycleCallback[];
22
22
  propsChangedCallbacks: PropsChangedCallback<any>[];
23
23
  updatedCallbacks: LifeCycleCallback[];
24
+ changedSubComponents: Set<Component>;
24
25
  get dirty(): boolean;
25
26
  get changed(): boolean;
26
27
  protected _dirty: boolean;
@@ -38,7 +39,7 @@ export declare class Component extends ReflectiveInjector implements JSXTypeof {
38
39
  render: (newProps: Props, oldProps: Props) => any;
39
40
  };
40
41
  markAsDirtied(): void;
41
- markAsChanged(): void;
42
+ markAsChanged(changedComponent?: Component): void;
42
43
  rendered(): void;
43
44
  destroy(): void;
44
45
  private invokePropsChangedHooks;
@@ -13,9 +13,7 @@ export declare class Renderer {
13
13
  private isInit;
14
14
  constructor(nativeRenderer: NativeRenderer, rootComponentRef: RootComponentRef, hostRef: HostRef);
15
15
  render(): void;
16
- private reconcile;
17
- private getPrevSibling;
18
- private reconcileElement;
16
+ private updateView;
19
17
  private applyChanges;
20
18
  private diff;
21
19
  private reuseComponentView;
@@ -7,5 +7,5 @@ import { Injector } from '../di/_api';
7
7
  export declare class RootComponent extends Component {
8
8
  onChange: (() => void) | null;
9
9
  constructor(factory: JSXInternal.ComponentConstructor, parentInjector: Injector);
10
- markAsChanged(): void;
10
+ markAsChanged(changedComponent?: Component): void;
11
11
  }
@@ -660,6 +660,7 @@ class Component extends ReflectiveInjector {
660
660
  this.mountCallbacks = [];
661
661
  this.propsChangedCallbacks = [];
662
662
  this.updatedCallbacks = [];
663
+ this.changedSubComponents = new Set();
663
664
  this._dirty = true;
664
665
  this._changed = true;
665
666
  this.updatedDestroyCallbacks = [];
@@ -755,14 +756,18 @@ class Component extends ReflectiveInjector {
755
756
  this._dirty = true;
756
757
  this.markAsChanged();
757
758
  }
758
- markAsChanged() {
759
+ markAsChanged(changedComponent) {
760
+ if (changedComponent) {
761
+ this.changedSubComponents.add(changedComponent);
762
+ }
759
763
  if (this._changed) {
760
764
  return;
761
765
  }
762
766
  this._changed = true;
763
- this.parentComponent.markAsChanged();
767
+ this.parentComponent.markAsChanged(this);
764
768
  }
765
769
  rendered() {
770
+ this.changedSubComponents.clear();
766
771
  const is = this.isFirstRending;
767
772
  this.isFirstRending = false;
768
773
  this._dirty = this._changed = false;
@@ -1163,9 +1168,12 @@ class RootComponent extends Component {
1163
1168
  super(parentInjector, factory, {});
1164
1169
  this.onChange = null;
1165
1170
  }
1166
- markAsChanged() {
1171
+ markAsChanged(changedComponent) {
1167
1172
  var _a;
1168
1173
  this._changed = true;
1174
+ if (changedComponent) {
1175
+ this.changedSubComponents.add(changedComponent);
1176
+ }
1169
1177
  (_a = this.onChange) === null || _a === void 0 ? void 0 : _a.call(this);
1170
1178
  }
1171
1179
  }
@@ -1234,75 +1242,24 @@ let Renderer = class Renderer {
1234
1242
  });
1235
1243
  }
1236
1244
  else {
1237
- this.reconcile(component, {
1238
- host,
1239
- isParent: true
1240
- });
1245
+ this.updateView(component);
1241
1246
  }
1242
1247
  this.isInit = false;
1243
1248
  }
1244
- reconcile(component, context) {
1249
+ updateView(component) {
1245
1250
  if (component.dirty) {
1246
- this.applyChanges(component, context);
1251
+ this.applyChanges(component);
1247
1252
  component.rendered();
1248
1253
  }
1249
1254
  else if (component.changed) {
1250
- const atom = component.$$view.atom.child;
1251
- this.reconcileElement(atom, context);
1255
+ component.changedSubComponents.forEach(child => {
1256
+ this.updateView(child);
1257
+ });
1252
1258
  component.rendered();
1253
1259
  }
1254
- else {
1255
- const prevSibling = this.getPrevSibling(component);
1256
- if (prevSibling) {
1257
- context.isParent = false;
1258
- context.host = prevSibling;
1259
- }
1260
- }
1261
- }
1262
- getPrevSibling(component) {
1263
- let atom = component.$$view.atom.child;
1264
- const childAtoms = [];
1265
- while (atom) {
1266
- childAtoms.push(atom);
1267
- atom = atom.sibling;
1268
- }
1269
- const components = [];
1270
- while (childAtoms.length) {
1271
- const last = childAtoms.pop();
1272
- if (last.jsxNode instanceof Component) {
1273
- components.push(last.jsxNode);
1274
- continue;
1275
- }
1276
- return last.nativeNode;
1277
- }
1278
- for (const component of components) {
1279
- const nativeNode = this.getPrevSibling(component);
1280
- if (nativeNode) {
1281
- return nativeNode;
1282
- }
1283
- }
1284
- return null;
1285
- }
1286
- reconcileElement(atom, context) {
1287
- while (atom) {
1288
- if (atom.jsxNode instanceof Component) {
1289
- this.reconcile(atom.jsxNode, context);
1290
- atom = atom.sibling;
1291
- continue;
1292
- }
1293
- if (atom.jsxNode instanceof JSXElement) {
1294
- this.reconcileElement(atom.child, {
1295
- host: atom.nativeNode,
1296
- isParent: true
1297
- });
1298
- context.host = atom.nativeNode;
1299
- context.isParent = false;
1300
- }
1301
- atom = atom.sibling;
1302
- }
1303
1260
  }
1304
- applyChanges(component, context) {
1305
- const { atom, render } = component.$$view;
1261
+ applyChanges(component) {
1262
+ const { atom, render, host, isParent } = component.$$view;
1306
1263
  const diffAtom = atom.child;
1307
1264
  const template = render(component.props, component.props);
1308
1265
  if (template) {
@@ -1311,7 +1268,10 @@ let Renderer = class Renderer {
1311
1268
  else {
1312
1269
  atom.child = null;
1313
1270
  }
1314
- this.diff(atom.child, diffAtom, context, 0, 0);
1271
+ this.diff(atom.child, diffAtom, {
1272
+ host,
1273
+ isParent
1274
+ }, 0, 0);
1315
1275
  }
1316
1276
  diff(newAtom, oldAtom, context, expectIndex, index) {
1317
1277
  const oldChildren = [];
@@ -1332,11 +1292,7 @@ let Renderer = class Renderer {
1332
1292
  const oldProps = reusedAtom.jsxNode.props;
1333
1293
  newAtom.jsxNode = reusedAtom.jsxNode;
1334
1294
  const newTemplate = render(newProps, oldProps);
1335
- newAtom.jsxNode.$$view = {
1336
- render,
1337
- template: newTemplate,
1338
- atom: newAtom
1339
- };
1295
+ newAtom.jsxNode.$$view = Object.assign({ render, template: newTemplate, atom: newAtom }, context);
1340
1296
  if (newTemplate === template) {
1341
1297
  this.reuseComponentView(newAtom, reusedAtom, context, expectIndex !== diffIndex - offset);
1342
1298
  return;
@@ -1512,7 +1468,7 @@ let Renderer = class Renderer {
1512
1468
  }
1513
1469
  buildView(atom, context) {
1514
1470
  if (atom.jsxNode instanceof Component) {
1515
- this.componentRender(atom.jsxNode, atom);
1471
+ this.componentRender(atom.jsxNode, atom, context);
1516
1472
  let child = atom.child;
1517
1473
  while (child) {
1518
1474
  this.buildView(child, context);
@@ -1556,16 +1512,13 @@ let Renderer = class Renderer {
1556
1512
  }
1557
1513
  }
1558
1514
  }
1559
- componentRender(component, from) {
1515
+ componentRender(component, from, context) {
1560
1516
  const { template, render } = component.setup();
1561
1517
  if (template) {
1562
1518
  this.linkTemplate(template, component, from);
1563
1519
  }
1564
- component.$$view = {
1565
- render,
1566
- template,
1567
- atom: from
1568
- };
1520
+ component.$$view = Object.assign({ render,
1521
+ template, atom: from }, context);
1569
1522
  return from;
1570
1523
  }
1571
1524
  createChainByComponentFactory(context, factory, parent) {
package/bundles/index.js CHANGED
@@ -662,6 +662,7 @@ class Component extends ReflectiveInjector {
662
662
  this.mountCallbacks = [];
663
663
  this.propsChangedCallbacks = [];
664
664
  this.updatedCallbacks = [];
665
+ this.changedSubComponents = new Set();
665
666
  this._dirty = true;
666
667
  this._changed = true;
667
668
  this.updatedDestroyCallbacks = [];
@@ -757,14 +758,18 @@ class Component extends ReflectiveInjector {
757
758
  this._dirty = true;
758
759
  this.markAsChanged();
759
760
  }
760
- markAsChanged() {
761
+ markAsChanged(changedComponent) {
762
+ if (changedComponent) {
763
+ this.changedSubComponents.add(changedComponent);
764
+ }
761
765
  if (this._changed) {
762
766
  return;
763
767
  }
764
768
  this._changed = true;
765
- this.parentComponent.markAsChanged();
769
+ this.parentComponent.markAsChanged(this);
766
770
  }
767
771
  rendered() {
772
+ this.changedSubComponents.clear();
768
773
  const is = this.isFirstRending;
769
774
  this.isFirstRending = false;
770
775
  this._dirty = this._changed = false;
@@ -1165,9 +1170,12 @@ class RootComponent extends Component {
1165
1170
  super(parentInjector, factory, {});
1166
1171
  this.onChange = null;
1167
1172
  }
1168
- markAsChanged() {
1173
+ markAsChanged(changedComponent) {
1169
1174
  var _a;
1170
1175
  this._changed = true;
1176
+ if (changedComponent) {
1177
+ this.changedSubComponents.add(changedComponent);
1178
+ }
1171
1179
  (_a = this.onChange) === null || _a === void 0 ? void 0 : _a.call(this);
1172
1180
  }
1173
1181
  }
@@ -1236,75 +1244,24 @@ exports.Renderer = class Renderer {
1236
1244
  });
1237
1245
  }
1238
1246
  else {
1239
- this.reconcile(component, {
1240
- host,
1241
- isParent: true
1242
- });
1247
+ this.updateView(component);
1243
1248
  }
1244
1249
  this.isInit = false;
1245
1250
  }
1246
- reconcile(component, context) {
1251
+ updateView(component) {
1247
1252
  if (component.dirty) {
1248
- this.applyChanges(component, context);
1253
+ this.applyChanges(component);
1249
1254
  component.rendered();
1250
1255
  }
1251
1256
  else if (component.changed) {
1252
- const atom = component.$$view.atom.child;
1253
- this.reconcileElement(atom, context);
1257
+ component.changedSubComponents.forEach(child => {
1258
+ this.updateView(child);
1259
+ });
1254
1260
  component.rendered();
1255
1261
  }
1256
- else {
1257
- const prevSibling = this.getPrevSibling(component);
1258
- if (prevSibling) {
1259
- context.isParent = false;
1260
- context.host = prevSibling;
1261
- }
1262
- }
1263
- }
1264
- getPrevSibling(component) {
1265
- let atom = component.$$view.atom.child;
1266
- const childAtoms = [];
1267
- while (atom) {
1268
- childAtoms.push(atom);
1269
- atom = atom.sibling;
1270
- }
1271
- const components = [];
1272
- while (childAtoms.length) {
1273
- const last = childAtoms.pop();
1274
- if (last.jsxNode instanceof Component) {
1275
- components.push(last.jsxNode);
1276
- continue;
1277
- }
1278
- return last.nativeNode;
1279
- }
1280
- for (const component of components) {
1281
- const nativeNode = this.getPrevSibling(component);
1282
- if (nativeNode) {
1283
- return nativeNode;
1284
- }
1285
- }
1286
- return null;
1287
- }
1288
- reconcileElement(atom, context) {
1289
- while (atom) {
1290
- if (atom.jsxNode instanceof Component) {
1291
- this.reconcile(atom.jsxNode, context);
1292
- atom = atom.sibling;
1293
- continue;
1294
- }
1295
- if (atom.jsxNode instanceof JSXElement) {
1296
- this.reconcileElement(atom.child, {
1297
- host: atom.nativeNode,
1298
- isParent: true
1299
- });
1300
- context.host = atom.nativeNode;
1301
- context.isParent = false;
1302
- }
1303
- atom = atom.sibling;
1304
- }
1305
1262
  }
1306
- applyChanges(component, context) {
1307
- const { atom, render } = component.$$view;
1263
+ applyChanges(component) {
1264
+ const { atom, render, host, isParent } = component.$$view;
1308
1265
  const diffAtom = atom.child;
1309
1266
  const template = render(component.props, component.props);
1310
1267
  if (template) {
@@ -1313,7 +1270,10 @@ exports.Renderer = class Renderer {
1313
1270
  else {
1314
1271
  atom.child = null;
1315
1272
  }
1316
- this.diff(atom.child, diffAtom, context, 0, 0);
1273
+ this.diff(atom.child, diffAtom, {
1274
+ host,
1275
+ isParent
1276
+ }, 0, 0);
1317
1277
  }
1318
1278
  diff(newAtom, oldAtom, context, expectIndex, index) {
1319
1279
  const oldChildren = [];
@@ -1334,11 +1294,7 @@ exports.Renderer = class Renderer {
1334
1294
  const oldProps = reusedAtom.jsxNode.props;
1335
1295
  newAtom.jsxNode = reusedAtom.jsxNode;
1336
1296
  const newTemplate = render(newProps, oldProps);
1337
- newAtom.jsxNode.$$view = {
1338
- render,
1339
- template: newTemplate,
1340
- atom: newAtom
1341
- };
1297
+ newAtom.jsxNode.$$view = Object.assign({ render, template: newTemplate, atom: newAtom }, context);
1342
1298
  if (newTemplate === template) {
1343
1299
  this.reuseComponentView(newAtom, reusedAtom, context, expectIndex !== diffIndex - offset);
1344
1300
  return;
@@ -1514,7 +1470,7 @@ exports.Renderer = class Renderer {
1514
1470
  }
1515
1471
  buildView(atom, context) {
1516
1472
  if (atom.jsxNode instanceof Component) {
1517
- this.componentRender(atom.jsxNode, atom);
1473
+ this.componentRender(atom.jsxNode, atom, context);
1518
1474
  let child = atom.child;
1519
1475
  while (child) {
1520
1476
  this.buildView(child, context);
@@ -1558,16 +1514,13 @@ exports.Renderer = class Renderer {
1558
1514
  }
1559
1515
  }
1560
1516
  }
1561
- componentRender(component, from) {
1517
+ componentRender(component, from, context) {
1562
1518
  const { template, render } = component.setup();
1563
1519
  if (template) {
1564
1520
  this.linkTemplate(template, component, from);
1565
1521
  }
1566
- component.$$view = {
1567
- render,
1568
- template,
1569
- atom: from
1570
- };
1522
+ component.$$view = Object.assign({ render,
1523
+ template, atom: from }, context);
1571
1524
  return from;
1572
1525
  }
1573
1526
  createChainByComponentFactory(context, factory, parent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
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",
@@ -49,5 +49,5 @@
49
49
  "bugs": {
50
50
  "url": "https://github.com/viewfly/viewfly.git/issues"
51
51
  },
52
- "gitHead": "0d39c19943b47221b99a6471e2614f55716c6659"
52
+ "gitHead": "2c80fa3f23c647a918d542c0b626384d22766cb8"
53
53
  }