lilact 0.30.1 → 0.31.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.
Files changed (33) hide show
  1. package/dist/lilact.development.js +68 -43
  2. package/dist/lilact.development.js.map +2 -2
  3. package/dist/lilact.development.min.js +23 -23
  4. package/dist/lilact.development.min.js.map +3 -3
  5. package/dist/lilact.production.min.js +23 -23
  6. package/docs/classes/accessories.ErrorBoundary.html +8 -8
  7. package/docs/classes/accessories.Suspense.html +7 -7
  8. package/docs/classes/components.Component.html +11 -11
  9. package/docs/classes/components.HTMLComponent.html +11 -11
  10. package/docs/classes/components.RootComponent.html +11 -11
  11. package/docs/functions/components.cloneComponent.html +1 -1
  12. package/docs/functions/components.createComponent.html +1 -1
  13. package/docs/functions/components.createPortal.html +1 -1
  14. package/docs/functions/components.createRoot.html +1 -1
  15. package/docs/functions/components.hotReloadRoot.html +1 -1
  16. package/docs/functions/components.memo.html +1 -1
  17. package/docs/functions/components.render.html +1 -1
  18. package/docs/functions/components.replaceAllComponentInstances.html +1 -1
  19. package/docs/functions/components.replaceComponentEntity.html +1 -1
  20. package/docs/static/lilact.development.js +68 -43
  21. package/docs/static/lilact.development.js.map +2 -2
  22. package/docs/static/lilact.development.min.js +23 -23
  23. package/docs/static/lilact.development.min.js.map +3 -3
  24. package/docs/static/lilact.production.min.js +23 -23
  25. package/docs/variables/components.cloneElement.html +1 -1
  26. package/examples/lilact.development.js +68 -43
  27. package/examples/lilact.development.js.map +2 -2
  28. package/examples/lilact.development.min.js +23 -23
  29. package/examples/lilact.development.min.js.map +3 -3
  30. package/examples/lilact.production.min.js +23 -23
  31. package/package.json +1 -1
  32. package/src/components.jsx +104 -69
  33. package/src/lilact.jsx +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lilact",
3
- "version": "0.30.1",
3
+ "version": "0.31.0",
4
4
  "description": "A Little React/JSX Runtime Implementation for Browser",
5
5
  "repository": "github:arashkazemi/lilact",
6
6
  "homepage": "https://arashkazemi.github.io/lilact/",
@@ -38,10 +38,30 @@ import { PropTypes } from './proptypes.jsx';
38
38
  const SVG_NS = "http://www.w3.org/2000/svg";
39
39
 
40
40
 
41
+
41
42
  function getComponentEntity(entity) {
42
43
  return entity?.[MEMOIZED] ? entity.component : entity;
43
44
  }
44
45
 
46
+ const hotEntityAliases = new Map();
47
+
48
+ function resolveHotEntity(entity) {
49
+ entity = getComponentEntity(entity);
50
+
51
+ const visited = new Set();
52
+
53
+ while (
54
+ typeof entity === "function" &&
55
+ hotEntityAliases.has(entity) &&
56
+ !visited.has(entity)
57
+ ) {
58
+ visited.add(entity);
59
+ entity = hotEntityAliases.get(entity);
60
+ }
61
+
62
+ return entity;
63
+ }
64
+
45
65
  const componentInstances = new Map();
46
66
 
47
67
  function registerComponentCore(core) {
@@ -105,7 +125,7 @@ export function replaceComponentEntity(componentCore, nextEntity) {
105
125
  }
106
126
 
107
127
  const oldEntity = getComponentEntity(componentCore.entity);
108
- const newEntity = getComponentEntity(nextEntity);
128
+ const newEntity = resolveHotEntity(nextEntity);
109
129
 
110
130
  if (oldEntity === newEntity) {
111
131
  return true;
@@ -148,6 +168,16 @@ export function replaceAllComponentInstances(oldEntity, newEntity) {
148
168
  return 0;
149
169
  }
150
170
 
171
+ newEntity = resolveHotEntity(newEntity);
172
+
173
+ if (oldEntity === newEntity) {
174
+ return 0;
175
+ }
176
+
177
+ // Keep this alias even when there are currently no instances.
178
+ // A future instance may still be created with oldEntity.
179
+ hotEntityAliases.set(oldEntity, newEntity);
180
+
151
181
  const instances = componentInstances.get(oldEntity);
152
182
 
153
183
  if (!instances) {
@@ -168,6 +198,7 @@ export function replaceAllComponentInstances(oldEntity, newEntity) {
168
198
  return count;
169
199
  }
170
200
 
201
+
171
202
  /*
172
203
  ComponentCache is for internal use. It is the heart of the JSX runtime,
173
204
  it holds child components and detects which one is being rendered or updated.
@@ -194,19 +225,18 @@ class ComponentCache
194
225
  bucket[IDX]++;
195
226
 
196
227
  const oldEntity = getComponentEntity(componentCore.entity);
197
- const newEntity = getComponentEntity(nextEntity);
228
+ const newEntity = resolveHotEntity(nextEntity);
198
229
 
199
230
  const incompatible =
200
- typeof oldEntity !== typeof newEntity ||
201
- (
202
- typeof oldEntity === "function" &&
203
- isClass(oldEntity) !== isClass(newEntity)
204
- );
205
-
231
+ typeof oldEntity !== typeof newEntity ||
232
+ (
233
+ typeof oldEntity === "function" &&
234
+ isClass(oldEntity) !== isClass(newEntity)
235
+ );
236
+
206
237
  if (incompatible) {
207
238
  componentCore = construct_func();
208
- }
209
- else if (newEntity) {
239
+ } else if (newEntity) {
210
240
  replaceComponentEntity(componentCore, newEntity);
211
241
  }
212
242
  } else {
@@ -810,92 +840,97 @@ const renderErrorHandler = (c, e) =>
810
840
 
811
841
 
812
842
 
813
- function constructFunc(core, parent) // returns {text} or component, and not component core.
814
- {
843
+ function constructFunc(core, parent) {
815
844
  let comp = core;
816
845
 
817
- if( core[TEXT]!==undefined ) {
818
- // do nothing...
819
- }
820
- else {
846
+ if (core[TEXT] === undefined) {
821
847
  let entity = core.entity;
822
848
  let memoized = false;
823
849
 
824
- if(typeof(entity)==='object') {
825
- if( entity[MEMOIZED] ) {
850
+ if (typeof entity === "object") {
851
+ if (entity[MEMOIZED]) {
826
852
  memoized = entity[MEMOIZED];
827
853
  entity = entity.component;
828
- }
829
- else {
854
+ } else {
830
855
  throw new Error("Invalid component.");
831
856
  }
832
857
  }
833
858
 
834
- if(typeof(entity)==='string') {
835
- comp = new HTMLComponent(entity, core.props);
836
- }
837
- else {
838
-
839
- if( isClass(entity) ) {
840
- if(entity?.defaultProps) {
841
- core.props = { ...entity.defaultProps, ...core.props };
842
- }
843
-
844
- comp = new entity(core.props);
859
+ entity = resolveHotEntity(entity);
845
860
 
846
- const desc = Object.getOwnPropertyDescriptor(comp, "state");
847
- if(desc) {
848
- if (typeof desc.get !== "function" && typeof desc.set !== "function") {
849
- comp[CORE].state = comp.state;
861
+ if (typeof entity === "string") {
862
+ comp = new HTMLComponent(entity, core.props);
863
+ } else if (isClass(entity)) {
864
+ if (entity?.defaultProps) {
865
+ core.props = {
866
+ ...entity.defaultProps,
867
+ ...core.props,
868
+ };
869
+ }
850
870
 
851
- Object.defineProperty(comp, "state", {
852
- get() { return this[CORE].state },
853
- set(v) {
854
- // todo: this should be changed, it should be only directly settable in constructor.
855
- if(this[CORE].state===undefined) {
856
- this[CORE].state = v;
857
- }
858
- else {
859
- throw new Error('Assigning component state this way is not allowed.');
860
- }
871
+ comp = new entity(core.props);
872
+
873
+ const desc = Object.getOwnPropertyDescriptor(comp, "state");
874
+
875
+ if (desc) {
876
+ if (
877
+ typeof desc.get !== "function" &&
878
+ typeof desc.set !== "function"
879
+ ) {
880
+ comp[CORE].state = comp.state;
881
+
882
+ Object.defineProperty(comp, "state", {
883
+ get() {
884
+ return this[CORE].state;
885
+ },
886
+ set(value) {
887
+ if (this[CORE].state === undefined) {
888
+ this[CORE].state = value;
889
+ } else {
890
+ throw new Error(
891
+ "Assigning component state this way is not allowed."
892
+ );
861
893
  }
862
- });
863
- }
894
+ },
895
+ });
864
896
  }
865
897
  }
866
- else if(typeof(entity)==='function') {
867
-
868
- if(entity?.defaultProps) {
869
- core.props = { ...entity.defaultProps, ...core.props };
870
- }
898
+ } else if (typeof entity === "function") {
899
+ if (entity?.defaultProps) {
900
+ core.props = {
901
+ ...entity.defaultProps,
902
+ ...core.props,
903
+ };
904
+ }
871
905
 
872
- comp = new Component(core.props);
906
+ comp = new Component(core.props);
907
+ comp.render = entity.bind(comp);
908
+ comp[CORE].hooks = [];
909
+ comp[CORE].hook_index = 0;
910
+ } else {
911
+ throw new Error("Error in constructing component.");
912
+ }
873
913
 
874
- // the binding is not necessary and is not according to the specs,
875
- // probably not even recommended! but helpful.
876
- comp.render = entity.bind(comp);
877
- comp[CORE].hooks = [];
878
- comp[CORE].hook_index = 0;
879
- }
880
- else {
881
- throw new Error("Error in constructing component.");
882
- }
914
+ comp[CORE].entity = entity;
915
+ registerComponentCore(comp[CORE]);
883
916
 
884
- comp[CORE].entity = entity;
885
- registerComponentCore(comp[CORE]);
917
+ if (core.container) {
918
+ comp[CORE].container = core.container;
919
+ }
886
920
 
887
- if (core.container) {
888
- comp[CORE].container = core.container;
889
- }
921
+ if (memoized) {
922
+ comp[CORE][MEMOIZED] = true;
890
923
  }
924
+ }
891
925
 
892
- if(memoized) comp[CORE][MEMOIZED] = true;
926
+ if (parent instanceof ComponentCore) {
927
+ comp[CORE].parent = parent;
893
928
  }
894
929
 
895
- if(parent instanceof ComponentCore) comp[CORE].parent = parent;
896
930
  return comp;
897
931
  }
898
932
 
933
+
899
934
  function prepareCore(parent, core) {
900
935
  try {
901
936
  parent.cache ??= new ComponentCache(parent);
package/src/lilact.jsx CHANGED
@@ -94,7 +94,7 @@ export {transpileJSX, transpilerConfig} from "./jsx";
94
94
  export const Lilact =
95
95
  {
96
96
 
97
- VERSION: "RC.6",
97
+ VERSION: "RC.7",
98
98
 
99
99
  // Configuration
100
100