jorgebucaran / hyperapp

1kB-ish JavaScript framework for building hypertext applications
MIT License
19.08k stars 780 forks source link

oldSub[2] is not a function #1105

Open IamCarbonMan opened 1 year ago

IamCarbonMan commented 1 year ago

when stopping a subscription- by &&ing it with a falsy state value in app()- and then restarting it, I get an error "oldSub[2] is not a function". It looks like it's trying to call the 3rd element of the subscription array but according to the docs a subscription array only has 2 elements

IamCarbonMan commented 1 year ago

https://github.com/IamCarbonMan/pokegotchi

code is here. a bit messy and written in coffeescript but as far as I can tell everything meets the docs

mshgh commented 1 year ago

I cannot read coffeescript, but I guess this would be the same issue I run into when using subscriptions. I cannot see anything in the documentation related to the return value of subscription unsubscribe handler, but based on the source code the only meaningful return values are undefined or false

see line 59 in https://github.com/jorgebucaran/hyperapp/blob/c3717e3ff78b6fa8663575d34d330d68929a0974/index.js#L48-L59

in may case my issue was caused by using one-liner. this is failing

  ...
  return () => function_returning_something()
}

while this works perfectly fine

  ...
  return () => {
    function_returning_something()
  }
}

I am curious if changing the line 59 like this would be the fix?

        : (oldSub && oldSub[2](), false)
jorgebucaran commented 1 year ago

If you'd like, feel free to send over a patch along with a test script. If you need a hand with writing the test, just let me know and I'll be happy to help you out or show you how to get started. I hope that makes sense.