Simplify counter example.
This commit is contained in:
Родитель
5cf22565d0
Коммит
1471f451cd
|
@ -8,14 +8,16 @@ import type {Address, DOM} from "reflex"
|
|||
*/
|
||||
|
||||
const Increment =
|
||||
{ type: "Increment"
|
||||
, create: () => Increment
|
||||
}
|
||||
() =>
|
||||
( { type: "Increment"
|
||||
}
|
||||
)
|
||||
|
||||
const Decrement =
|
||||
{ type: "Decrement"
|
||||
, create: () => Decrement
|
||||
}
|
||||
() =>
|
||||
( { type: "Decrement"
|
||||
}
|
||||
)
|
||||
|
||||
export const init =
|
||||
(value/*:number*/)/*:Model*/ =>
|
||||
|
@ -25,18 +27,18 @@ export const update =
|
|||
( model/*:Model*/
|
||||
, action/*:Action*/
|
||||
)/*:Model*/ =>
|
||||
( action.type === Increment.type
|
||||
( action.type === "Increment"
|
||||
? { value: model.value + 1 }
|
||||
: action.type === Decrement.type
|
||||
: action.type === "Decrement"
|
||||
? { value: model.value - 1 }
|
||||
: model
|
||||
)
|
||||
|
||||
const counterStyle = {
|
||||
value: {
|
||||
fontWeight: "bold"
|
||||
const counterStyle =
|
||||
{ value:
|
||||
{ fontWeight: "bold"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const view =
|
||||
|
@ -48,7 +50,7 @@ export const view =
|
|||
}
|
||||
, [ html.button
|
||||
( { key: "decrement"
|
||||
, onClick: forward(address, Decrement.create)
|
||||
, onClick: forward(address, Decrement)
|
||||
}
|
||||
, ["-"]
|
||||
)
|
||||
|
@ -60,7 +62,7 @@ export const view =
|
|||
)
|
||||
, html.button
|
||||
( { key: "increment"
|
||||
, onClick: forward(address, Increment.create)
|
||||
, onClick: forward(address, Increment)
|
||||
}
|
||||
, ["+"]
|
||||
)
|
||||
|
|
|
@ -2,22 +2,15 @@
|
|||
|
||||
import type {Address, DOM} from "reflex"
|
||||
|
||||
type Tag <type> =
|
||||
{ type: type
|
||||
}
|
||||
|
||||
export type Model =
|
||||
{ value: number
|
||||
}
|
||||
|
||||
export type Action
|
||||
= Tag<"Increment">
|
||||
| Tag<"Decrement">
|
||||
= {type: "Increment"}
|
||||
| {type: "Decrement"}
|
||||
|
||||
|
||||
declare export var Increment:Tag<"Increment">
|
||||
declare export var Decrement:Tag<"Decrement">
|
||||
|
||||
declare export function init (value:number):
|
||||
Model
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче