subay 0.0.13 → 0.1.1

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.
package/README.md CHANGED
@@ -603,10 +603,8 @@ const Greeting = (name: string, children: () => Node[]) => {
603
603
 
604
604
  **Component Usage**
605
605
 
606
- When using a component in a template, reference the component at the tag position.
607
- Because the template is an HTML string, self-closing tags are not supported when referencing.
608
- The parameters passed to the component must be in the same order as the component's declared parameters.
609
- The parameters received by the component are always consistent with those passed in.
606
+ Subay components do not support interpolation at the tag position in templates. Instead, they are used through direct calls or deferred calls.
607
+ A deferred call means creating a function that returns the result of the component call.
610
608
 
611
609
  **Example**
612
610
 
@@ -618,9 +616,14 @@ const Greeting = (greet: string, name: () => string) => {
618
616
  };
619
617
 
620
618
  const name = o('World');
621
- const app = html` <div><${Greeting} greet=${'Hello'} name=${name}></${Greeting}></div> `;
622
619
 
623
- document.body.append(...app);
620
+ // Direct call
621
+ const app1 = html` <div>${Greeting('Hello', name)}</div> `;
622
+
623
+ // Deferred call
624
+ const app2 = html` <div>${() => Greeting('Hello', name)}</div> `;
625
+
626
+ document.body.append(...app1);
624
627
  ```
625
628
 
626
629
  **Don't Do This**
@@ -633,25 +636,19 @@ const Greeting = (greet: string, name: () => string) => {
633
636
  };
634
637
 
635
638
  const name = o('World');
636
- // Error, the following span will be treated as a child node of Greeting.
639
+ // Error - Interpolation at tag position
637
640
  const app = html`
638
641
  <div>
639
- <${Greeting}
640
- greet=${'Hello'}
641
- name=${name}
642
- />
643
- <span></span>
642
+ <${Greeting} greet=${'Hello'} name=${name}></${Greeting}>
644
643
  </div>
645
644
  `;
646
- // Error, parameter order is inconsistent with Greeting's parameters
647
- const app = html` <div><${Greeting} name=${name} greet=${'Hi'} ></${Greeting}></div> `;
648
645
 
649
646
  document.body.append(...app);
650
647
  ```
651
648
 
652
649
  **Dynamic Components**
653
650
 
654
- The interpolation at the tag position can be the return value of `S` or `o`, and components can be dynamically selected for rendering based on conditions.
651
+ You can dynamically select which component to render based on conditions by returning different components from a function.
655
652
 
656
653
  **Example**
657
654
 
@@ -668,14 +665,13 @@ const Farewell = (name: () => string) => {
668
665
 
669
666
  const showGreeting = o(true);
670
667
  const name = o('World');
671
- const Component = S(() => (showGreeting() ? Greeting : Farewell));
672
668
 
673
669
  const app = html`
674
670
  <div>
675
- <${Component} name=${name} ></${Component}>
671
+ ${() => (showGreeting() ? Greeting(name) : Farewell(name))}
676
672
  <button onclick=${() => showGreeting(!showGreeting())}>Toggle</button>
677
673
  </div>
678
674
  `;
679
675
 
680
676
  document.body.append(...app);
681
- ```
677
+ ```