Here is the code I'm reviewing...
import { Observable } from 'rxjs/Rx'; // reducer import { playerRegister, PlayerState } from './player'; export function getPlayer$ (state$: Observable<MyAppState>): Observable<PlayerState> { return state$.select(state => state.player); };
Although the Angular framework does not enforce a naming convention for observables, you will often see observables named with a trailing "$" sign. This can be useful when scanning through code and looking for observable values.
In Finnish-Goldman notation, what you do is pluralize observable variable names with a unicode character that matches the last letter of the pluralized word. For example: const oxeÑ = Observable. from(olleyOlleyOxenStream()); const mic€ = Observable.
$ prefix in variable names has no any kind of an effect. A $ dollar sign in JavaScript (and TypeScript by extension) is a valid identifier to use as part of a variable name, it carries no syntactical meaning. It can be used in the beginning, middle or end of a variable/function name.
$ suffix (popularized by Cycle.js) is used to indicate that the variable is an Observable. It could make it to the official style guide too but it's not there yet. Read more here : What does the suffixed dollar sign $ mean?
Syntactically, the dollar ($
) character has no special meaning in JavaScript identifiers.
It is, however, sometimes used by convention to indicate that a variable holds an Observable
or that a function will return an Observable
.
This is a code convention named Finnish Notation, apparently due to the origin of the developer that is attributed for first using it. It's used to indicate the Observable
type of a variable or function.
The idea is that an Observable usually represents a stream of multiple Values and a pluralized variable / function name would indicate this. To not be confused with array variables (which are usually also pluralized), the $
character is used instead of the s
. When reading the variable, you'd read the $
as an s
.
When naming an array, you'll most likely use the proper plural form of a single element's name, as in:
const pets = ['cat', 'dog', 'turtle']
While, if you had an observable that emitted those three values, you'd use:
const pet$ = from(['cat', 'dog', 'turtle']) // read: pets
It's up to you and your team whether you want to use it. I guess there is no explicit consensus as of now, so you can have a long and meaningful argument about it ;-). There are already tslint rules available that allow you to enforce your decision.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With