grammarly / focal

Program user interfaces the FRP way.
Apache License 2.0
723 stars 34 forks source link

Don't import entire RxJS #32

Closed blacktaxi closed 6 years ago

blacktaxi commented 6 years ago

Not importing entire RxJS anymore, only stuff that's used. Confirmed with bundle analyzer.

Before: image

After: image

oleksiilevzhynskyi commented 6 years ago

@blacktaxi that's looks great! I do see the only one downside of this approach - we need to explicitly import the corresponding operator to make it work. E.g.:

import { Atom } from '@grammarly/focal'
const counter = Atom.create(1)
counter.filter(x => x > 1)

won't work without

import 'rxjs/add/operator/filter'

Am I get it right?

blacktaxi commented 6 years ago

@oleksiilevzhynskyi that's the idea. Alternatively you can use pipe and import operators as standalone functions like so:

import { Atom } from '@grammarly/focal'
import 'rxjs/add/operator/pipe'
import { filter } from 'rxjs/operators/filter'
import { map } from 'rxjs/operators/map'

const counter = Atom.create(1)
counter.pipe(
  filter(x => x > 1),
  map(x => x + 1)
)
blacktaxi commented 6 years ago

@oleksiilevzhynskyi also you can always import the whole of RxJS in your project, before that was done automatically by importing Focal. With this approach there is choice now.