Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit f26caeb

Browse files
authored
🔀 Merge pull request #1618 from jovotech/v4/dev
🔖 Prepare latest release
2 parents 487026b + b7a6501 commit f26caeb

34 files changed

+20126
-8315
lines changed

clients/client-web-vue2/package-lock.json

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/components.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,53 @@ class YourComponent extends BaseComponent {
428428

429429
## Advanced Component Features
430430

431+
### Type Safety
432+
433+
You can pass the following interfaces and types to `BaseComponent`:
434+
435+
- [Component options](#component-options)
436+
- [Component data](#component-data)
437+
- Component events when [delegating to a component](./handlers.md#delegate-to-components)
438+
439+
For example, this could look like this:
440+
441+
```typescript
442+
import { Component, BaseComponent, ComponentConfig, ComponentData } from '@jovotech/framework';
443+
444+
export interface YourComponentConfig extends ComponentConfig {
445+
someKey: string;
446+
}
447+
448+
export interface YourComponentData extends ComponentData {
449+
someKey: string;
450+
}
451+
452+
export enum YourComponentEvents {
453+
Yes = 'onYes',
454+
No = 'onNo',
455+
}
456+
457+
class YourComponent extends BaseComponent<YourComponentData, YourComponentConfig, YourComponentEvents> {
458+
// ...
459+
}
460+
```
461+
462+
You don't need to pass all three elements:
463+
464+
```typescript
465+
import { Component, BaseComponent } from '@jovotech/framework';
466+
467+
export enum YourComponentEvents {
468+
Yes = 'onYes',
469+
No = 'onNo',
470+
}
471+
472+
class YourComponent extends BaseComponent<{}, {}, YourComponentEvents> {
473+
// ...
474+
}
475+
```
476+
477+
431478
### ComponentTree
432479

433480
The [`ComponentTree`](https://github.com/jovotech/jovo-framework/blob/v4/latest/framework/src/ComponentTree.ts) contains all [registered components](#component-registration):

docs/handlers.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ onNo() {
189189
}
190190
```
191191

192+
The following options can be added to `$delegate()`:
193+
194+
- `resolve`: Handlers that should be called after the child component [resolves](#resolve-a-component) with certain data.
195+
- Can include references to handler functions like `this.onYes` (doesn't work with anonymous functions)
196+
- Can include a string to the handler key: `'onYes'`
197+
- `config`: The config that is used by the child component. Can be accessed inside the child component with `this.$component.config`.
198+
192199
In the above example, the [`$state` stack](./state-stack.md) gets updated like this:
193200

194201
```typescript
@@ -237,12 +244,22 @@ yourHandler() {
237244
}
238245
```
239246

240-
The following options can be added to `$delegate()`:
247+
You can also pass that enum to the component for [type safety](./components.md#type-safety):
248+
249+
```typescript
250+
// src/components/YesNoComponent.ts
251+
252+
export enum YesNoComponentEvent {
253+
Yes = 'yes',
254+
No = 'no',
255+
}
256+
257+
class YesNoComponent extends BaseComponent<{}, {}, YesNoComponentEvent> {
258+
// ...
259+
}
260+
```
261+
241262

242-
- `resolve`: Handlers that should be called after the child component [resolves](#resolve-a-component) with certain data.
243-
- Can include references to handler functions like `this.onYes` (doesn't work with anonymous functions)
244-
- Can include a string to the handler key: `'onYes'`
245-
- `config`: The config that is used by the child component. Can be accessed inside the child component with `this.$component.config`.
246263

247264
### Resolve a Component
248265

0 commit comments

Comments
 (0)