Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/andraaspar/mithril-tsx-component

TSX base class & settings for Mithril.
https://github.com/andraaspar/mithril-tsx-component

Last synced: 2 months ago
JSON representation

TSX base class & settings for Mithril.

Awesome Lists containing this project

README

        

# mithril-tsx-component

> TSX base class & settings for Mithril.

## Install

**This assumes an existing TypeScript project.**

```
npm i mithril-tsx-component
```
Or:
```
yarn add mithril-tsx-component
```

## Setup

### tsconfig.json

```JSON
{
// ...
"compilerOptions": {
// ...
"jsx": "react",
"jsxFactory": "m"
}
}
```

## Use

```TSX
import * as m from 'mithril'

import { MithrilTsxComponent } from 'mithril-tsx-component'

export interface IFooCompAttrs { }

type Vnode = m.Vnode
type VnodeDOM = m.VnodeDOM

export class FooComp extends MithrilTsxComponent {

// oninit(v: Vnode) {}
// onbeforeupdate(v: Vnode, o: VnodeDOM) {}
view(v: Vnode) {
return (


Hello World!

)
}
// oncreate(v: VnodeDOM) {}
// onupdate(v: VnodeDOM) {}
// onbeforeremove(v: VnodeDOM) {}
// onremove(v: VnodeDOM) {}
}
```

## VS Code snippet

Use the following in VS Code’s TypeScript React snippets file:

```JSON
{
"Mithril Component": {
"prefix": "mc",
"body": [
"import * as m from 'mithril'",
"",
"import { MithrilTsxComponent } from 'mithril-tsx-component'",
"",
"export interface I$1Attrs { }",
"",
"type Vnode = m.Vnode",
"type VnodeDOM = m.VnodeDOM",
"",
"export class $1 extends MithrilTsxComponent {",
"",
"\t// oninit(v: Vnode) {}",
"\t// onbeforeupdate(v: Vnode, o: VnodeDOM) {}",
"\tview(v: Vnode) {",
"\t\treturn (",
"\t\t\t$0",
"\t\t)",
"\t}",
"\t// oncreate(v: VnodeDOM) {}",
"\t// onupdate(v: VnodeDOM) {}",
"\t// onbeforeremove(v: VnodeDOM) {}",
"\t// onremove(v: VnodeDOM) {}",
"}"
]
}
}
```