Sheldon Lee
Sheldon Lee

Reputation: 25

I don't understand some syntax in Dispatcher.js in Flux

While reading code on Flux, I found some lines I don't understand.

Source: https://github.com/facebook/flux/blob/master/src/Dispatcher.js

  1. On line 109, the angle brackets

    class Dispatcher<TPayload>
    
  2. On line 110-115, the whole block doesn't look like javascript.

    _callbacks: {[key: DispatchToken]: (payload: TPayload) => void};
    _isDispatching: boolean;
    _isHandled: {[key: DispatchToken]: boolean};
    _isPending: {[key: DispatchToken]: boolean};
    _lastID: number;
    _pendingPayload: TPayload;
    
  3. On line 138, the function with : void before curly braces.

    unregister(id: DispatchToken): void {
    ...}
    

I thing it is because of some kind of js library. But I'm not sure. The only trace I can find is that invariant is required for this js file. but I can't find the code or documents of invariant.

Upvotes: 1

Views: 329

Answers (1)

mfirry
mfirry

Reputation: 3692

It isn't just Javascript (check out this line), it's flow.

Flow adds static type checking to Javascript code.

Specifically:

  1. http://flowtype.org/docs/classes.html#polymorphic-classes
  2. It's a mix of es6 and Flow syntax
  3. http://flowtype.org/docs/functions.html#type-annotating-functions

Upvotes: 2

Related Questions