kosich / rxjs-autorun

Re-evaluate an expression whenever Observable in it emits
MIT License
33 stars 2 forks source link

Renaming functions and-or adding aliases #2

Open kosich opened 3 years ago

kosich commented 3 years ago

While $, _ function names are short and are unobtrusive, I think we'll need more descriptive names. Also, run function name doesn't reflect well what it does (as it doesn't immediately run the expression) and is not conventional.

Maybe autorun needs renaming too.

As suggested by @fkrasnowski run could be renamed to something like computed or derived or autopiped

$ and _ as indirectly indicated by @voliva could have additional export aliases, like track (watch, observe, or …) and read (silent, muted, sample, untracked, or …)

Let me know what you think

kosich commented 3 years ago

I currently gravitate towards:

package name: rxjs-autorun methods:

E.g.:

c(() => $(a) + _(b))

c(() => {
  return $(a) + _(b);
})

computed(() => track(a) + read(b))

computed(() => {
  return track(a) + read(b);
})

Let me know what you think!

Do we need the short aliases?

cc @Jopie64

P.S: I think, we're in super alpha, so we don't need to bother about this too much and we can change the names later

Jopie64 commented 3 years ago

Naming is often the hardest part 😫

I'm wondering, can you explain the user of the autorun function? Maybe a use case?

For me it looks like it only cares about the side effects... Is that what it is about?

I'm not so sure about built in aliasses... A user can already do aliasses via the import syntax:

import { computed as c } from 'autorun';

And even with require something like

const { computed: c } = require('autorun');

If I remember correctly. Or do you have a different reason for using aliasses?

Furthermore, computed sounds good to me. Hard to think of anything better. But that's more because I'm not good at naming things. 😬 For me it will probably become another (powerful) rx operator in the toolbox.

I like short names, especially when they are used a lot. So $ and _ are ok for me. Especially $ cause that's the convention extension for streams. But I really would like it when those (also?) became arguments of the expression.

So those are my thoughts 😊

kosich commented 3 years ago

autorun — yeah, side-effects mainly (I guess only side-effects) Maybe also as easy-to-use connector to Observables for those not willing to dive into Rx API

I like the _ and $ for brevity so that we don't over-pollute expressions. And added c while writing that comment, it just felt as a natural counterpart — now I think c is stupid :)

The benefits of having named short export:

  1. it's always the same name everywhere
  2. it lets IDE to do auto-import

The downsides were already described in the #1 :

  1. _ and $ are both popular names
  2. _ can also be used as argument placeholder

But I really would like it when those (also?) became arguments of the expression.

Regarding this, I put that on hold on purpose while we figure out all that track/untrack weak/strong eager/late API.

I'm glad we agree on computed! 🎉