News for hackers. Stuff that matters.
Re:Introducing Hooks by spankalee on Thursday October 25, 2018 @05:06PM (#18304592)
It'd be really great for VDOM, builder APIs, and any immediate mode -> retained mode mapping, to be able to get the _callsite_ of a function invocation. Then they could associate state with the callsite unambiguously without resorting to tracking invocations on a stack and disallowing control flow.

Tagged template literals already give us something of a callsite, since the template strings object is cached per callsite. You could do something ugly and use that to associate state:

  const state = useState``();
Re:Introducing Hooks by tln on Thursday October 25, 2018 @08:58PM (#18305957)
I don't think this will work, when I just tried to add a property in a template function I get:

    TypeError: Cannot define property foo, object is not extensible
Cool idea though
Re:Introducing Hooks by spankalee on Thursday October 25, 2018 @11:00PM (#18306413)
You don't add properties to the strings object, but use is as a key into a WeakMap.
Re:Introducing Hooks by tln on Friday October 26, 2018 @01:11PM (#18311129)
The strings object doesn't seem to differ based on call site.

    > f = l => l
    [Function: f]
    > f`hi` === f`hi`
    true
Re:Introducing Hooks by spankalee on Wednesday October 31, 2018 @07:27PM (#18350088)
What JS VM did you use? Edge/Chakra has a bug, but it's been fixed. That expression should return false in Chrome, Safari and Firefox.