rxjs-autorun icon indicating copy to clipboard operation
rxjs-autorun copied to clipboard

Renaming functions and-or adding aliases

Open kosich opened this issue 4 years ago • 3 comments

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 avatar Sep 28 '20 11:09 kosich

I currently gravitate towards:

package name: rxjs-autorun methods:

  • autorunautorun this name reflects well the usage
  • run → two aliases: c and computed similar to mobx & vue APIs
  • $ → two aliases: $ and track
  • _ → two aliases: _ and probably read (untracked is the second nominate 🙂)

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

kosich avatar Oct 07 '20 17:10 kosich

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 😊

Jopie64 avatar Oct 07 '20 21:10 Jopie64

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! 🎉

kosich avatar Oct 07 '20 23:10 kosich