adamhaile / surplus

High performance JSX web views for S.js applications
639 stars 26 forks source link

Issue with mounting a module that has updates on instantiation #65

Open awei01 opened 6 years ago

awei01 commented 6 years ago

Hi, new to Surplus and enjoying it so far. I recently ran into this issue and have been left scratching my head. I've created a fiddle here: https://jsfiddle.net/awei01/hfLq5knr/

The basic scenario is that I have a module that updates some S values when instantiated (like a loading indicator). Correct me if I'm wrong, but I'm assuming that the issue is that the component wraps everything in an S.freeze or something, so that values that change throw the warning about values changing.

I'm wondering how to unfreeze the instantiation so that the component can observe the loading state. Hopefully my demo will be clearer than this crappy explanation.

adamhaile commented 6 years ago

Woah! This is actually a bug in S.value(). If you change isLoading() to an S.data() it will work. It will also work if you add a trivial computation that reads isLoading() before you call doSomething(), because the bug is in an optimization for the case where a signal changes that isn't being read by anyone. Simplest repro is:

const v = S.value(1)
v(2) // ok
v(3) // error

I'll get a fix out for this soon. Thanks for the report, especially for including an example!

awei01 commented 6 years ago

Oh, ok. Good to know. Thanks for the fast response. Looking forward to the fix.