Count value is 0.');
+const Comp = () => {
+ return (() => {
+ const _el$ = $tmpl();
+ $$effect(() =>
+ color.get() != null ? _el$.style.setProperty('color', color.get()) : _el$.style.removeProperty('color')
+ );
+ _el$.style.setProperty('display', 'flex');
+ return _el$;
+ })();
+};
+
+```
+## Loop
+
+```jsx
+
+
+// to
+$$runComponent(For, {
+ get each() {
+ return state.todoList;
+ },
+ children: todo => [
+ $$runComponent(Todo, {
+ todo: todo,
+ }),
+ $$runComponent(Todo, {
+ todo: todo,
+ }),
+ ],
+})
+
+```
+
+## Conditional
+编译为`Cond`组件,`Cond`组件接收`branches`属性。
+`branches`属性为一个数组,数组中的每个元素都是一个数组,数组的第一个元素是条件,第二个元素是返回的dom。
+```ts
+// It's boolean when the condition is static of default branch
+// Otherwise it's a function that return boolean
+type CondExpression = boolean | (() => boolean);
+// When branch only include static JSXElement the branch can be a JSXElement
+// Otherwise, the branch should be a function that return JSXElement
+type Branch = JSXElement | (() => JSXElement);
+
+export interface CondProps {
+ // Array of tuples, first item is the condition, second is the branch to render
+ branches: [CondExpression, Branch][];
+}
+```
+```jsx
+/**
+ * 源码:
+ * const fn = vi.fn();
+ * function App() {
+ * const x = reactive(7);
+ *
+ * return (
+ *
xxx`),
+ _tmpl$4 = /*#__PURE__*/ _$template(`
is between 5 and 10`);
+let change;
+
+function App() {
+ const x = reactive(7);
+ change = v => x.set(v);
+ return (() => {
+ const _el$ = _tmpl$3(),
+ _el$2 = _el$.firstChild;
+ _$insert(
+ _el$,
+ _$runComponent(Cond, {
+ get branches() {
+ return [
+ [
+ () => x.get() > 10,
+ () => {
+ const _el$3 = _tmpl$(),
+ _el$4 = _el$3.firstChild;
+ _$insert(_el$3, x, _el$4);
+ return _el$3;
+ },
+ ],
+ [
+ () => 5 > x.get(),
+ () => {
+ const _el$5 = _tmpl$2(),
+ _el$6 = _el$5.firstChild;
+ _$insert(_el$5, x, _el$6);
+ return _el$5;
+ },
+ ],
+ [
+ true,
+ () => {
+ const _el$7 = _tmpl$4(),
+ _el$8 = _el$7.firstChild;
+ _$insert(_el$7, x, _el$8);
+ return _el$7;
+ },
+ ],
+ ];
+ },
+ }),
+ null
+ );
+
+ return _el$;
+ })();
+}
+
+render(() => _$runComponent(App, {}), container);
+```
+## Early Return
+
+# **Component composition**
+
+## Props
+
+使用`.get()`的表达式作为props时,转为对象时通过getter包装。
+使用props时,通过props.(参数名)访问来保证在组件时读取props时能够保持响应。
+
+> 好处: 1. 使用props时无需感知是否为响应式,无需额外判断 2. 使用统一,JSX和函数体JS都通过.get() 读值
+> 问题: 1. 不能解构 -> 通过2.0 API编译语法糖解决
+
+```jsx
+function App() {
+ const name = reactive("init")
+ return