@xaendar/core 0.6.11 → 0.6.13

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.
@@ -158,6 +158,8 @@ declare type ContextIdentifier<ReturnType = unknown> = {
158
158
  reactive: boolean;
159
159
  };
160
160
 
161
+ export declare function declareConst(context: Context, name: string, expression: NoArgsFunction<unknown>): void;
162
+
161
163
  /**
162
164
  * Runs a side-effectful function and automatically re-runs it whenever any
163
165
  * Signal read during its execution changes.
@@ -366,7 +368,7 @@ declare type PropertyDecoratorOptionsWithRequired<ActualValue = unknown, Incomin
366
368
  required: true;
367
369
  };
368
370
 
369
- export declare function _renderElement(parentNode: HTMLElement, context: Context, tagName: string, attributes: RenderElementAttribute[], events: RenderElementEvent[]): void;
371
+ export declare function _renderElement(parentNode: HTMLElement, context: Context, tagName: string, attributes: RenderElementAttribute[], events: RenderElementEvent[]): HTMLElement;
370
372
 
371
373
  declare type RenderElementAttribute = {
372
374
  name: string;
@@ -454,7 +454,7 @@ var Context = class {
454
454
  };
455
455
  }
456
456
  getEventHandler(handler) {
457
- return this._root[handler];
457
+ return this._root[handler].bind(this._root);
458
458
  }
459
459
  addChild(context) {
460
460
  this._children.push(context);
@@ -479,6 +479,11 @@ var Context = class {
479
479
  }
480
480
  };
481
481
  //#endregion
482
+ //#region ../packages/core/src/utils/declare-const.util.ts
483
+ function declareConst(context, name, expression) {
484
+ context.addIdentifier(name, expression);
485
+ }
486
+ //#endregion
482
487
  //#region ../packages/core/src/utils/for.util.ts
483
488
  /**
484
489
  * Reactively iterates over a list of items, re-running the loop whenever the tracked condition changes.
@@ -590,7 +595,11 @@ function _if(parentNode, parentContext, blocks) {
590
595
  */
591
596
  function handleIf(parentNode, parentContext, ifBlock, state) {
592
597
  if (ifBlock.condition()) return checkAndUpdateState(parentNode, parentContext, state, 0, ifBlock.block);
593
- else parentContext.unlisten();
598
+ else if (state) {
599
+ const context = state.context;
600
+ context.unlisten();
601
+ parentContext.removeChild(context);
602
+ }
594
603
  }
595
604
  /**
596
605
  * Handles the `if` / `else` case (exactly two branches).
@@ -706,11 +715,12 @@ function _renderElement(parentNode, context, tagName, attributes, events) {
706
715
  }
707
716
  });
708
717
  events.forEach((event) => {
709
- const handler = ($event) => context.getEventHandler(event.handler);
718
+ const handler = ($event) => context.getEventHandler(event.handler)();
710
719
  const name = event.name;
711
720
  element.addEventListener(name, handler);
712
721
  context.listen(() => element.removeEventListener(name, handler));
713
722
  });
723
+ return element;
714
724
  }
715
725
  //#endregion
716
726
  //#region ../packages/core/src/utils/switch.util.ts
@@ -746,4 +756,4 @@ function _switch(parentNode, parentContext, expression, blocks) {
746
756
  })));
747
757
  }
748
758
  //#endregion
749
- export { BaseWebComponent, Context, Event, Property, WebComponent, _for, _if, _iterationVariables, _renderElement, _renderLiteralText, _renderText, _switch, computed, effect, input, signal };
759
+ export { BaseWebComponent, Context, Event, Property, WebComponent, _for, _if, _iterationVariables, _renderElement, _renderLiteralText, _renderText, _switch, computed, declareConst, effect, input, signal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/core",
3
- "version": "0.6.11",
3
+ "version": "0.6.13",
4
4
  "description": "A library containing core utils such as webcomponent base classes and theming support",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
- "@xaendar/signals": "0.6.11",
20
- "@xaendar/types": "0.6.11"
19
+ "@xaendar/signals": "0.6.13",
20
+ "@xaendar/types": "0.6.13"
21
21
  }
22
22
  }