purescript-sdom icon indicating copy to clipboard operation
purescript-sdom copied to clipboard

Clarification in the project docs

Open Dierk opened this issue 6 years ago • 2 comments

Hi, I'm not quite sure if my following take on the project is correct or not. Either way, this kind of information would have helped me to better understand the approach:

SDOM components conceptually create their visual representation from a model (state), analogous to approaches like React. However, very much unlike React, this state is never materialized in a separate data structure. There is no separate "presentation model" on the value level - only on the type level. All model data resides directly in the DOM. Event handlers read from the DOM and write to the DOM. They do not update any other state. Reading and writing is type-safe wrt the model type.

Dierk avatar Mar 11 '18 11:03 Dierk

This isn't quite right - there is a presentational model, it's just that it's only used once, when the component gets attached to the DOM. This might be on app startup, or in the case of dynamic arrays, the elements might be attached later. But they only get attached when they are first needed. There isn't really a DOM representation at the type level, we're just using types to enforce the static properties needed to make this possible. Event handlers do update the model data.

paf31 avatar Mar 11 '18 18:03 paf31

Hm, for the mere mortals like me :-) this is not so obvious. To make creative use of the SDOM it would help to understand how that works. Ok, there is an initial model provided in the call to attach, but what is then retained in the push is not the model but the model -> model function. Can I see the current model somehow?

Dierk avatar Mar 11 '18 20:03 Dierk