malinajs 0.7.0-a14 → 0.7.0-a15

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 (3) hide show
  1. package/malina.js +18 -24
  2. package/package.json +1 -1
  3. package/runtime.js +39 -48
package/malina.js CHANGED
@@ -1663,8 +1663,8 @@
1663
1663
  ctx.write(true, `let {${pa}, ...$attributes} = $props;`);
1664
1664
 
1665
1665
  if(!this.script.readOnly && !n.constantProps) {
1666
- ctx.write(true, `$runtime.current_component.push = () => ({${n.props.map(p => p.name + '=' + p.name).join(', ')}, ...$attributes} = $props = $option.props || {});`);
1667
- ctx.write(true, `$runtime.current_component.exportedProps = () => ({${n.props.map(p => p.name).join(', ')}});`);
1666
+ ctx.write(true, `$runtime.current_component.$push = ($$props) => ({${n.props.map(p => p.name + '=' + p.name).join(', ')}, ...$attributes} = $props = $$props);`);
1667
+ ctx.write(true, `$runtime.current_component.$exportedProps = () => ({${n.props.map(p => p.name).join(', ')}});`);
1668
1668
  }
1669
1669
  } else if(this.inuse.$props) {
1670
1670
  let pa = n.props.map(p => {
@@ -1674,8 +1674,8 @@
1674
1674
  ctx.write(true, `let {${pa}} = $props;`);
1675
1675
 
1676
1676
  if(!this.script.readOnly && !n.constantProps) {
1677
- ctx.write(true, `$runtime.current_component.push = () => ({${n.props.map(p => p.name + '=' + p.name).join(', ')}} = $props = $option.props || {});`);
1678
- ctx.write(true, `$runtime.current_component.exportedProps = () => ({${n.props.map(p => p.name).join(', ')}});`);
1677
+ ctx.write(true, `$runtime.current_component.$push = ($$props) => ({${n.props.map(p => p.name + '=' + p.name).join(', ')}} = $props = $$props);`);
1678
+ ctx.write(true, `$runtime.current_component.$exportedProps = () => ({${n.props.map(p => p.name).join(', ')}});`);
1679
1679
  }
1680
1680
  }
1681
1681
  }));
@@ -1685,13 +1685,13 @@
1685
1685
  this.module.head.push(xNode('no-props', ctx => {
1686
1686
  if(this.inuse.$props && this.inuse.$attributes) {
1687
1687
  ctx.write(true, 'let $props = $option.props || {}, $attributes = $props;');
1688
- if(!this.script.readOnly) ctx.write(true, '$runtime.current_component.push = () => $props = $attributes = $option.props || {};');
1688
+ if(!this.script.readOnly) ctx.write(true, '$runtime.current_component.$push = ($$props) => $props = $attributes = $$props;');
1689
1689
  } else if(this.inuse.$props) {
1690
1690
  ctx.write(true, 'let $props = $option.props || {};');
1691
- if(!this.script.readOnly) ctx.write(true, '$runtime.current_component.push = () => $props = $option.props || {};');
1691
+ if(!this.script.readOnly) ctx.write(true, '$runtime.current_component.$push = ($$props) => $props = $$props;');
1692
1692
  } else if(this.inuse.$attributes) {
1693
1693
  ctx.write(true, 'let $attributes = $option.props || {};');
1694
- if(!this.script.readOnly) ctx.write(true, '$runtime.current_component.push = () => $attributes = $option.props || {};');
1694
+ if(!this.script.readOnly) ctx.write(true, '$runtime.current_component.$push = ($$props) => $attributes = $$props;');
1695
1695
  }
1696
1696
  }));
1697
1697
 
@@ -1781,22 +1781,13 @@
1781
1781
  }
1782
1782
  }));
1783
1783
 
1784
- this.module.head.push(xNode('$context', {
1785
- $hold: ['componentFn']
1786
- }, (ctx) => {
1787
- if(this.inuse.$context) {
1788
- this.require('componentFn');
1789
- ctx.write(true, 'const $context = $runtime.$context;');
1790
- }
1784
+ this.module.head.push(xNode('$context', (ctx) => {
1785
+ if(this.inuse.$context) ctx.write(true, 'const $context = $option.context || {};');
1791
1786
  }));
1792
1787
 
1793
1788
  this.module.top.push(xNode(this.glob.$onMount, {
1794
- $hold: ['componentFn']
1795
1789
  }, (ctx, n) => {
1796
- if(n.value) {
1797
- this.require('componentFn');
1798
- ctx.write(true, `import { $onMount } from 'malinajs/runtime.js';`);
1799
- }
1790
+ if(n.value) ctx.write(true, `import { $onMount } from 'malinajs/runtime.js';`);
1800
1791
  }));
1801
1792
 
1802
1793
  this.module.top.push(xNode('$onDestroy', (ctx) => {
@@ -2408,7 +2399,9 @@
2408
2399
  base = n;
2409
2400
  shift = 0;
2410
2401
  } else if(n._innerBinding) {
2411
- let npath = [base._boundName];
2402
+ let npath;
2403
+ if(base) npath = [base._boundName];
2404
+ else npath = [...path, 'firstChild'];
2412
2405
  while(shift--) npath.push('nextSibling');
2413
2406
  walk(n, npath);
2414
2407
  shift = 0;
@@ -4983,6 +4976,7 @@
4983
4976
  if(Object.keys(events).length == 0) events = null;
4984
4977
 
4985
4978
  let result = xNode('component', {
4979
+ $wait: ['apply'],
4986
4980
  componentName,
4987
4981
  staticProps,
4988
4982
  props: propsFn,
@@ -4996,7 +4990,7 @@
4996
4990
  let comma = false;
4997
4991
  ctx.write(`$runtime.callComponent($context, ${n.componentName}, {`);
4998
4992
 
4999
- if(n.props.length && n.staticProps) {
4993
+ if(n.props.length && (n.staticProps || !this.inuse.apply)) {
5000
4994
  ctx.write(`props: {${n.props.join(', ')}}`);
5001
4995
  comma = true;
5002
4996
  n.props = [];
@@ -5067,7 +5061,7 @@
5067
5061
  if(n.props.length) ctx.write(',\n', true, `() => ({${n.props.join(', ')}})`);
5068
5062
  else other = ', null';
5069
5063
 
5070
- if(ctx.inuse.apply && n.props.length) {
5064
+ if(this.inuse.apply && n.props.length) {
5071
5065
  if(other) ctx.write(other);
5072
5066
  other = '';
5073
5067
  ctx.write(',');
@@ -5076,7 +5070,7 @@
5076
5070
  else ctx.write('$runtime.$$compareDeep');
5077
5071
  } else other += ', null';
5078
5072
 
5079
- if(n.propsSetter.length) {
5073
+ if(n.propsSetter.length && this.inuse.apply) {
5080
5074
  if(other) ctx.write(other);
5081
5075
  other = '';
5082
5076
  ctx.write(',\n', true, `($$_value) => ({${n.propsSetter.join(', ')}} = $$_value)`);
@@ -6551,7 +6545,7 @@
6551
6545
  return { event, fn, rootModifier };
6552
6546
  }
6553
6547
 
6554
- const version = '0.7.0-a14';
6548
+ const version = '0.7.0-a15';
6555
6549
 
6556
6550
 
6557
6551
  async function compile(source, config = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "malinajs",
3
- "version": "0.7.0-a14",
3
+ "version": "0.7.0-a15",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "prepare": "npm run build",
package/runtime.js CHANGED
@@ -348,7 +348,7 @@ function $$addEventForComponent(list, event, fn) {
348
348
  }
349
349
 
350
350
 
351
- let current_component, $context;
351
+ let current_component;
352
352
 
353
353
 
354
354
  const makeApply = () => {
@@ -370,8 +370,8 @@ const makeApply = () => {
370
370
  return r;
371
371
  };
372
372
 
373
- current_component.apply = apply;
374
- current_component.push = apply;
373
+ current_component.$apply = apply;
374
+ current_component.$push = apply;
375
375
  apply();
376
376
  return apply;
377
377
  };
@@ -379,21 +379,15 @@ const makeApply = () => {
379
379
 
380
380
  const makeComponent = (init) => {
381
381
  return ($option = {}) => {
382
- $context = $option.context || {};
383
382
  let prev_component = current_component,
384
383
  prev_cd = current_cd,
385
- $component = current_component = {
386
- $option,
387
- context: $context,
388
- exported: {}
389
- };
384
+ $component = current_component = {$option};
390
385
  current_cd = null;
391
386
 
392
387
  try {
393
388
  $component.$dom = init($option);
394
389
  } finally {
395
390
  current_component = prev_component;
396
- $context = null;
397
391
  current_cd = prev_cd;
398
392
  }
399
393
 
@@ -407,32 +401,27 @@ const callComponent = (context, component, option = {}, propFn, cmp, setter, cla
407
401
  let $component, parentWatch, parentCD = current_cd;
408
402
 
409
403
  if(propFn) {
410
- if(cmp) {
411
- parentWatch = $watch(propFn, value => {
412
- option.props = value;
413
- if($component) {
414
- $component.push?.();
415
- $component.apply?.();
416
- }
417
- }, { value: {}, cmp });
418
- fire(parentWatch);
419
- } else option.props = propFn();
404
+ parentWatch = $watch(propFn, value => {
405
+ $component.$push?.(value);
406
+ $component.$apply?.();
407
+ }, { value: {}, idle: true, cmp });
408
+ fire(parentWatch);
409
+ option.props = parentWatch.value;
420
410
  }
421
411
 
422
412
  if(classFn) {
423
413
  fire($watch(classFn, value => {
424
414
  option.$class = value;
425
- $component?.apply?.();
415
+ $component?.$apply?.();
426
416
  }, { value: {}, cmp: keyComparator }));
427
417
  }
428
418
 
429
419
  $component = safeCall(() => component(option));
430
- if(setter && $component?.exportedProps) {
431
- let w = new WatchObject($component.exportedProps, value => {
420
+ if($component instanceof Node) $component = {$dom: $component};
421
+ if(setter && $component?.$exportedProps) {
422
+ let w = new WatchObject($component.$exportedProps, value => {
432
423
  setter(value);
433
- cd_component(parentCD).apply();
434
- option.props = parentWatch.fn();
435
- $component.push();
424
+ cd_component(parentCD).$apply();
436
425
  });
437
426
  Object.assign(w, { idle: true, cmp, value: parentWatch.value });
438
427
  $component.$cd.watchers.push(w);
@@ -455,15 +444,16 @@ const attachDynComponent = (label, exp, bind) => {
455
444
 
456
445
  if(component) {
457
446
  destroyList = current_destroyList = [];
447
+ current_mountList = [];
458
448
  $cd = current_cd = cd_new();
459
449
  try {
460
450
  $dom = bind(component).$dom;
451
+ cd_attach2(parentCD, $cd);
452
+ insertAfter(label, $dom);
453
+ safeCallMount(current_mountList, destroyList);
461
454
  } finally {
462
- current_destroyList = null;
463
- current_cd = null;
455
+ current_destroyList = current_mountList = current_cd = null;
464
456
  }
465
- cd_attach2(parentCD, $cd);
466
- insertAfter(label, $dom);
467
457
  active = true;
468
458
  } else {
469
459
  $cd = null;
@@ -477,7 +467,7 @@ const attachDynComponent = (label, exp, bind) => {
477
467
  const autoSubscribe = (...list) => {
478
468
  list.forEach(i => {
479
469
  if(isFunction(i.subscribe)) {
480
- let unsub = i.subscribe(current_component.apply);
470
+ let unsub = i.subscribe(current_component.$apply);
481
471
  if(isFunction(unsub)) $onDestroy(unsub);
482
472
  }
483
473
  });
@@ -613,7 +603,7 @@ const makeExternalProperty = (name, getter, setter) => {
613
603
  let $component = current_component;
614
604
  Object.defineProperty($component, name, {
615
605
  get: getter,
616
- set: v => { setter(v); $component.apply(); }
606
+ set: v => { setter(v); $component.$apply(); }
617
607
  });
618
608
  };
619
609
 
@@ -684,7 +674,7 @@ const callExportedFragment = (childComponent, name, slot, events, props, cmp) =>
684
674
  fire(w);
685
675
  props = () => result;
686
676
  }
687
- let fn = childComponent.exported[name];
677
+ let fn = childComponent.$exported?.[name];
688
678
  ([$dom, push] = fn(props, events, slot));
689
679
  return $dom;
690
680
  };
@@ -692,11 +682,13 @@ const callExportedFragment = (childComponent, name, slot, events, props, cmp) =>
692
682
 
693
683
  const exportFragment = (name, fn) => {
694
684
  let childCD = current_cd;
695
- cd_component(childCD).exported[name] = (props, events, slot) => {
685
+ let component = cd_component(childCD);
686
+ if(!component.$exported) component.$exported = {};
687
+ component.$exported[name] = (props, events, slot) => {
696
688
  let prev = current_cd, $cd = current_cd = cd_new();
697
689
  cd_attach2(childCD, $cd);
698
690
  $onDestroy(() => cd_detach($cd));
699
- let apply = cd_component(childCD).apply;
691
+ let apply = cd_component(childCD).$apply;
700
692
  apply();
701
693
  try {
702
694
  return [fn(props, events || {}, slot), apply];
@@ -813,8 +805,7 @@ const mount = (label, component, option) => {
813
805
  label.appendChild($dom);
814
806
  safeCallMount(current_mountList, destroyList);
815
807
  } finally {
816
- current_destroyList = null;
817
- current_mountList = null;
808
+ current_destroyList = current_mountList = null;
818
809
  }
819
810
  app.destroy = () => {
820
811
  safeGroupCall(destroyList);
@@ -832,8 +823,7 @@ const mountStatic = (label, component, option) => {
832
823
  safeGroupCall(current_mountList);
833
824
  return app;
834
825
  } finally {
835
- current_destroyList = null;
836
- current_mountList = null;
826
+ current_destroyList = current_mountList = null;
837
827
  }
838
828
  };
839
829
 
@@ -916,9 +906,7 @@ function ifBlock(label, fn, parts, parentLabel) {
916
906
  try {
917
907
  $dom = builder();
918
908
  } finally {
919
- current_destroyList = null;
920
- current_mountList = null;
921
- current_cd = null;
909
+ current_destroyList = current_mountList = current_cd = null;
922
910
  }
923
911
  cd_attach2(parentCD, $cd);
924
912
  if($dom.nodeType == 11) {
@@ -997,7 +985,7 @@ function $$awaitBlock(label, relation, fn, build_main, build_then, build_catch)
997
985
  } else first = last = $dom;
998
986
  insertAfter(label, $dom);
999
987
  safeCallMount(mountList, destroyList);
1000
- cd_component(parentCD).apply();
988
+ cd_component(parentCD).$apply();
1001
989
  }
1002
990
 
1003
991
  $watch(relation, () => {
@@ -1251,10 +1239,13 @@ const invokeSlot = ($component, slotName, $context, propsFn, placeholder, cmp) =
1251
1239
  const makeSlot = (fr, fn) => {
1252
1240
  let parentCD = current_cd;
1253
1241
  return (callerComponent, $context, props) => {
1254
- let $dom = fr.cloneNode(true), prev = current_cd, $cd = current_cd = cd_new();
1255
- cd_attach2(parentCD, $cd);
1256
- $onDestroy(() => cd_detach($cd));
1257
- parentCD.component.apply();
1242
+ let $dom = fr.cloneNode(true), prev = current_cd;
1243
+ if(parentCD) {
1244
+ let $cd = current_cd = cd_new();
1245
+ cd_attach2(parentCD, $cd);
1246
+ $onDestroy(() => cd_detach($cd));
1247
+ cd_component(parentCD).$apply();
1248
+ } else current_cd = null;
1258
1249
  try {
1259
1250
  return { $dom, push: fn($dom, $context, callerComponent, props) };
1260
1251
  } finally {
@@ -1263,4 +1254,4 @@ const makeSlot = (fr, fn) => {
1263
1254
  };
1264
1255
  };
1265
1256
 
1266
- export { $$addEventForComponent, $$awaitBlock, $$cloneDeep, $$compareArray, $$compareDeep, $$deepComparator, $$eachBlock, $$htmlBlock, $$htmlBlockStatic, $$htmlToFragment, $$htmlToFragmentClean, $$removeElements, $$removeItem, $context, $digest, $makeEmitter, $onDestroy, $onMount, $tick, $watch, WatchObject, __app_onerror, __bindActionSubscribe, addClass, addEvent, addStyles, attachAnchor, attachBlock, attachDynComponent, autoSubscribe, bindAction, bindAttribute, bindAttributeBase, bindClass, bindClassExp, bindInput, bindStyle, bindText, callComponent, callExportedFragment, cd_attach, cd_attach2, cd_component, cd_detach, cd_new, cloneDeep, configure, createTextNode, current_cd, current_component, current_destroyList, current_mountList, destroyResults, eachDefaultKey, exportFragment, fire, getFinalLabel, ifBlock, ifBlockReadOnly, insertAfter, invokeSlot, invokeSlotBase, isArray, isFunction, iterNodes, keyComparator, makeAnchor, makeApply, makeBlock, makeBlockBound, makeClassResolver, makeComponent, makeEachBlock, makeEachElseBlock, makeEachSingleBlock, makeExternalProperty, makeRootEvent, makeSlot, mergeAllEvents, mergeEvents, mount, mountStatic, noop, prefixPush, refer, removeElementsBetween, setClassToElement, spreadAttributes, svgToFragment, unwrapProps };
1257
+ export { $$addEventForComponent, $$awaitBlock, $$cloneDeep, $$compareArray, $$compareDeep, $$deepComparator, $$eachBlock, $$htmlBlock, $$htmlBlockStatic, $$htmlToFragment, $$htmlToFragmentClean, $$removeElements, $$removeItem, $digest, $makeEmitter, $onDestroy, $onMount, $tick, $watch, WatchObject, __app_onerror, __bindActionSubscribe, addClass, addEvent, addStyles, attachAnchor, attachBlock, attachDynComponent, autoSubscribe, bindAction, bindAttribute, bindAttributeBase, bindClass, bindClassExp, bindInput, bindStyle, bindText, callComponent, callExportedFragment, cd_attach, cd_attach2, cd_component, cd_detach, cd_new, cloneDeep, configure, createTextNode, current_cd, current_component, current_destroyList, current_mountList, destroyResults, eachDefaultKey, exportFragment, fire, getFinalLabel, ifBlock, ifBlockReadOnly, insertAfter, invokeSlot, invokeSlotBase, isArray, isFunction, iterNodes, keyComparator, makeAnchor, makeApply, makeBlock, makeBlockBound, makeClassResolver, makeComponent, makeEachBlock, makeEachElseBlock, makeEachSingleBlock, makeExternalProperty, makeRootEvent, makeSlot, mergeAllEvents, mergeEvents, mount, mountStatic, noop, prefixPush, refer, removeElementsBetween, setClassToElement, spreadAttributes, svgToFragment, unwrapProps };