mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-14 13:14:30 -08:00
21 lines
492 B
JavaScript
21 lines
492 B
JavaScript
|
|
import {render} from 'https://unpkg.com/preact?module';
|
||
|
|
|
||
|
|
let state, component, root
|
||
|
|
|
||
|
|
export const createApp = initial => {
|
||
|
|
/* if state is already initialized then preserve it */
|
||
|
|
state = state ?? initial.initialState
|
||
|
|
component = initial.component
|
||
|
|
root = initial.root
|
||
|
|
do_render()
|
||
|
|
}
|
||
|
|
|
||
|
|
export const handler = fn => (...args) => {
|
||
|
|
state = fn(state, ...args)
|
||
|
|
do_render()
|
||
|
|
}
|
||
|
|
|
||
|
|
export const connect = comp => props => comp(props, state)
|
||
|
|
|
||
|
|
const do_render = () => render(component(), root)
|