Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/andraaspar/mithril-tsx-component
- Owner: andraaspar
- License: mit
- Archived: true
- Created: 2017-08-09T13:49:17.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-27T13:47:56.000Z (almost 6 years ago)
- Last Synced: 2024-10-23T00:35:51.938Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 7.81 KB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - mithril-tsx-component - TSX base class & settings for Mithril. (TypeScript)
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.VnodeDOMexport 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) {}",
"}"
]
}
}
```