raimohanska / lonna

A very popular library
Other
26 stars 6 forks source link

API Design Decisions #1

Open semmel opened 4 years ago

semmel commented 4 years ago

Just some quick observations/questions:

raimohanska commented 4 years ago

Thanks for the feedback and suggestions! I'm glad you found good things here!

The API is in the works and a pipeable API would be nice IMO too! (even the readme says this) Currently the lib is in a "could this work?" phase and the API will definitely have to be shaped for (subjectively) optimal shape in case I (we) are gonna make this an actual library.

At this point, I've not included a general atomic updates system. I'm on the fence whether it would be an asset. In Bacon it has certainly made things very complicated and the library's behavior hard to reason about even though it mostly works great due to extensive testing. What I have in Lonna now is StatelessProperty which is used for Map and Combine (the common state-decomposition operators in UI state management). Stateless Property delegates it current value to it's source(s) so it will avoid invalid states in diamond-shaped setups. That just might be enough.

raimohanska commented 4 years ago

The API is now pipeable, with some exceptions like view and combine which are most convenient in their current form in my opinion. Here is some example code with the current API.

The reason for keeping view in Observable-First order is that type inference works way better this way. Also, when writing UI code you'll want minimal boilerplate. Consider

L.view(prop, "name")}

versus

prop.pipe(L.map((x: Thing) => x.name))

In the latter form the type Thing cannot be inferred.