I've got mixed feelings about all this autorun thing.
It looks very cool. And I love this pattern. I find it clear and convenient
But, RxJS already includes the combineLatest operator for the same purpose, less cool, still clear, and convenient.
But, MobX fans will fall in love with it!
Comparison between some aproaches:
RxJS:
// atom initializtion:constlizard$=newBehaviorSubject('π¦');constwizard$=of('π§ββοΈ');// reaction / subscription:combineLatest([lizard$,wizard$]).subscribe(([lizard,wizard])=>console.log(`king gizzard & the ${lizard}${wizard}`));// update atom:lizard$.next('π');
MobX:
// atom initializtion:constlizard=observable({emoji:'π¦'});constwizard=observable({emoji:'π§ββοΈ'});// reaction / subscription:autorun(()=>console.log(`king gizzard & the ${lizard.emoji}${wizard.emoji}`));// update atom:lizard.emoji='π';
Svelte:
// atom initializtion:letlizard='π¦'letwizard='π§ββοΈ'// reaction / subscription:$:console.log(`king gizzard & the ${lizard}${wizard}`)// update atom:lizard='π';
It might look like MobX and Svelte strategy is better, due to their terseness. But RxJS is about operators! And its full force lays in them. Your solution:
// atom initialization:constlizard$=newBehaviorSubject('π¦');constwizard$=of('π§ββοΈ');// reaction / subscription:autorun($=>console.log(`king gizzard & the ${$(lizard$)}${$(wizard$)}`))// OR with pipe and operators!run($=>`king gizzard & the ${$(lizard$)}${$(wizard$)}`).pipe(/* operators */).subscribe(console.log)// update atom:lizard$.next('π');
Best of both worlds??
Glad you add distinctUntilChanged. And I think run could be better named computed or derived or autopiped π¨π
Totally agree with all three points!
And I love your examples β this gives some perspective! Thanks π
I've started this only because it was a fun dev challenge, I was sure as an API it's useless and error-prone! Then when it was ready... I began to have doubts π€π
The shorter notation might make sense in templates like in <$> or Recks...
Probably it's a maker's affection of some sort: when you're painting something for a day long, and you look at it -- and it's crap, you know it's crap but still you kinda like it π
I think, I'll finish and post the state thing.
Maybe even include it into proxify lib (bad naming here too π€¦ββοΈ)
Still not sure what to do w/ autorun β will polish it, then we'll see...
BTW, I've been sharing all this on twitter too, here's a thread
VΓctor Oliva made another cool autorun concept β check it out!
(I'd ping you long ago, though haven't found you there)
and here's latest concept w/ state & autorun from twitter:
Thanks for taking your time to look into this on Friday evening π
Have a good weekend!
SATURDAY: okay... I've shared autorun on github github.com/kosich/rxjs-autorun (no npm package, naming is still a problem)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Phew π ! That's cool! Thanks for proofreading the sources! π
Hey, @fkrasnowski , sorry for bothering you again π
Want to give an update:
State:
π listen to distinct state value changes
π write to state (sub)values
π« reset state
π sync read current state value
π TS support coming
/ I've dropped
fn
calls with wholethis
issue for now π and used your cool approach with pluck! π /π work in progress
Autorun:
Another THEORETICAL thing born in discussions (here and on twitter for the very same
proxify
π)A function that is re-evaluated when an Observable used in it changes
(I think MobX'
autorun
does a similar thing)π work in progress #2
Mix:
The two might look cool together:
Let me know what you think π€
Take care!
I've got mixed feelings about all this
autorun
thing.combineLatest
operator for the same purpose, less cool, still clear, and convenient.Comparison between some aproaches:
RxJS:
MobX:
Svelte:
It might look like MobX and Svelte strategy is better, due to their terseness. But RxJS is about operators! And its full force lays in them. Your solution:
Best of both worlds??
Glad you add
distinctUntilChanged
. And I thinkrun
could be better namedcomputed
orderived
orautopiped
π¨πTotally agree with all three points!
And I love your examples β this gives some perspective! Thanks π
I've started this only because it was a fun dev challenge, I was sure as an API it's useless and error-prone! Then when it was ready... I began to have doubts π€π
The shorter notation might make sense in templates like in
<$>
or Recks...Probably it's a maker's affection of some sort: when you're painting something for a day long, and you look at it -- and it's crap, you know it's crap but still you kinda like it π
I think, I'll finish and post the
state
thing.Maybe even include it into
proxify
lib (bad naming here too π€¦ββοΈ)Still not sure what to do w/
autorun
β will polish it, then we'll see...BTW, I've been sharing all this on twitter too, here's a thread
VΓctor Oliva made another cool autorun concept β check it out!
(I'd ping you long ago, though haven't found you there)
and here's latest concept w/ state & autorun from twitter:
Thanks for taking your time to look into this on Friday evening π
Have a good weekend!
SATURDAY: okay... I've shared autorun on github github.com/kosich/rxjs-autorun (no npm package, naming is still a problem)