haskell - How to know what made a behavior change? -


i'm writing network description a listbox logic.
it's simple: have behavior (maybe) current selected item, , want whenever user adds new item list, current selected item select just-created value.

it's possible user remove items list, , cause various of other changes, have know when new item created; can't select last item on every change.

i don't have code show because speculations on can't written api*, have context of frameworks t , (simplified):

bdb :: behavior t [entry] -- created accumb. bselected :: behavior t (maybe entry) -- created accumb. eaddentry :: event t () -- user clicked add button. created fromaddhandler. 

* well, did think using eaddentry select last entry, that's bad , if work it's race between adding of new item , selecting of it.

how can go it?

i gave cactus's suggestion in comments try, , turns out couldn't been done (i'd have bind changes in middle of let block selection behavior, , list behavior is, depend on each other).

so decided start again scratch over-do time, , wrap entire state in it's own data-type network merely drive. network call functions on network according events, , that's it. turned out superior imo, because there's no applicative-style mess, functionality simple functions, , it's more modular (i decide not use frp @ example, , changes extremely minor -- switch firing functions; although i'd still have find put state, impure ioref).

it's clean, looks similar this:

data dbstate = dbstate database selecteditem lastaction etc etc emptystate :: dbstate stateremove, stateadd :: dbstate -> dbstate 

and behavior just:

let bdb = accumb emptystate $ unions       [stateadd <$ eaddentry       ,stateremove <$ eremoveentry       ] 

prior, had length lines filled lambdas, <$>, <*>, etc. over.

and rectimate' , see changes through lastaction.
added error-checking extremely trivially that.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -