Data modeling in functional reactive programming
Asked Answered
frp
M

0

7

I feel like I have a good handle on functional reactive programming (FRP) "in the small", e.g. composing mouse events together into a "drag" event stream or mapping and filtering WebSocket events into useable objects that the UI can respond to.

But it seems that the FRP resources I've read intend for it to be used as the main data model of an application. That part I don't get.

So first off, can FRP be used as the main data model for an application?

Is there a global event stream whose events are all changes to the model? That model and those events would have to encompass everything that could possibly happen in the application. Or maybe the model could be split into smaller bits (a la Stores in Facebook's Flux architecture)... but isn't that just storing state in a really weird way and pulling a semantic trick?

Here's a concrete example. I'm making a tilemap editor application like Tiled. A tilemap is a list of layers. Each layer has a two-dimensional array of tiles. Each map, layer, and tile can have its own associated properties that the UI has to represent as it changes.

Is each of these things a stream, so that at the top-level I have streams of streams of streams? Or do I have separate streams of things (the layers stream, the tiles stream) that different parts of my application keep a watch on?

And what does a tile stream look like? Is each event a "add tile" or "remove tile" command with an associated tile? Or maybe each event is the entire 2d array which could get big? How can I take advantage of the "time travel" benefits of FRP in this model?

Is there some bigger picture that I'm missing?

Mesothelium answered 15/7, 2015 at 22:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.