|
| 1 | +import { Record, Union } from "../fable_modules/fable-library.4.1.3/Types.js"; |
| 2 | +import { record_type, string_type, union_type } from "../fable_modules/fable-library.4.1.3/Reflection.js"; |
| 3 | +import { bounce, update as update_1, create, SelfMessage$1_$reflection, State_$reflection as State_$reflection_1 } from "../../src/Debouncer.fs.js"; |
| 4 | +import { Cmd_map, Cmd_batch, Cmd_none } from "../fable_modules/Fable.Elmish.4.0.1/cmd.fs.js"; |
| 5 | +import { fromSeconds } from "../fable_modules/fable-library.4.1.3/TimeSpan.js"; |
| 6 | +import { ofArray, empty, singleton } from "../fable_modules/fable-library.4.1.3/List.js"; |
| 7 | +import { div } from "../fable_modules/Fulma.3.0.0/Elements/Form/Field.fs.js"; |
| 8 | +import { label } from "../fable_modules/Fulma.3.0.0/Elements/Form/Label.fs.js"; |
| 9 | +import { div as div_1 } from "../fable_modules/Fulma.3.0.0/Elements/Form/Control.fs.js"; |
| 10 | +import { input } from "../fable_modules/Fulma.3.0.0/Elements/Form/./Input.fs.js"; |
| 11 | +import { Option, IInputType } from "../fable_modules/Fulma.3.0.0/Elements/Form/Input.fs.js"; |
| 12 | +import { equals } from "../fable_modules/fable-library.4.1.3/Util.js"; |
| 13 | +import { ProgramModule_mkProgram, ProgramModule_run } from "../fable_modules/Fable.Elmish.4.0.1/program.fs.js"; |
| 14 | +import { Program_withReactSynchronous } from "../fable_modules/Fable.Elmish.React.4.0.0/react.fs.js"; |
| 15 | +import "./scss/main.scss"; |
| 16 | + |
| 17 | + |
| 18 | +export class State extends Union { |
| 19 | + constructor(tag, fields) { |
| 20 | + super(); |
| 21 | + this.tag = tag; |
| 22 | + this.fields = fields; |
| 23 | + } |
| 24 | + cases() { |
| 25 | + return ["Initial", "IsTyping", "StoppedTyping"]; |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +export function State_$reflection() { |
| 30 | + return union_type("Demo.State", [], State, () => [[], [], []]); |
| 31 | +} |
| 32 | + |
| 33 | +export class Model extends Record { |
| 34 | + constructor(Debouncer, UserInput, State) { |
| 35 | + super(); |
| 36 | + this.Debouncer = Debouncer; |
| 37 | + this.UserInput = UserInput; |
| 38 | + this.State = State; |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +export function Model_$reflection() { |
| 43 | + return record_type("Demo.Model", [], Model, () => [["Debouncer", State_$reflection_1()], ["UserInput", string_type], ["State", State_$reflection()]]); |
| 44 | +} |
| 45 | + |
| 46 | +export class Msg extends Union { |
| 47 | + constructor(tag, fields) { |
| 48 | + super(); |
| 49 | + this.tag = tag; |
| 50 | + this.fields = fields; |
| 51 | + } |
| 52 | + cases() { |
| 53 | + return ["DebouncerSelfMsg", "ChangeValue", "EndOfInput", "Reset"]; |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +export function Msg_$reflection() { |
| 58 | + return union_type("Demo.Msg", [], Msg, () => [[["Item", SelfMessage$1_$reflection(Msg_$reflection())]], [["Item", string_type]], [], []]); |
| 59 | +} |
| 60 | + |
| 61 | +function init(_arg) { |
| 62 | + return [new Model(create(), "", new State(0, [])), Cmd_none()]; |
| 63 | +} |
| 64 | + |
| 65 | +function update(msg, model) { |
| 66 | + switch (msg.tag) { |
| 67 | + case 0: { |
| 68 | + const patternInput_1 = update_1(msg.fields[0], model.Debouncer); |
| 69 | + return [new Model(patternInput_1[0], model.UserInput, model.State), patternInput_1[1]]; |
| 70 | + } |
| 71 | + case 2: { |
| 72 | + const patternInput_2 = bounce(fromSeconds(2.5), "reset_demo", new Msg(3, []), model.Debouncer); |
| 73 | + return [new Model(patternInput_2[0], model.UserInput, new State(2, [])), Cmd_batch(singleton(Cmd_map((arg_1) => (new Msg(0, [arg_1])), patternInput_2[1])))]; |
| 74 | + } |
| 75 | + case 3: |
| 76 | + return [new Model(model.Debouncer, "", new State(0, [])), Cmd_none()]; |
| 77 | + default: { |
| 78 | + const patternInput = bounce(fromSeconds(1.5), "user_input", new Msg(2, []), model.Debouncer); |
| 79 | + return [new Model(patternInput[0], msg.fields[0], new State(1, [])), Cmd_batch(singleton(Cmd_map((arg) => (new Msg(0, [arg])), patternInput[1])))]; |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +function view(model, dispatch) { |
| 85 | + let matchValue; |
| 86 | + return div(empty(), ofArray([label(empty(), singleton((matchValue = model.State, (matchValue.tag === 1) ? "Waiting for more keystrokes... " : ((matchValue.tag === 2) ? "You stop typing. I will soon reset the demo" : "Type here, I will detect when you stop typing")))), div_1(empty(), singleton(input(ofArray([new Option(1, [new IInputType(0, [])]), new Option(13, [(ev) => { |
| 87 | + dispatch(new Msg(1, [ev.target.value])); |
| 88 | + }]), new Option(8, [model.UserInput]), new Option(4, [equals(model.State, new State(2, []))])]))))])); |
| 89 | +} |
| 90 | + |
| 91 | +export function start(id) { |
| 92 | + ProgramModule_run(Program_withReactSynchronous(id, ProgramModule_mkProgram(() => init(void 0), update, view))); |
| 93 | +} |
| 94 | + |
| 95 | +window.startDemo = ((id) => { |
| 96 | + start(id); |
| 97 | +}); |
| 98 | + |
0 commit comments