From 1471f451cd10b525098211d0c3be7e2090383eed Mon Sep 17 00:00:00 2001 From: travis Date: Thu, 17 Mar 2016 10:44:47 -0700 Subject: [PATCH] Simplify counter example. --- examples/counter/src/counter.js | 30 +++++++++++++++------------- examples/counter/src/counter.js.flow | 11 ++-------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/examples/counter/src/counter.js b/examples/counter/src/counter.js index 3e05d96..3a587a4 100644 --- a/examples/counter/src/counter.js +++ b/examples/counter/src/counter.js @@ -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) } , ["+"] ) diff --git a/examples/counter/src/counter.js.flow b/examples/counter/src/counter.js.flow index c984e2f..28808fc 100644 --- a/examples/counter/src/counter.js.flow +++ b/examples/counter/src/counter.js.flow @@ -2,22 +2,15 @@ import type {Address, DOM} from "reflex" -type Tag = - { 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