Simplify counter-pair example
This commit is contained in:
Родитель
1471f451cd
Коммит
6db3c23812
|
@ -10,24 +10,24 @@ import type {Action, Model} from "./counter-pair"
|
|||
|
||||
|
||||
const Top =
|
||||
(action/*:Counter.Action*/)/*:Action*/ =>
|
||||
(action) =>
|
||||
( { type: "Top"
|
||||
, source: action
|
||||
}
|
||||
)
|
||||
|
||||
const Bottom =
|
||||
(action/*:Counter.Action*/)/*:Action*/ =>
|
||||
(action) =>
|
||||
( { type: "Bottom"
|
||||
, source: action
|
||||
}
|
||||
)
|
||||
|
||||
const Reset =
|
||||
{ type: "Reset"
|
||||
, source: void(0)
|
||||
, create: () => Reset
|
||||
}
|
||||
() =>
|
||||
( { type: "Reset"
|
||||
}
|
||||
)
|
||||
|
||||
export const init =
|
||||
(top/*:number*/, bottom/*:number*/)/*:Model*/ =>
|
||||
|
@ -82,7 +82,7 @@ export const view =
|
|||
}
|
||||
, [ html.button
|
||||
( { key: "reset"
|
||||
, onClick: forward(address, Reset.create)
|
||||
, onClick: forward(address, Reset)
|
||||
}
|
||||
, ["Reset"]
|
||||
)
|
||||
|
|
|
@ -8,15 +8,10 @@ export type Model =
|
|||
, bottom: Counter.Model
|
||||
}
|
||||
|
||||
export type Tagged <tag, action> =
|
||||
{ type: tag
|
||||
, source: action
|
||||
}
|
||||
|
||||
export type Action
|
||||
= Tagged<"Top", Counter.Action>
|
||||
| Tagged<"Bottom", Counter.Action>
|
||||
| Tagged<"Reset", void>
|
||||
= { type: "Top", source: Counter.Action }
|
||||
| { type: "Bottom", source: Counter.Action }
|
||||
| { type: "Reset" }
|
||||
|
||||
declare export function init
|
||||
(top:number, bottom:number):Model
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче