Skip to content

Commit

Permalink
docs(NOBUG): remove old guide from core docs
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-wade committed Dec 8, 2023
1 parent 7560a57 commit 53aec94
Showing 1 changed file with 0 additions and 140 deletions.
140 changes: 0 additions & 140 deletions packages/website/pages/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,146 +71,6 @@ import { defineComponent, html } from 'https://unpkg.com/@tybalt/[email protected]/dis

Alternatively, you can use `cdnjs`, or `jsDelivr`.

## Guide

### Props

Dom elements can have attributes set on them. You can transform an attribute into a prop by specifying
some data about it with the props config object passed to `defineComponent`.

```javascript
defineComponent({
props: { example: {} },
});
```

All props are passed as observables with the same name as the first argument to setup. Each observable
is notified when the corresponding attribute changes.

```javascript
defineComponent({
props: {
example: {},
},
setup({ example }) {
assert(example instanceof Observable);
},
});
```

Props can have a default value that is provided if the attribute is unset.

```javascript
defineComponent({
props: {
example: {
default: 'tybalt',
},
},
});
```

Props can also have a validator. Validation errors are pushed to the error stream of the observable.

```javascript
defineComponent({
props: {
example: {
validator: oneOf(['foo', 'bar', 'baz']),
},
},
setup({ example }) {
example.subscribe({
error(err) {
alert(err);
},
});
},
});
```

To create derived state from a prop, you should create a new observable, and then update it with the
derived value.

```javascript
{
props: {
name: { validator: string() }
},
setup({ name }) {
const greeting = new BehaviorSubject(`hello ${name}`);

return { greeting };
}
}
```

### Events

Events can be emitted from Tybalt components using `emit`, passed on the second argument to `setup`.

```javascript
defineComponent({
name: 'setup-context',
setup({}, { emit }): {
emit('mounted');
}
});
```

If you want to listen for an event, attach an event handler using a special attribute that starts with `@` and is the name of the event you want to listen for

```javascript
defineComponent({
name: 'setup-context',
setup(): {
return {
listener: () => console.log('hello world')
}
},
render({ listener }) {
return html`<button @click=${listener}>Click me!</button>`;
}
});
```

### Slots

There are `slot` and `template` elements in javascript that work well with web components.

```javascript
defineComponent({
name: 'slot-example',
shadowMode: 'open',
render() {
return html`
<div class="my-class">
<span>Example: </span>
<slot name="content"></slot>
</div>
`;
},
});
```

When you render a `slot-example` component, it will replace the `slot` element with the children
of the `slot-example` component. A component rendered in the DOM as

```html
<slot-example>
<div my-attribute="foo">example content</div>
</slot-example>
```

Would be rendered to the user as

```html
<div class="my-class">
<span>Example: </span>
<div my-attribute="foo">example content</div>
</div>
```

## API

### defineComponent
Expand Down

0 comments on commit 53aec94

Please sign in to comment.