Last active
February 6, 2018 16:46
-
-
Save newyankeecodeshop/7a014da8127a8db700d13d8dc681f87a to your computer and use it in GitHub Desktop.
A GongFu updater pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function update1(msg, model, appContext) { | |
// This approach uses effects to implement application logic to do other UI actions. | |
switch (msg.type) { | |
case "ButtonPressed": | |
if (userCanDo(msg)) { | |
return { | |
model: assocTyped("doo", doo, model), | |
effect: Effect(DoSomething(msg.what)) | |
}; | |
else | |
return { model, effect: Effect(ShowAnotherCrazyModal()) }; | |
break; | |
case "DoSomething": | |
... | |
break; | |
case "ShowAnotherCrazyModal": | |
... | |
break; | |
} | |
} | |
function update2(msg, model, appContext) { | |
// This approach calls the update function directly with the appropriate message. | |
switch (msg.type) { | |
case "ButtonPressed": | |
if (userCanDo(msg)) { | |
model = assocTyped("doo", doo, model); | |
return update2(DoSomething(msg.what), model, appContext); | |
else | |
return update2(ShowAnotherCrazyModal()); | |
break; | |
case "DoSomething": | |
... | |
break; | |
case "ShowAnotherCrazyModal": | |
... | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment