question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typeahead documentation adjustments for rxjs 5.5

See original GitHub issue

The Typeahead documentation should be adapted to the changes coming in rxjs 5.5.

For example:

search = (text$: Observable<string>) =>
    text$
      .debounceTime(200)
      .distinctUntilChanged()
      .map(term => term.length < 2 ? []
        : states.filter(v => v.toLowerCase().startsWith(term.toLocaleLowerCase())).splice(0, 10));
}

This does not compile anymore, and could be changed to:

search = (text$: Observable<string>) =>
    text$.pipe(
      debounceTime(200),
      distinctUntilChanged(),
      map(term => term.length < 2 ? []
        : states.filter(v => v.toLowerCase().startsWith(term.toLocaleLowerCase())).splice(0, 10)
      )
    );
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jnizetcommented, Mar 24, 2018

I made some readings and experiments.

Demo

First of all: our demo. It currently uses 3 different ways to apply operators:

  • import 'rxjs/add/operator/debounceTime', followed by obs.debounceTime(...): this uses the “old” side-effect import, which is clearly not recommended anymore
  • import {debounceTime} from 'rxjs/operator/debounceTime', followed by debounceTime.call(...): this is the same style as used in ng-bootstrap itself.
  • import {debounceTime} from 'rxjs/operators', followed by obs.pipe(debounceTime(...)). This is what is recommended by RxJS now (see https://github.com/ReactiveX/rxjs/blob/master/doc/pipeable-operators.md#usage)

The result is that the vendor bundle of our demo contains all the RxJS operators. The size of the bundle, on master, is 509 kB.

Migrating all the usages to the recommended usage (using pipeable operators, and importing them all from rxjs/operators) does make the code consistent, and shows the best practices in the demo code. But it doesn’t significantly reduce the vendor bundle size: 507 kB.

The guide about pipeable operators warns about larger bundle sizes when importing from rxjs/operators, and proposes two solutions:

  1. Importing each operator individually: import {debounceTime} from 'rxjs/operators/debounceTime'
  2. Apply a change to the Webpack configuration.

The first solution is not a very good one, IMO. Indeed, it doesn’t use the officially recommended way of importing, and it doesn’t prepare us for the near future. Indeed RxJS 6 is coming, and doesn’t allow such deep imports of operators anymore. See https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md#breaking-changes-3:

Pipeable operators must now be imported from rxjs like so: import { map, filter, switchMap } from ‘rxjs/operators’;. No deep imports.

I thus tried to apply the second solution (Webpack configuration change) in the demo and, 🎉 , the bundle size goes from 509 kB to 449K. Using source-map-explorer indeed shows a signficant reduction in size for the rxjs operators.

Library

The ng-bootstrap non-demo code consistently uses the following style: import {debounceTime} from 'rxjs/operator/debounceTime', followed by debounceTime.call(...).

I find this less readable and idiomatic than the standard way of using pipeable operators. I thus tried to replace them by pipeable operators, importing from rxjs/operators as recommended. I then built ng-bootstrap, and used this build in one of my angular-cli based projects. The production bundle size generated by the CLI stays identical, and source-map-explorer shows only a few operators in the bundle. So I think it’s safe to use pipeable operators in the library code, too.

Conclusion

I plan to submit two PRs:

  • one for the demo, using pipeable operators and applying the webpack change, reducing the bundle size and showing “the good way”
  • one for the library code, using pipeable operators.
1reaction
pkozlowski-opensourcecommented, Apr 10, 2018

I believe that all the changes mentioned here have landed in master via #2255, #2256 and subsequent changes. Will be released as part of 2.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Example usage of the typeahead widget from https ... - StackBlitz
A typeahead example that gets values from a. static <code>string[]</code>. <ul>. <li><code>debounceTime</code> operator</li>.
Read more >
How to properly import RxJS by patching? - Stack Overflow
I have an Angular project and I need to use Observables from RxJS with a few selection of operators. This is what the...
Read more >
Type Ahead - Learn RxJS
This recipe demonstrates the creation of type ahead client side code. ​​. Ultimate RxJS. ​​. Example Code. ( StackBlitz ). Typeahead. // RxJS...
Read more >
Change Log - /inputs - Kendo UI for Angular - Telerik
exclude rxjs/operators from CDN bundles (#637) ... require rxjs <5.5 as peer; Upgrade to latest if using rxjs ^5.5; See https://goo.gl/ ...
Read more >
ng2-completer | Yarn - Package Manager
ng2 autocomplete/typeahead component. angular2, autcomplete, typeahead ... Change Log. All notable changes to this project will be documented in this file.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found