mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
deploy: leporello-js/app@a6e3f1b36f
This commit is contained in:
@@ -1,38 +1,44 @@
|
||||
const fib = n => {
|
||||
if(n == 0) {
|
||||
if (n == 0) {
|
||||
return 0
|
||||
}
|
||||
if(n == 1) {
|
||||
if (n == 1) {
|
||||
return 1
|
||||
}
|
||||
return fib(n - 1) + fib(n - 2)
|
||||
}
|
||||
|
||||
/* external */
|
||||
import {h, render} from 'https://unpkg.com/preact?module';
|
||||
|
||||
/* external */
|
||||
import {Stateful} from './stateful.js'
|
||||
import { h, render } from "preact"
|
||||
|
||||
/* external */
|
||||
import { Stateful } from "./stateful.js"
|
||||
|
||||
const Fibonacci = Stateful({
|
||||
getInitialState: () => ({index: 0}),
|
||||
getInitialState: () => ({ index: 0 }),
|
||||
|
||||
handlers: {
|
||||
prev: ({index}, event) => ({index: index - 1}),
|
||||
next: ({index}, event) => ({index: index + 1}),
|
||||
prev: ({ index }, event) => ({ index: index - 1 }),
|
||||
next: ({ index }, event) => ({ index: index + 1 }),
|
||||
},
|
||||
|
||||
render: (props, state, handlers) =>
|
||||
h('div', null,
|
||||
h('h1', null,
|
||||
'nth Fibonacci number is ',
|
||||
|
||||
render: (props, state, handlers) =>
|
||||
h(
|
||||
"div",
|
||||
null,
|
||||
h(
|
||||
"h1",
|
||||
null,
|
||||
"nth Fibonacci number is ",
|
||||
fib(state.index),
|
||||
' for n = ',
|
||||
state.index
|
||||
" for n = ",
|
||||
state.index,
|
||||
),
|
||||
h('button', {onClick: handlers.prev}, 'Previous'), ' ',
|
||||
h('button', {onClick: handlers.next}, 'Next'), ' ',
|
||||
)
|
||||
h("button", { onClick: handlers.prev }, "Previous"),
|
||||
" ",
|
||||
h("button", { onClick: handlers.next }, "Next"),
|
||||
" ",
|
||||
),
|
||||
})
|
||||
|
||||
render(h(Fibonacci), globalThis.document.body)
|
||||
|
||||
Reference in New Issue
Block a user