purescript-concur / purescript-concur-core

Concur UI library for Purescript. Core framework.
MIT License
30 stars 10 forks source link

independant periodic signals #8

Open Ebmtranceboy opened 4 years ago

Ebmtranceboy commented 4 years ago

Hi, I have an issue to create a widget with two independant periodic signals and I've created a gist to demonstrate my problem: https://try.purescript.org/?gist=b6a4189f977795ed7dd694671b9db8a8

Initially, I've created two signals to drive the movement of my shape : one for the translation (lines 264-270) and one for the rotation (lines 272-275). Unfortunately, my shape in widget1 (lines 277-294) is only modified by rotation because the rotation signal happens sooner than the translation one. I have confirmation of this behaviour in widget2 (lines 293-313) where it is the translation that is triggered sooner, and thus is the only one to drive my shape.

I've designed a library (lines 87-260) to address this issue : it is built around the periodically function which modifies a model by creating a signal from three records : one record for updating the periodic independant signals (lines 330-336 and lines 338-341) of any type, one for the independant periods ({t: 15.0, r: 12.0} line 349) of type Number and one for the current state of the model which is a record having the labels sample and period, should the corresponding quantities have the same labels (translation and rotation here). This way, I can get the expected behaviour in widget3 (lines 343-357) where both translation and rotation are observed simultaneously.

Depending on your thought about this, I'd like to know if you can point me towards an easier way to do that. Otherwise, I'd be glad to propose my library as a contribution.

Thanks

Ebmtranceboy commented 4 years ago

Here's a slightly updated (debugged) and improved (no more use of the pickFn function) version of the library, together with a 3-independant-part signal demo : https://try.purescript.org/?gist=419deac545741f065dad5e60276cb9fe

ajnsit commented 4 years ago

Thanks, the example looks very interesting! I'll take a look soon.