3 ms·
And you can put hooks in if statements too, but like iterables it won't have the effect you probably want. it = ["hello", "world", "foo", "bar"] shoul
by Spivak 5y ago
And you can put hooks in if statements too, but like iterables it won't have the effect you probably want.
it = ["hello", "world", "foo", "bar"]
shouldbehello = next(it)
shouldbeworld = next(it)
if sometimes_true_sometimes_false:
shouldbefoo = next(it)
# if the conditional is false this will be foo, oops.
shouldbebar = next(it)
Hooks aren't callback functions, they're functions that take callback functions. apparently this is breaking python. The naming convention is just so the linter can identify hooks, they're not magic.
def react_to_stuff(func, var):
orig = var.copy()
def monitor():
while True:
sleep 2
if var != orig:
orig = var.copy()
func(var)
t = Thread(target=monitor)
t.start()
stuff = "Hello"
react_to_stuff(lambda x: print(x), stuff)
- dmitriid 5y agoNo idea why you're giving examples in Python code when we're talking about Javascript and React. On "it's iterators actually", I have a response to a sibling comment here: https://news.ycombinator.com/item?id=30799543 https://news.ycombinator.com/item?id=30799543
- Spivak 5y agoBecause it’s better pseduocode and the concept isn’t language dependent.