Skip to content

Commit f963b52

Browse files
help with quickstart
1 parent b94f449 commit f963b52

File tree

1 file changed

+82
-9
lines changed

1 file changed

+82
-9
lines changed

website/docs/quick-start-tutorial.md

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ By the end of this tutorial, you'll know how to:
2222

2323
## Step 1: Create Your First Component
2424

25+
Let's start by creating a working directory:
26+
27+
```bash
28+
mkdir oc-tutorial && cd oc-tutorial
29+
```
30+
2531
Let's create a simple "hello-world" component:
2632

2733
```bash
@@ -33,19 +39,24 @@ This creates a new directory with the following structure:
3339
```
3440
hello-world/
3541
├── package.json # Component configuration
36-
├── src/view.ts # ES6 template (the view)
37-
├── src/server.js # Server-side logic (optional)
42+
├── src/
43+
│ ├── view.ts # TypeScript template (the view)
44+
│ └── server.ts # Server-side logic
3845
└── public/
3946
└── logo.png # Static assets
47+
├── tsconfig.json # TypeScript configuration
48+
└── node_modules/ # Dependencies
4049
```
4150

4251
### Understanding the Files
4352

4453
**package.json**: Contains component metadata, dependencies, and OpenComponents-specific configuration.
4554

46-
**template.ts**: The ES6 template that defines how your component looks using modern JavaScript.
55+
**src/view.ts**: The TypeScript template that defines how your component looks using modern JavaScript with CSS imports and client-side event handling.
4756

48-
**server.ts**: Optional file for server-side logic, data fetching, or API calls.
57+
**src/server.ts**: Contains server-side logic, data fetching, parameter definitions, and API actions.
58+
59+
**Important Note**: The generated component is more sophisticated than basic examples you might see in documentation. It includes TypeScript, CSS modules, client-side interactivity, and server actions.
4960

5061
### Template Options
5162

@@ -66,6 +77,19 @@ oc init my-component --template-type=svelte
6677

6778
## Step 2: Explore Your Component
6879

80+
### Understanding Component Parameters
81+
82+
The generated component includes parameters that you need to know about. Let's check what parameters are required:
83+
84+
```bash
85+
cd hello-world
86+
cat package.json
87+
```
88+
89+
Look for the `oc.parameters` section in the package.json. You'll notice that some parameters may be marked as `"mandatory": true`. This is crucial for testing your component.
90+
91+
### Examine the Generated Files
92+
6993
Navigate to your component directory:
7094

7195
```bash
@@ -75,7 +99,7 @@ cd hello-world
7599
Look at the generated template:
76100

77101
```bash
78-
cat template.js
102+
cat src/view.ts
79103
```
80104

81105
You'll see something like:
@@ -93,6 +117,12 @@ export default function (model) {
93117

94118
## Step 3: Start Local Development
95119

120+
**Important**: Run the development server from the parent directory (not inside the component directory):
121+
122+
```bash
123+
cd .. # Go back to oc-tutorial directory
124+
```
125+
96126
Start a local development registry:
97127

98128
```bash
@@ -116,16 +146,29 @@ Watching for changes...
116146

117147
Open your browser and visit:
118148

119-
- **Component endpoint**: http://localhost:3030/hello-world
149+
- **Component endpoint**: http://localhost:3030/hello-world?userId=1
120150
- **Component info**: http://localhost:3030/hello-world/~info
121-
- **Component preview**: http://localhost:3030/hello-world/~preview
151+
152+
**Important**: The generated component requires parameters. If you get an error about "missing mandatory parameters", check the component info page to see what parameters are required.
153+
154+
### Check Component Information
155+
156+
Visit http://localhost:3030/hello-world/~info to see detailed information about your component, including all available parameters and which ones are mandatory.
122157

123158
Or use the CLI preview:
124159

125160
```bash
126161
oc preview http://localhost:3030/hello-world
127162
```
128163

164+
**Note**: If the preview command doesn't work, don't worry - you can test your component directly in the browser using the URLs above.
165+
166+
## Step 4: Test Interactive Features
167+
168+
1. Visit http://localhost:3030/hello-world?userId=1
169+
2. Click the "Fun year fact" button
170+
3. You should see a fact about the birth year appear
171+
129172
## Step 4: Customize Your Component
130173

131174
Let's modify the component to make it more interesting. Edit the `server.js` file:
@@ -175,7 +218,7 @@ Save the files and refresh your browser - you should see the changes immediately
175218
Try your component with different parameters:
176219

177220
```
178-
http://localhost:3030/hello-world?name=Alice
221+
http://localhost:3030/hello-world?userId=0
179222
```
180223

181224
## Step 6: Create a Test HTML Page
@@ -192,7 +235,7 @@ Create a simple HTML file to test client-side rendering:
192235
<h1>My Website</h1>
193236

194237
<!-- Your component will be rendered here -->
195-
<oc-component href="http://localhost:3030/hello-world?name=Developer">
238+
<oc-component href="http://localhost:3030/hello-world?userId=1">
196239
Loading component...
197240
</oc-component>
198241

@@ -298,6 +341,18 @@ Update your HTML to use the production registry:
298341

299342
## Common Troubleshooting
300343

344+
### Directory Issues
345+
346+
**Problem**: "no components found in specified path"
347+
**Solution**: Make sure you're running `oc dev . 3030` from the parent directory containing your components, not from inside the component directory.
348+
349+
### Parameter Issues
350+
351+
**Problem**: "Expected mandatory parameters are missing"
352+
**Solution**: Check the component info page at `/~info` to see what parameters are required, then include them in your URL.
353+
354+
### General Issues
355+
301356
### Component Won't Start
302357

303358
**Problem**: `Error: Cannot find module`
@@ -319,6 +374,8 @@ Update your HTML to use the production registry:
319374
**Problem**: Component shows "Loading..." forever
320375
**Solution**:
321376

377+
- Check if you're including required parameters in the component URL
378+
- Visit the component info page (`/~info`) to see parameter requirements
322379
- Check browser console for errors
323380
- Verify registry is accessible
324381
- Check component syntax
@@ -341,6 +398,15 @@ Update your HTML to use the production registry:
341398

342399
## Next Steps
343400

401+
### Understanding Your Component
402+
403+
The generated component demonstrates several OpenComponents features:
404+
- **Parameter Handling**: Shows how to define and use mandatory/optional parameters
405+
- **Server Actions**: The "funFact" button demonstrates client-server communication
406+
- **CSS Modules**: Scoped styling that won't conflict with other components
407+
- **TypeScript**: Type safety for better development experience
408+
- **Client-side Interactivity**: Event handling within components
409+
344410
Now that you've created your first component, explore these advanced topics:
345411

346412
1. **[Component Structure](components/getting-started)** - Learn about advanced component patterns
@@ -351,6 +417,13 @@ Now that you've created your first component, explore these advanced topics:
351417

352418
## Best Practices
353419

420+
### For Beginners
421+
422+
- **Always run `oc dev` from the directory containing your components**, not from inside a component
423+
- **Check component info** at `/~info` to see required parameters
424+
- **Use the browser console** to debug client-side issues
425+
- **Test both client-side and server-side rendering** to ensure compatibility
426+
354427
- **Keep components small and focused** - Each component should have a single responsibility
355428
- **Use semantic versioning** - Follow semver for component versions
356429
- **Test thoroughly** - Test both server-side and client-side rendering

0 commit comments

Comments
 (0)