0

I'm reading this code . It's my first encounter with RxJS.

Here is the relevant code:

const resolvedAll = updatedPkgJSONs
    ::map((pkgJson) => ({pkgJson, target: '..', isProd}))
    ::resolveAll(nodeModules, undefined, isExplicit)::skip(1)
    ::publishReplay().refCount()

I'm trying to guess the meaning of the above statement. But I'm stuck at resolveAll function.

Here is the resolveAll function:

export function resolveAll (nodeModules, targets = Object.create(null), isExplicit) {
    return this::expand(({target, pkgJson, isProd = false}) => {
        // more code
    })
}

What's the meaning of this::expand? Is it the case that the parameters should match? ({pkgJson, target: '..', isProd}) and {target, pkgJson, isProd = false}

I know there is the document. But I'm having a hard time relating the document to my example.

zjk
  • 1,873
  • 1
  • 24
  • 41
  • @DenysSéguret Hi, I do wish to have the question reopened. I'm still in the process of figuring it out by myself. Not sure how long that'll take. – zjk Sep 23 '16 at 08:22

1 Answers1

2

There are quite a few features in this code:

  • The :: operator, known as the bind operator will ensure that this is bound correctly.
  • The ({arg1, arg2, arg3}) is a destructuring operator
  • The isProd = false is a default value for the argument.

Specifically, what's happening here is that this::expand is a function that accepts a function as an argument (also known as a higher order function), the function expand accepts, accepts one Object argument, with properties named target, pkgJson and, optionally, isProd (which would default to false).

Graham
  • 6,577
  • 17
  • 55
  • 76
Madara's Ghost
  • 158,961
  • 49
  • 244
  • 292