raphaelameaume / fragment

[alpha] A web development environment for creative coding
https://fragment.tools
MIT License
828 stars 19 forks source link

Props: preserve changes made in browser when hot reloaded #89

Closed raphaelameaume closed 8 months ago

raphaelameaume commented 8 months ago

Issue All the props are reset to their default values on each hot reload of a sketch.

Summary This preserves the current values of props if they were changed from GUIs and adds an indicator in the UI if the value of a prop is not the same one as in the code. A change in the default value (from code) will override the current value in browser.

Details This PR adds an __initialValue key to every prop so they can be compared and reconciled when a sketch is hot reloaded. If the __initialValue is the same between the old props and the new ones, then the new value is overwritten by the old one. This also adds a little indicator (similar to what can be seen in code editors when a line has changed) on the left of a Field if the current value is not the same as the one declared in code. This makes it easy to spot any changes made in the UI and not yet reflected in code. The key binding for refresh R that is in charge of reloading the sketch now also takes care of resetting props values to the default ones.