Closed sxd1140 closed 4 years ago
Hiya, for the sake of not having to cross-check this operator:
pairwise
and what does it do?That may give me more information on what you're trying to get out of wonka
đź‘Ť Are you referring to it as an Rx operator? Would love to make sure that wonka
supports every necessary use-case, but I'd love to keep the operators to a minimum, since I think it already has all the operators needed to fulfill lots of usecases
I need handle scroller change event, so need current scroller position
and last scroller position
to know scrolling direction.
Sounds like you were thinking of the combine
operator, but if you have a single stream of position events you could also use the scan
operator to transform a single value into a stream of { last, current }
or sth similar
Thanks, I look scan operator
.
scan((acc, val) => acc + val)
in Example.
But in d.ts file https://github.com/kitten/wonka/blob/acc4e71e338ca178ad6da5748d7ffa6c3a3446c8/src/operators/wonka_operator_scan.d.ts#L3
What the second param I should pass?
Hm, seems like that example has a typo! As can be seen in the Reason example for it (and in the typings as you’ve already pointed out) there is a second argument indeed.
Like for reduce
with Array
s that second argument is for the initial value of the accumulation, but it’s not optional for scan
Ok. But seem like scan
just pass one value.
pipe(
fromArray([1, 2, 3, 4, 5, 6]),
scan((last, current) => current, 0),
subscribe( [`I need two value here, last and current`] => {}),
);
You can just store the previous value using scan
temporarily, then calculate your scroll trajectory separately:
scan(
({ current: prev }, current) => ({ prev, current }),
{ current: null }
),
map(({ prev, current }) => prev !== null ? current - prev : 0)
I got it. Thanks a lot.
Is have
pairwise
operator in wonka?