4 ms·
The code looks a bit messy to be honest, maybe it's just the variable naming. `const input$ = sources.DOM.select('.field').events('input')` Why not name it the
by XCSme 8y ago
The code looks a bit messy to be honest, maybe it's just the variable naming. `const input$ = sources.DOM.select('.field').events('input')` Why not name it the same as the DOM function `querySelector` ? `const name$ = input$.map(ev => ev.target.value).startWith('')` Wouldn't in this case `name$` be a boolean, but then `map` is called on a boolean. I just find the syntax very confusing.
- typon 8y agoWhat makes you guess that `name$` is a boolean?
- projectramo 8y agoPerhaps you were thinking of “name?” Because there is nothing about “$name” that implies it’s a Boolean
- jakelazaroff 8y agoBy convention, anything suffixed with $ is a stream. input$ is a stream of input events on all elements matching the selector ".field". The declaration for name$ says to take that stream of events and turn it into a stream of the value of those events, and to seed it with an empty string as the initial value. Reactive programming is a paradigm shift and definitely tough to wrap your head around at first. André Staltz (the creator of Cycle) has a good intro here: https://gist.github.com/staltz/868e7e9bc2a7b8c1f754 https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
- shados 8y agoThe conventions, naming, etc are not Cycle (or even JavaScript, in most case) specific. It's just straight out of the reactive programming ecosystem. I think Cycle uses XStream these days, assuming it didn't change again from last time I looked, and they renamed some stuff from the previous RxJS based implementation to be a bit friendlier, but even then the streams are not necessarily about DOM/html. CycleJS lets you do everything with streams, from managing http request or I/O and any other form of environment input. And yes, that includes DOM events, but it wouldn't make sense to name functions in a general API after a specific use case.
- crucialfelix 8y agoIt's startWith not startsWith. I read it wrong myself too.