Skip to content

Commit

Permalink
🔀 Merge pull request #1618 from jovotech/v4/dev
Browse files Browse the repository at this point in the history
🔖 Prepare latest release
  • Loading branch information
jankoenig committed Jan 31, 2024
2 parents 487026b + b7a6501 commit f26caeb
Show file tree
Hide file tree
Showing 34 changed files with 20,126 additions and 8,315 deletions.
18 changes: 15 additions & 3 deletions clients/client-web-vue2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions docs/components.md
Expand Up @@ -428,6 +428,53 @@ class YourComponent extends BaseComponent {

## Advanced Component Features

### Type Safety

You can pass the following interfaces and types to `BaseComponent`:

- [Component options](#component-options)
- [Component data](#component-data)
- Component events when [delegating to a component](./handlers.md#delegate-to-components)

For example, this could look like this:

```typescript
import { Component, BaseComponent, ComponentConfig, ComponentData } from '@jovotech/framework';

export interface YourComponentConfig extends ComponentConfig {
someKey: string;
}

export interface YourComponentData extends ComponentData {
someKey: string;
}

export enum YourComponentEvents {
Yes = 'onYes',
No = 'onNo',
}

class YourComponent extends BaseComponent<YourComponentData, YourComponentConfig, YourComponentEvents> {
// ...
}
```

You don't need to pass all three elements:

```typescript
import { Component, BaseComponent } from '@jovotech/framework';

export enum YourComponentEvents {
Yes = 'onYes',
No = 'onNo',
}

class YourComponent extends BaseComponent<{}, {}, YourComponentEvents> {
// ...
}
```


### ComponentTree

The [`ComponentTree`](https://github.com/jovotech/jovo-framework/blob/v4/latest/framework/src/ComponentTree.ts) contains all [registered components](#component-registration):
Expand Down
27 changes: 22 additions & 5 deletions docs/handlers.md
Expand Up @@ -189,6 +189,13 @@ onNo() {
}
```

The following options can be added to `$delegate()`:

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

In the above example, the [`$state` stack](./state-stack.md) gets updated like this:

```typescript
Expand Down Expand Up @@ -237,12 +244,22 @@ yourHandler() {
}
```

The following options can be added to `$delegate()`:
You can also pass that enum to the component for [type safety](./components.md#type-safety):

```typescript
// src/components/YesNoComponent.ts

export enum YesNoComponentEvent {
Yes = 'yes',
No = 'no',
}

class YesNoComponent extends BaseComponent<{}, {}, YesNoComponentEvent> {
// ...
}
```


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

### Resolve a Component

Expand Down

0 comments on commit f26caeb

Please sign in to comment.