Last active
April 26, 2019 22:16
-
-
Save PxyUp/30c0f6cbb3106008c0e06995d49f6170 to your computer and use it in GitHub Desktop.
Router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { bootstrap, Component, rValue, createComponent, createRouter, Router, rList } from 'revact'; | |
class Counter extends Component { | |
reactive = { | |
counter: rValue(0) | |
} | |
template = { | |
tag: "span", | |
textValue: this.reactive.counter, | |
listeners: { | |
click: () => { | |
this.reactive.counter.value++ | |
} | |
} | |
} | |
} | |
class HelloWorld extends Component { | |
template = { | |
tag: "span", | |
textValue: "HelloWorld" | |
} | |
} | |
function createHelloWolrd() { | |
return createComponent(HelloWorld) | |
} | |
function createCounter() { | |
return createComponent(Counter) | |
} | |
bootstrap('#first', () => { | |
const list = [ | |
{ | |
name: 'Hello', | |
path: '/', | |
click: () => { | |
Router.goToUrl('/') | |
} | |
}, | |
{ | |
name: 'Counter', | |
path: '/counter', | |
click: () => { | |
Router.goToUrl('/counter') | |
} | |
}, | |
] | |
return { | |
tag: "div", | |
children: [ | |
rList(list, (item) => { | |
return { | |
tag: "button", | |
textValue: item.name, | |
listeners: { | |
click: () => item.click() | |
} | |
} | |
}, [(e: any) => e]), | |
createRouter({ | |
'/': { | |
component: createHelloWolrd, | |
title: "Hello Wolrd", | |
}, | |
'/counter': { | |
component: createCounter, | |
title: "Counter", | |
} | |
}) | |
] | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment