Skip to content

Commit 392e0ec

Browse files
authored
Merge pull request #73 from koculu/define-component
Define component
2 parents bb7078a + 3f64a01 commit 392e0ec

39 files changed

+524
-276
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ HTML:
6262
Defining component:
6363

6464
```ts
65-
import { createApp, createComponent, ref, html, type Ref } from 'regor'
65+
import { createApp, defineComponent, ref, html, type Ref } from 'regor'
6666

6767
interface MyComponent {
6868
message: Ref<string>
@@ -74,7 +74,7 @@ const template = html`<button @click="count++">
7474

7575
const props = ['message']
7676

77-
const myComponent = createComponent<MyComponent>(template, {
77+
const myComponent = defineComponent<MyComponent>(template, {
7878
context: (head) => ({
7979
message: head.props.message,
8080
count: ref(0),
@@ -120,7 +120,7 @@ Example:
120120
```
121121

122122
```ts
123-
const tableRow = createComponent(
123+
const tableRow = defineComponent(
124124
html`<tr>
125125
<TableCell :value="row.name" />
126126
<TableCell :value="row.age" />
@@ -222,7 +222,7 @@ These directives empower you to create dynamic and interactive user interfaces,
222222
**App / Component Template Functions**
223223

224224
- **`createApp`** Similar to Vue's `createApp`, it initializes a Regor application instance.
225-
- **`createComponent`** Creates a Regor component instance.
225+
- **`defineComponent`** Creates a Regor component instance.
226226
- **`toFragment`** Converts a JSON template to a document fragment.
227227
- **`toJsonTemplate`** Converts a DOM element to a JSON template.
228228

docs-site/public/sample.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ <h1>Regor Counter App Demo</h1>
7272
<!-- TypeScript example tab -->
7373
<div class="tab-content" :class="{ active: activeTab === 'ts' }">
7474
<pre><code class="language-typescript">// example.ts
75-
import { createApp, createComponent, ref, html, type Ref } from 'regor';
75+
import { createApp, defineComponent, ref, html, type Ref } from 'regor';
7676

7777
interface CounterProps { initial: Ref<number>; }
7878
const template = html`<button @click=\"count++\">{{ count }} (initial: {{ initial }})</button>`;
79-
const Counter = createComponent<CounterProps>(
79+
const Counter = defineComponent<CounterProps>(
8080
template,
8181
{
8282
context: (head) => ({ initial: head.props.initial, count: ref(head.props.initial()) }),

docs-site/src/content/docs/api/createApp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ The `createApp` function returns an object with the following properties:
7373

7474
## See Also
7575

76-
- [`createComponent`](/api/createComponent)
76+
- [`defineComponent`](/api/defineComponent)
7777
- [`toFragment`](/api/toFragment)
7878
- [`toJsonTemplate`](/api/toJsonTemplate)
7979

docs-site/src/content/docs/api/createComponent.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
2-
title: createComponent
2+
title: defineComponent
33
---
44

55
## Overview
66

7-
The `createComponent` function is used to create a Regor component, which encapsulates a part of your user interface (UI) with its own behavior and template. Components allow you to build complex UIs by composing smaller, reusable units.
7+
The `defineComponent` function is used to create a Regor component, which encapsulates a part of your user interface (UI) with its own behavior and template. Components allow you to build complex UIs by composing smaller, reusable units.
88

99
## Usage
1010

1111
### Creating a Regor Component
1212

13-
To create a Regor component, call the `createComponent` function with the following parameters:
13+
To create a Regor component, call the `defineComponent` function with the following parameters:
1414

1515
- `template` (required): An HTML string or an object specifying the template for rendering the component. It can include the following properties:
1616

@@ -30,10 +30,10 @@ To create a Regor component, call the `createComponent` function with the follow
3030
### Example
3131

3232
```ts
33-
import { createComponent, createApp, html } from 'regor'
33+
import { defineComponent, createApp, html } from 'regor'
3434

3535
// Define a Regor component
36-
const myComponent = createComponent(
36+
const myComponent = defineComponent(
3737
html`<div></div>`, // Define the component content from html string
3838
{
3939
context: (head) => ({
@@ -57,7 +57,7 @@ createApp({
5757

5858
## Return Value
5959

60-
The `createComponent` function returns a component object with the following properties:
60+
The `defineComponent` function returns a component object with the following properties:
6161

6262
- `context`: The Regor context associated with the component. It defines the component's behavior, data, and reactivity.
6363

@@ -94,4 +94,3 @@ The `createComponent` function returns a component object with the following pro
9494
- [`toJsonTemplate`](/api/toJsonTemplate)
9595

9696
[Back to the API list](/api/)
97-

docs-site/src/content/docs/api/index.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,75 +10,75 @@ Use this page as an index, then open each API page for signature details and exa
1010

1111
## App and Components
1212

13-
1. [`createApp`](./createApp)
14-
2. [`createComponent`](./createComponent)
15-
3. [`toFragment`](./toFragment)
16-
4. [`toJsonTemplate`](./toJsonTemplate)
17-
5. [`RegorConfig`](./regorConfig)
13+
1. [`createApp`](/api/createApp)
14+
2. [`defineComponent`](/api/defineComponent)
15+
3. [`toFragment`](/api/toFragment)
16+
4. [`toJsonTemplate`](/api/toJsonTemplate)
17+
5. [`RegorConfig`](/api/regorConfig)
1818

1919
## Reactivity
2020

21-
1. [`ref`](./ref)
22-
2. [`sref`](./sref)
23-
3. [`isRef`](./isRef)
24-
4. [`isDeepRef`](./isDeepRef)
25-
5. [`unref`](./unref)
26-
6. [`pause`](./pause)
27-
7. [`resume`](./resume)
28-
8. [`trigger`](./trigger)
29-
9. [`entangle`](./entangle)
21+
1. [`ref`](/api/ref)
22+
2. [`sref`](/api/sref)
23+
3. [`isRef`](/api/isRef)
24+
4. [`isDeepRef`](/api/isDeepRef)
25+
5. [`unref`](/api/unref)
26+
6. [`pause`](/api/pause)
27+
7. [`resume`](/api/resume)
28+
8. [`trigger`](/api/trigger)
29+
9. [`entangle`](/api/entangle)
3030

3131
## Computed and Effects
3232

33-
1. [`computed`](./computed)
34-
2. [`computeRef`](./computeRef)
35-
3. [`computeMany`](./computeMany)
36-
4. [`watchEffect`](./watchEffect)
37-
5. [`collectRefs`](./collectRefs)
38-
6. [`silence`](./silence)
33+
1. [`computed`](/api/computed)
34+
2. [`computeRef`](/api/computeRef)
35+
3. [`computeMany`](/api/computeMany)
36+
4. [`watchEffect`](/api/watchEffect)
37+
5. [`collectRefs`](/api/collectRefs)
38+
6. [`silence`](/api/silence)
3939

4040
## Observation and Batch
4141

42-
1. [`observe`](./observe)
43-
2. [`observeMany`](./observeMany)
44-
3. [`observerCount`](./observerCount)
45-
4. [`batch`](./batch)
46-
5. [`startBatch`](./startBatch)
47-
6. [`endBatch`](./endBatch)
42+
1. [`observe`](/api/observe)
43+
2. [`observeMany`](/api/observeMany)
44+
3. [`observerCount`](/api/observerCount)
45+
4. [`batch`](/api/batch)
46+
5. [`startBatch`](/api/startBatch)
47+
6. [`endBatch`](/api/endBatch)
4848

4949
## Lifecycle and Scope
5050

51-
1. [`useScope`](./useScope)
52-
2. [`onMounted`](./onMounted)
53-
3. [`onUnmounted`](./onUnmounted)
51+
1. [`useScope`](/api/useScope)
52+
2. [`onMounted`](/api/onMounted)
53+
3. [`onUnmounted`](/api/onUnmounted)
5454

5555
## Cleanup and Unbind
5656

57-
1. [`addUnbinder`](./addUnbinder)
58-
2. [`getBindData`](./getBindData)
59-
3. [`removeNode`](./removeNode)
60-
4. [`unbind`](./unbind)
61-
5. [`drainUnbind`](./drainUnbind)
57+
1. [`addUnbinder`](/api/addUnbinder)
58+
2. [`getBindData`](/api/getBindData)
59+
3. [`removeNode`](/api/removeNode)
60+
4. [`unbind`](/api/unbind)
61+
5. [`drainUnbind`](/api/drainUnbind)
6262

6363
## Utilities
6464

65-
1. [`flatten`](./flatten)
66-
2. [`markRaw`](./markRaw)
67-
3. [`isRaw`](./isRaw)
68-
4. [`persist`](./persist)
69-
5. [`html`](./html)
70-
6. [`raw`](./raw)
65+
1. [`flatten`](/api/flatten)
66+
2. [`markRaw`](/api/markRaw)
67+
3. [`isRaw`](/api/isRaw)
68+
4. [`persist`](/api/persist)
69+
5. [`html`](/api/html)
70+
6. [`raw`](/api/raw)
7171

7272
## Logging
7373

74-
1. [`warningHandler`](./warningHandler)
74+
1. [`warningHandler`](/api/warningHandler)
7575

7676
## Recommendation
7777

7878
Start with:
7979

80-
1. [`createApp`](./createApp)
81-
2. [`ref`](./ref)
82-
3. [`sref`](./sref)
83-
4. [`computed`](./computed)
84-
5. [`watchEffect`](./watchEffect)
80+
1. [`createApp`](/api/createApp)
81+
2. [`ref`](/api/ref)
82+
3. [`sref`](/api/sref)
83+
4. [`computed`](/api/computed)
84+
5. [`watchEffect`](/api/watchEffect)

docs-site/src/content/docs/api/onMounted.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ The `onMounted` function allows you to register a callback function that will be
1313
To register an `onMounted` callback, simply call the `onMounted` function and pass the desired callback function as an argument. The callback will be executed when the app or component is mounted.
1414

1515
```ts
16-
import { createApp, createComponent, html, useScope, onMounted } from 'regor'
16+
import { createApp, defineComponent, html, useScope, onMounted } from 'regor'
1717

18-
const userRow = createComponent(html`<div></div>`, {
18+
const userRow = defineComponent(html`<div></div>`, {
1919
context: () => ({
2020
// Register an onMounted callback
2121
onMounted(() => {

docs-site/src/content/docs/api/onUnmounted.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ The `onUnmounted` function allows you to register a callback function that will
1313
To register an `onUnmounted` callback, simply call the `onUnmounted` function and pass the desired callback function as an argument. The callback will be executed when the component or scope is unmounted or cleaned up.
1414

1515
```ts
16-
import { createApp, createComponent, html, useScope, onUnmounted } from 'regor'
16+
import { createApp, defineComponent, html, useScope, onUnmounted } from 'regor'
1717

18-
const userRow = createComponent(html`<div></div>`, {
18+
const userRow = defineComponent(html`<div></div>`, {
1919
context: () => ({
2020
// Register an onUnmounted callback
2121
onUnmounted(() => {

docs-site/src/content/docs/api/regorConfig.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ The `RegorConfig` class provides default configuration values for various proper
132132
## See Also
133133

134134
- [`createApp`](/api/createApp)
135-
- [`createComponent`](/api/createComponent)
135+
- [`defineComponent`](/api/defineComponent)
136136
- [`toFragment`](/api/toFragment)
137137
- [`toJsonTemplate`](/api/toJsonTemplate)
138138

docs-site/src/content/docs/api/toFragment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ The `toFragment` function returns a `DocumentFragment` containing the elements c
7070

7171
- [`toJsonTemplate`](/api/toJsonTemplate)
7272
- [`createApp`](/api/createApp)
73-
- [`createComponent`](/api/createComponent)
73+
- [`defineComponent`](/api/defineComponent)
7474

7575
[Back to the API list](/api/)

docs-site/src/content/docs/api/toJsonTemplate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ The `toJsonTemplate` function returns a JSON structure that represents the HTML
6565

6666
- [`toFragment`](/api/toFragment)
6767
- [`createApp`](/api/createApp)
68-
- [`createComponent`](/api/createComponent)
68+
- [`defineComponent`](/api/defineComponent)
6969

7070
[Back to the API list](/api/)

0 commit comments

Comments
 (0)